Commit 5a4dc3cf authored by mjs@apple.com's avatar mjs@apple.com

2009-02-05 Maciej Stachowiak <mjs@apple.com> and Brady Eidson <beidson@apple.com>

        Reviewed by Dan Bernstein and Geoff Garen.

        - WebKit code to track per-day and per-week visit counts in history

        For now this data is only exposed via SPI for performance reasons.
        
        * History/WebHistoryItem.mm:
        (-[WebHistoryItem initFromDictionaryRepresentation:]): Add parsing support
        for new data.
        (-[WebHistoryItem _recordInitialVisit]): Tell WebCore to record an initial visit.
        (-[WebHistoryItem dictionaryRepresentation]): Add saving support for new data.
        (-[WebHistoryItem _getDailyVisitCounts:]): SPI accessor.
        (-[WebHistoryItem _getWeeklyVisitCounts:]): SPI accessor.
        * History/WebHistoryItemInternal.h: Declare new methods.
        * History/WebHistoryItemPrivate.h: Ditto.

        * History/WebHistory.mm:
        (-[WebHistoryPrivate visitedURL:withTitle:]): For the initial visit, use
        the new _recordInitialVisit method instead of setting visit count to 1.

        * Misc/WebNSArrayExtras.h:
        * Misc/WebNSArrayExtras.m:
        (-[NSArray _webkit_numberAtIndex:]): Helper to retrieve an NSNumber or nil from an NSArray
        (-[NSArray _webkit_stringAtIndex:]): Helper to retrieve an NSString of nil from an NSArray



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@40711 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 73ecea19
2009-02-05 Maciej Stachowiak <mjs@apple.com> and Brady Eidson <beidson@apple.com>
Reviewed by Dan Bernstein and Geoff Garen.
- WebKit code to track per-day and per-week visit counts in history
For now this data is only exposed via SPI for performance reasons.
* History/WebHistoryItem.mm:
(-[WebHistoryItem initFromDictionaryRepresentation:]): Add parsing support
for new data.
(-[WebHistoryItem _recordInitialVisit]): Tell WebCore to record an initial visit.
(-[WebHistoryItem dictionaryRepresentation]): Add saving support for new data.
(-[WebHistoryItem _getDailyVisitCounts:]): SPI accessor.
(-[WebHistoryItem _getWeeklyVisitCounts:]): SPI accessor.
* History/WebHistoryItemInternal.h: Declare new methods.
* History/WebHistoryItemPrivate.h: Ditto.
* History/WebHistory.mm:
(-[WebHistoryPrivate visitedURL:withTitle:]): For the initial visit, use
the new _recordInitialVisit method instead of setting visit count to 1.
* Misc/WebNSArrayExtras.h:
* Misc/WebNSArrayExtras.m:
(-[NSArray _webkit_numberAtIndex:]): Helper to retrieve an NSNumber or nil from an NSArray
(-[NSArray _webkit_stringAtIndex:]): Helper to retrieve an NSString of nil from an NSArray
2009-02-05 Aaron Boodman <aa@chromium.org>
Reviewed by Dave Hyatt.
......
......@@ -276,7 +276,7 @@ static WebHistoryDateKey timeIntervalForBeginningOfDay(NSTimeInterval interval)
} else {
LOG(History, "Adding new global history entry for %@", url);
entry = [[WebHistoryItem alloc] initWithURLString:URLString title:title lastVisitedTimeInterval:[NSDate timeIntervalSinceReferenceDate]];
[entry _setVisitCount:1];
[entry _recordInitialVisit];
[_entriesByURL setObject:entry forKey:URLString];
[entry release];
}
......
......@@ -35,6 +35,7 @@
#import "WebIconDatabase.h"
#import "WebKitLogging.h"
#import "WebKitNSStringExtras.h"
#import "WebNSArrayExtras.h"
#import "WebNSDictionaryExtras.h"
#import "WebNSObjectExtras.h"
#import "WebNSURLExtras.h"
......@@ -63,6 +64,8 @@ static NSString *displayTitleKey = @"displayTitle";
static NSString *lastVisitWasFailureKey = @"lastVisitWasFailure";
static NSString *lastVisitWasHTTPNonGetKey = @"lastVisitWasHTTPNonGet";
static NSString *redirectURLsKey = @"redirectURLs";
static NSString *dailyVisitCountKey = @"D"; // short key to save space
static NSString *weeklyVisitCountKey = @"W"; // short key to save space
// Notification strings.
NSString *WebHistoryItemChangedNotification = @"WebHistoryItemChangedNotification";
......@@ -369,10 +372,24 @@ static WebWindowWatcher *_windowWatcher = nil;
NSUInteger size = [redirectURLs count];
std::auto_ptr<Vector<String> > redirectURLsVector(new Vector<String>(size));
for (NSUInteger i = 0; i < size; ++i)
(*redirectURLsVector)[i] = String([redirectURLs objectAtIndex:i]);
(*redirectURLsVector)[i] = String([redirectURLs _webkit_stringAtIndex:i]);
core(_private)->setRedirectURLs(redirectURLsVector);
}
NSArray *dailyCounts = [dict _webkit_arrayForKey:dailyVisitCountKey];
NSArray *weeklyCounts = [dict _webkit_arrayForKey:weeklyVisitCountKey];
if (dailyCounts || weeklyCounts) {
Vector<int> coreDailyCounts([dailyCounts count]);
Vector<int> coreWeeklyCounts([weeklyCounts count]);
for (size_t i = 0; i < coreDailyCounts.size(); ++i)
coreDailyCounts[i] = [[dailyCounts _webkit_numberAtIndex:i] intValue];
for (size_t i = 0; i < coreWeeklyCounts.size(); ++i)
coreWeeklyCounts[i] = [[weeklyCounts _webkit_numberAtIndex:i] intValue];
core(_private)->adoptVisitCounts(coreDailyCounts, coreWeeklyCounts);
}
NSArray *childDicts = [dict objectForKey:childrenKey];
if (childDicts) {
for (int i = [childDicts count] - 1; i >= 0; i--) {
......@@ -401,6 +418,11 @@ static WebWindowWatcher *_windowWatcher = nil;
core(_private)->setVisitCount(count);
}
- (void)_recordInitialVisit
{
core(_private)->recordInitialVisit();
}
@end
@implementation WebHistoryItem (WebPrivate)
......@@ -413,7 +435,7 @@ static WebWindowWatcher *_windowWatcher = nil;
- (NSDictionary *)dictionaryRepresentation
{
ASSERT_MAIN_THREAD();
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:6];
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:8];
HistoryItem* coreItem = core(_private);
......@@ -446,6 +468,24 @@ static WebWindowWatcher *_windowWatcher = nil;
[result release];
}
const Vector<int>& dailyVisitCounts = coreItem->dailyVisitCounts();
if (dailyVisitCounts.size()) {
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:13];
for (size_t i = 0; i < dailyVisitCounts.size(); ++i)
[array addObject:[NSNumber numberWithInt:dailyVisitCounts[i]]];
[dict setObject:array forKey:dailyVisitCountKey];
[array release];
}
const Vector<int>& weeklyVisitCounts = coreItem->weeklyVisitCounts();
if (weeklyVisitCounts.size()) {
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:5];
for (size_t i = 0; i < weeklyVisitCounts.size(); ++i)
[array addObject:[NSNumber numberWithInt:weeklyVisitCounts[i]]];
[dict setObject:array forKey:weeklyVisitCountKey];
[array release];
}
if (coreItem->children().size()) {
const HistoryItemVector& children = coreItem->children();
NSMutableArray *childDicts = [NSMutableArray arrayWithCapacity:children.size()];
......@@ -583,6 +623,20 @@ static WebWindowWatcher *_windowWatcher = nil;
return [result autorelease];
}
- (size_t)_getDailyVisitCounts:(const int**)counts
{
HistoryItem* coreItem = core(_private);
*counts = coreItem->dailyVisitCounts().data();
return coreItem->dailyVisitCounts().size();
}
- (size_t)_getWeeklyVisitCounts:(const int**)counts
{
HistoryItem* coreItem = core(_private);
*counts = coreItem->weeklyVisitCounts().data();
return coreItem->weeklyVisitCounts().size();
}
@end
......
......@@ -53,6 +53,7 @@ extern void WKNotifyHistoryItemChanged();
- (void)setTitle:(NSString *)title;
- (void)_visitedWithTitle:(NSString *)title;
- (void)_setVisitCount:(int)count;
- (void)_recordInitialVisit;
@end
......
......@@ -61,4 +61,7 @@
- (id)_transientPropertyForKey:(NSString *)key;
- (void)_setTransientProperty:(id)property forKey:(NSString *)key;
- (size_t)_getDailyVisitCounts:(const int**)counts;
- (size_t)_getWeeklyVisitCounts:(const int**)counts;
@end
......@@ -28,6 +28,12 @@
#import <Cocoa/Cocoa.h>
@interface NSArray (WebNSArrayExtras)
-(NSNumber *)_webkit_numberAtIndex:(NSUInteger)index;
-(NSString *)_webkit_stringAtIndex:(NSUInteger)index;
@end
@interface NSMutableArray (WebNSArrayExtras)
......
......@@ -30,7 +30,23 @@
#import <wtf/Assertions.h>
@implementation NSMutableArray (WebExtras)
@implementation NSArray (WebNSArrayExtras)
-(NSNumber *)_webkit_numberAtIndex:(NSUInteger)index
{
id object = [self objectAtIndex:index];
return [object isKindOfClass:[NSNumber class]] ? object : nil;
}
-(NSString *)_webkit_stringAtIndex:(NSUInteger)index
{
id object = [self objectAtIndex:index];
return [object isKindOfClass:[NSString class]] ? object : nil;
}
@end
@implementation NSMutableArray (WebNSArrayExtras)
- (void)_webkit_removeUselessMenuItemSeparators
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment