[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677
kocienda
kocienda at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 05:58:41 UTC 2009
The following commit has been merged in the debian/unstable branch:
commit 25610a630da63e091a953f77087a49c183d9e8e2
Author: kocienda <kocienda at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Mon Mar 25 17:45:44 2002 +0000
2002-03-25 Kenneth Kocienda <kocienda at apple.com>
Fix for this bug:
Radar 2867562 (Disk cache should write new entries lazily)
* Database.subproj/IFURLFileDatabase.h:
* Database.subproj/IFURLFileDatabase.m: (+[IFURLFileDatabaseOp
opWithCode:key:object:]), (-[IFURLFileDatabaseOp initWithCode:key:object:]),
(-[IFURLFileDatabaseOp opcode]), (-[IFURLFileDatabaseOp key]),
(-[IFURLFileDatabaseOp object]), (-[IFURLFileDatabaseOp perform:]),
(-[IFURLFileDatabaseOp dealloc]), (-[IFURLFileDatabase initWithPath:]),
(-[IFURLFileDatabase dealloc]), (-[IFURLFileDatabase setTimer]),
(-[IFURLFileDatabase setObject:forKey:]), (-[IFURLFileDatabase
removeObjectForKey:]), (-[IFURLFileDatabase removeAllObjects]),
(-[IFURLFileDatabase objectForKey:]), (-[IFURLFileDatabase
performSetObject:forKey:]), (-[IFURLFileDatabase performRemoveObjectForKey:]),
(-[IFURLFileDatabase lazySync:]), (-[IFURLFileDatabase sync]):
* WebFoundation.pbproj/project.pbxproj:
Simple fix to remove Objective-C include when compiling with
a straight C compiler.
* CacheLoader.subproj/IFURLCacheLoaderConstants.h:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@840 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebKit/Misc.subproj/WebFileDatabase.h b/WebKit/Misc.subproj/WebFileDatabase.h
index 71dc223..1556216 100644
--- a/WebKit/Misc.subproj/WebFileDatabase.h
+++ b/WebKit/Misc.subproj/WebFileDatabase.h
@@ -6,9 +6,17 @@
#import "IFDatabase.h"
-
@interface IFURLFileDatabase : IFDatabase
{
+ NSMutableArray *ops;
+ NSMutableDictionary *setCache;
+ NSMutableSet *removeCache;
+ NSTimer *timer;
+ NSTimeInterval touch;
NSLock *mutex;
}
+
+-(void)performSetObject:(id)object forKey:(id)key;
+-(void)performRemoveObjectForKey:(id)key;
+
@end
diff --git a/WebKit/Misc.subproj/WebFileDatabase.m b/WebKit/Misc.subproj/WebFileDatabase.m
index b9be7d0..c640966 100644
--- a/WebKit/Misc.subproj/WebFileDatabase.m
+++ b/WebKit/Misc.subproj/WebFileDatabase.m
@@ -4,10 +4,106 @@
#import "IFURLFileDatabase.h"
#import "IFNSFileManagerExtensions.h"
+#import "IFURLCacheLoaderConstantsPrivate.h"
+#import "WebFoundationDebug.h"
static NSNumber *IFURLFileDirectoryPosixPermissions;
static NSNumber *IFURLFilePosixPermissions;
+typedef enum
+{
+ IFURLFileDatabaseSetObjectOp,
+ IFURLFileDatabaseRemoveObjectOp,
+} IFURLFileDatabaseOpCode;
+
+enum
+{
+ SYNC_INTERVAL = 5,
+ SYNC_IDLE_THRESHOLD = 5,
+};
+
+// interface IFURLFileDatabaseOp -------------------------------------------------------------
+
+ at interface IFURLFileDatabaseOp : NSObject
+{
+ IFURLFileDatabaseOpCode opcode;
+ id key;
+ id object;
+}
+
++(id)opWithCode:(IFURLFileDatabaseOpCode)opcode key:(id)key object:(id)object;
+-(id)initWithCode:(IFURLFileDatabaseOpCode)opcode key:(id)key object:(id)object;
+
+-(IFURLFileDatabaseOpCode)opcode;
+-(id)key;
+-(id)object;
+-(void)perform:(IFURLFileDatabase *)target;
+
+ at end
+
+
+// implementation IFURLFileDatabaseOp -------------------------------------------------------------
+
+ at implementation IFURLFileDatabaseOp
+
++(id)opWithCode:(IFURLFileDatabaseOpCode)theOpcode key:(id)theKey object:(id)theObject
+{
+ return [[[IFURLFileDatabaseOp alloc] initWithCode:theOpcode key:theKey object:theObject] autorelease];
+}
+
+-(id)initWithCode:(IFURLFileDatabaseOpCode)theOpcode key:(id)theKey object:(id)theObject
+{
+ if ((self = [super init])) {
+
+ opcode = theOpcode;
+ key = [theKey retain];
+ object = [theObject retain];
+
+ return self;
+ }
+
+ [self release];
+ return nil;
+}
+
+-(IFURLFileDatabaseOpCode)opcode
+{
+ return opcode;
+}
+
+-(id)key
+{
+ return key;
+}
+
+-(id)object
+{
+ return object;
+}
+
+-(void)perform:(IFURLFileDatabase *)target
+{
+ switch (opcode) {
+ case IFURLFileDatabaseSetObjectOp:
+ [target performSetObject:object forKey:key];
+ break;
+ case IFURLFileDatabaseRemoveObjectOp:
+ [target performRemoveObjectForKey:key];
+ break;
+ }
+}
+
+-(void)dealloc
+{
+ [key release];
+ [object release];
+
+ [super dealloc];
+}
+
+ at end
+
+
// implementation IFURLFileDatabase -------------------------------------------------------------
@implementation IFURLFileDatabase
@@ -28,6 +124,12 @@ static NSNumber *IFURLFilePosixPermissions;
{
if ((self = [super initWithPath:thePath])) {
+ ops = [[NSMutableArray alloc] init];
+ setCache = [[NSMutableDictionary alloc] init];
+ removeCache = [[NSMutableSet alloc] init];
+ timer = nil;
+ mutex = [[NSLock alloc] init];
+
return self;
}
@@ -38,6 +140,11 @@ static NSNumber *IFURLFilePosixPermissions;
-(void)dealloc
{
[self close];
+ [self sync];
+
+ [setCache release];
+ [removeCache release];
+ [mutex release];
[super dealloc];
}
@@ -70,69 +177,63 @@ static NSNumber *IFURLFilePosixPermissions;
return [NSString stringWithFormat:@"%.2u/%.2u/%.10u-%.10u.cache", ((hash1 & 0xff) >> 4), ((hash2 & 0xff) >> 4), hash1, hash2];
}
+-(void)setTimer
+{
+ if (timer == nil) {
+ timer = [[NSTimer scheduledTimerWithTimeInterval:SYNC_INTERVAL target:self selector:@selector(lazySync:) userInfo:nil repeats:YES] retain];
+ }
+}
+
// database functions ---------------------------------------------------------------------------
#pragma mark database functions
-
-(void)setObject:(id)object forKey:(id)key
{
- BOOL result;
- NSString *filePath;
- NSMutableData *data;
- NSDictionary *attributes;
- NSDictionary *directoryAttributes;
- NSArchiver *archiver;
- NSFileManager *defaultManager;
-
- result = NO;
+ IFURLFileDatabaseOp *op;
- data = [NSMutableData data];
- archiver = [[NSArchiver alloc] initForWritingWithMutableData:data];
- [archiver encodeObject:key];
- [archiver encodeObject:object];
+ touch = CFAbsoluteTimeGetCurrent();
- attributes = [NSDictionary dictionaryWithObjectsAndKeys:
- [NSDate date], @"NSFileModificationDate",
- NSUserName(), @"NSFileOwnerAccountName",
- IFURLFilePosixPermissions, @"NSFilePosixPermissions",
- NULL
- ];
-
- directoryAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
- [NSDate date], @"NSFileModificationDate",
- NSUserName(), @"NSFileOwnerAccountName",
- IFURLFileDirectoryPosixPermissions, @"NSFilePosixPermissions",
- NULL
- ];
-
- defaultManager = [NSFileManager defaultManager];
-
- filePath = [NSString stringWithFormat:@"%@/%@", path, [IFURLFileDatabase uniqueFilePathForKey:key]];
-
- result = [defaultManager createFileAtPath:filePath contents:data attributes:attributes];
- if (!result) {
- result = [defaultManager createFileAtPathWithIntermediateDirectories:filePath contents:data attributes:attributes directoryAttributes:directoryAttributes];
- }
-
- [archiver release];
+ [mutex lock];
+
+ [setCache setObject:object forKey:key];
+ op = [[IFURLFileDatabaseOp alloc] initWithCode:IFURLFileDatabaseSetObjectOp key:key object:nil];
+ [ops addObject:op];
+ [self setTimer];
+
+ [mutex unlock];
}
-(void)removeObjectForKey:(id)key
{
- NSString *filePath;
-
- filePath = [NSString stringWithFormat:@"%@/%@", path, [IFURLFileDatabase uniqueFilePathForKey:key]];
+ IFURLFileDatabaseOp *op;
- [[NSFileManager defaultManager] removeFileAtPath:filePath handler:nil];
+ touch = CFAbsoluteTimeGetCurrent();
+
+ [mutex lock];
+
+ [removeCache addObject:key];
+ op = [[IFURLFileDatabaseOp alloc] initWithCode:IFURLFileDatabaseRemoveObjectOp key:key object:nil];
+ [ops addObject:op];
+ [self setTimer];
+
+ [mutex unlock];
}
-(void)removeAllObjects
{
+ touch = CFAbsoluteTimeGetCurrent();
+
[mutex lock];
+ [setCache removeAllObjects];
+ [removeCache removeAllObjects];
[self close];
[[NSFileManager defaultManager] backgroundRemoveFileAtPath:path];
[self open];
[mutex unlock];
+
+#ifdef WEBFOUNDATION_DEBUG
+ WebFoundationLogAtLevel(WebFoundationLogDiskCacheActivity, @"- [WEBFOUNDATION_DEBUG] - removeAllObjects");
+#endif
}
-(id)objectForKey:(id)key
@@ -147,6 +248,21 @@ static NSNumber *IFURLFilePosixPermissions;
result = nil;
fileKey = nil;
+ touch = CFAbsoluteTimeGetCurrent();
+
+ // check caches
+ [mutex lock];
+ if ([removeCache containsObject:key]) {
+ [mutex unlock];
+ return nil;
+ }
+ if ((result = [setCache objectForKey:key])) {
+ [mutex unlock];
+ return result;
+ }
+ [mutex unlock];
+
+ // go to disk
filePath = [NSString stringWithFormat:@"%@/%@", path, [IFURLFileDatabase uniqueFilePathForKey:key]];
data = [[NSData alloc] initWithContentsOfMappedFile:filePath];
@@ -174,6 +290,67 @@ static NSNumber *IFURLFilePosixPermissions;
}
+-(void)performSetObject:(id)object forKey:(id)key
+{
+ BOOL result;
+ NSString *filePath;
+ NSMutableData *data;
+ NSDictionary *attributes;
+ NSDictionary *directoryAttributes;
+ NSArchiver *archiver;
+ NSFileManager *defaultManager;
+
+#ifdef WEBFOUNDATION_DEBUG
+ WebFoundationLogAtLevel(WebFoundationLogDiskCacheActivity, @"- [WEBFOUNDATION_DEBUG] - performSetObject - %@", key);
+#endif
+
+ result = NO;
+
+ data = [NSMutableData data];
+ archiver = [[NSArchiver alloc] initForWritingWithMutableData:data];
+ [archiver encodeObject:key];
+ [archiver encodeObject:object];
+
+ attributes = [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSDate date], @"NSFileModificationDate",
+ NSUserName(), @"NSFileOwnerAccountName",
+ IFURLFilePosixPermissions, @"NSFilePosixPermissions",
+ NULL
+ ];
+
+ directoryAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSDate date], @"NSFileModificationDate",
+ NSUserName(), @"NSFileOwnerAccountName",
+ IFURLFileDirectoryPosixPermissions, @"NSFilePosixPermissions",
+ NULL
+ ];
+
+ defaultManager = [NSFileManager defaultManager];
+
+ filePath = [NSString stringWithFormat:@"%@/%@", path, [IFURLFileDatabase uniqueFilePathForKey:key]];
+
+ result = [defaultManager createFileAtPath:filePath contents:data attributes:attributes];
+ if (!result) {
+ result = [defaultManager createFileAtPathWithIntermediateDirectories:filePath contents:data attributes:attributes directoryAttributes:directoryAttributes];
+ }
+
+ [archiver release];
+}
+
+-(void)performRemoveObjectForKey:(id)key
+{
+ NSString *filePath;
+
+
+#ifdef WEBFOUNDATION_DEBUG
+ WebFoundationLogAtLevel(WebFoundationLogDiskCacheActivity, @"- [WEBFOUNDATION_DEBUG] - performRemoveObjectForKey - %@", key);
+#endif
+
+ filePath = [NSString stringWithFormat:@"%@/%@", path, [IFURLFileDatabase uniqueFilePathForKey:key]];
+
+ [[NSFileManager defaultManager] removeFileAtPath:filePath handler:nil];
+}
+
// database management functions ---------------------------------------------------------------------------
#pragma mark database management functions
@@ -220,9 +397,69 @@ static NSNumber *IFURLFilePosixPermissions;
return YES;
}
+-(void)lazySync:(NSTimer *)theTimer
+{
+ IFURLFileDatabaseOp *op;
+
+ while (touch + SYNC_IDLE_THRESHOLD < CFAbsoluteTimeGetCurrent() && [ops count] > 0) {
+ [mutex lock];
+
+ if (timer) {
+ [timer invalidate];
+ [timer autorelease];
+ timer = nil;
+ }
+
+ op = [ops lastObject];
+ if (op) {
+ [ops removeLastObject];
+ [op perform:self];
+ [setCache removeObjectForKey:[op key]];
+ [removeCache removeObject:[op key]];
+ [op release];
+ }
+
+ [mutex unlock];
+ }
+
+ // come back later to finish the work...
+ if ([ops count] > 0) {
+ [mutex lock];
+ [self setTimer];
+ [mutex unlock];
+ }
+}
+
-(void)sync
{
- // no-op for this kind of database
+ NSArray *array;
+ int opCount;
+ int i;
+ IFURLFileDatabaseOp *op;
+
+ touch = CFAbsoluteTimeGetCurrent();
+
+ array = nil;
+
+ [mutex lock];
+ if ([ops count] > 0) {
+ array = [NSArray arrayWithArray:ops];
+ [ops removeAllObjects];
+ }
+ if (timer) {
+ [timer invalidate];
+ [timer autorelease];
+ timer = nil;
+ }
+ [setCache removeAllObjects];
+ [removeCache removeAllObjects];
+ [mutex unlock];
+
+ opCount = [array count];
+ for (i = 0; i < opCount; i++) {
+ op = [array objectAtIndex:i];
+ [op perform:self];
+ }
}
@end
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list