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

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

Issue 3045020: Merge 53961 - [Mac] Fix the custom homepages preferences to:... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/472/src/
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
===================================================================
--- chrome/browser/cocoa/custom_home_pages_model.mm (revision 53981)
+++ chrome/browser/cocoa/custom_home_pages_model.mm (working copy)
@@ -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 @@
- (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 @@
- (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.
+- (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 @@
[entries_ addObject:entry];
}
}
+}
+
+- (void)reloadURLs {
+ [self willChangeValueForKey:@"customHomePages"];
+ SessionStartupPref pref(SessionStartupPref::GetStartupPref(profile_));
+ [self setURLsInternal:pref.urls];
[self didChangeValueForKey:@"customHomePages"];
}
@@ -129,4 +133,8 @@
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