Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5488)

Unified Diff: chrome/browser/cocoa/custom_home_pages_model.mm

Issue 3023023: [Mac] Fix the custom homepages preferences. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/cocoa/custom_home_pages_model.mm
diff --git a/chrome/browser/cocoa/custom_home_pages_model.mm b/chrome/browser/cocoa/custom_home_pages_model.mm
index 084cf114c31bf65c1fcaa19214772745b290d3ae..9d47c415cadb649a34b83768edfec429d447210c 100644
--- a/chrome/browser/cocoa/custom_home_pages_model.mm
+++ b/chrome/browser/cocoa/custom_home_pages_model.mm
@@ -5,29 +5,16 @@
#import "chrome/browser/cocoa/custom_home_pages_model.h"
#include "base/sys_string_conversions.h"
-#include "chrome/browser/history/history.h"
#include "chrome/browser/net/url_fixer_upper.h"
+#include "chrome/browser/session_startup_pref.h"
NSString* const kHomepageEntryChangedNotification =
@"kHomepageEntryChangedNotification";
-// An entry representing a single item in the custom home page model. Stores
-// a url and a favicon.
-@interface CustomHomePageEntry : NSObject {
- @private
- scoped_nsobject<NSString> url_;
- scoped_nsobject<NSImage> icon_;
-
- // If non-zero, indicates we're loading the favicon for the page.
- HistoryService::Handle icon_handle_;
-}
-@property(nonatomic, copy) NSString* URL;
-@property(nonatomic, retain) NSImage* image;
+@interface CustomHomePagesModel (Private)
+- (void)setURLsInternal:(const std::vector<GURL>&)urls;
@end
-//----------------------------------------------------------------------------
-
-
@implementation CustomHomePagesModel
- (id)initWithProfile:(Profile*)profile {
@@ -52,6 +39,8 @@ NSString* const kHomepageEntryChangedNotification =
- (void)removeObjectFromCustomHomePagesAtIndex:(NSUInteger)index {
[entries_ removeObjectAtIndex:index];
+ // Force a save.
+ [self validateURLs];
}
// Get/set the urls the model currently contains as a group. These will weed
@@ -70,6 +59,15 @@ NSString* const kHomepageEntryChangedNotification =
- (void)setURLs:(const std::vector<GURL>&)urls {
[self willChangeValueForKey:@"customHomePages"];
+ [self setURLsInternal:urls];
+ SessionStartupPref pref(SessionStartupPref::GetStartupPref(profile_));
+ pref.urls = urls;
+ SessionStartupPref::SetStartupPref(profile_, pref);
+ [self didChangeValueForKey:@"customHomePages"];
+}
+
+// Converts the C++ URLs to Cocoa objects without notifying KVO.
pink (ping after 24hrs) 2010/07/28 14:49:18 Should you explain why you don't want to notify kv
+- (void)setURLsInternal:(const std::vector<GURL>&)urls {
[entries_ removeAllObjects];
for (size_t i = 0; i < urls.size(); ++i) {
scoped_nsobject<CustomHomePageEntry> entry(
@@ -81,6 +79,12 @@ NSString* const kHomepageEntryChangedNotification =
[entries_ addObject:entry];
}
}
+}
+
+- (void)reloadURLs {
+ [self willChangeValueForKey:@"customHomePages"];
+ SessionStartupPref pref(SessionStartupPref::GetStartupPref(profile_));
+ [self setURLsInternal:pref.urls];
[self didChangeValueForKey:@"customHomePages"];
}
@@ -129,4 +133,8 @@ NSString* const kHomepageEntryChangedNotification =
return icon_.get();
}
+- (NSString*)description {
+ return url_.get();
+}
+
@end
« no previous file with comments | « chrome/browser/cocoa/custom_home_pages_model.h ('k') | chrome/browser/cocoa/custom_home_pages_model_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698