diff options
-rw-r--r-- | chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm | 8 | ||||
-rw-r--r-- | chrome/browser/ui/global_error_service.cc | 13 | ||||
-rw-r--r-- | chrome/browser/ui/global_error_service.h | 11 | ||||
-rw-r--r-- | chrome/browser/ui/global_error_service_factory.cc | 2 | ||||
-rw-r--r-- | chrome/browser/ui/global_error_service_unittest.cc | 8 | ||||
-rw-r--r-- | chrome/browser/ui/gtk/browser_toolbar_gtk.cc | 6 | ||||
-rw-r--r-- | chrome/browser/ui/views/toolbar_view.cc | 26 | ||||
-rw-r--r-- | chrome/common/chrome_notification_types.h | 6 |
8 files changed, 62 insertions, 18 deletions
diff --git a/chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm b/chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm index 7c72d56..355ca55 100644 --- a/chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm +++ b/chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm @@ -81,7 +81,8 @@ const CGFloat kWrenchMenuLeftPadding = 3.0; } // namespace -@interface ToolbarController(Private) +@interface ToolbarController() +@property(assign, nonatomic) Browser* browser; - (void)addAccessibilityDescriptions; - (void)initCommandStatus:(CommandUpdater*)commands; - (void)prefChanged:(std::string*)prefName; @@ -128,6 +129,8 @@ class NotificationBridge : public NotificationObserver { : controller_(controller) { registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED, NotificationService::AllSources()); + registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED, + Source<Profile>([controller browser]->profile())); } // Overridden from NotificationObserver: @@ -139,6 +142,7 @@ class NotificationBridge : public NotificationObserver { [controller_ prefChanged:Details<std::string>(details).ptr()]; break; case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: + case chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED: [controller_ badgeWrenchMenuIfNeeded]; break; default: @@ -156,6 +160,8 @@ class NotificationBridge : public NotificationObserver { @implementation ToolbarController +@synthesize browser = browser_; + - (id)initWithModel:(ToolbarModel*)model commands:(CommandUpdater*)commands profile:(Profile*)profile diff --git a/chrome/browser/ui/global_error_service.cc b/chrome/browser/ui/global_error_service.cc index 566276b..995020b9 100644 --- a/chrome/browser/ui/global_error_service.cc +++ b/chrome/browser/ui/global_error_service.cc @@ -8,8 +8,10 @@ #include "base/stl_util.h" #include "chrome/browser/ui/global_error.h" +#include "chrome/common/chrome_notification_types.h" +#include "content/common/notification_service.h" -GlobalErrorService::GlobalErrorService() { +GlobalErrorService::GlobalErrorService(Profile* profile) : profile_(profile) { } GlobalErrorService::~GlobalErrorService() { @@ -18,10 +20,12 @@ GlobalErrorService::~GlobalErrorService() { void GlobalErrorService::AddGlobalError(GlobalError* error) { errors_.push_back(error); + NotifyErrorsChanged(error); } void GlobalErrorService::RemoveGlobalError(GlobalError* error) { errors_.erase(std::find(errors_.begin(), errors_.end(), error)); + NotifyErrorsChanged(error); } GlobalError* GlobalErrorService::GetGlobalErrorByMenuItemCommandID( @@ -54,3 +58,10 @@ GlobalError* GlobalErrorService::GetFirstGlobalErrorWithBubbleView() const { } return NULL; } + +void GlobalErrorService::NotifyErrorsChanged(GlobalError* error) { + NotificationService::current()->Notify( + chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED, + Source<Profile>(profile_), + Details<GlobalError>(error)); +} diff --git a/chrome/browser/ui/global_error_service.h b/chrome/browser/ui/global_error_service.h index 500cf2f..5ee29c6 100644 --- a/chrome/browser/ui/global_error_service.h +++ b/chrome/browser/ui/global_error_service.h @@ -12,6 +12,7 @@ #include "chrome/browser/profiles/profile_keyed_service.h" class GlobalError; +class Profile; // This service manages a list of errors that are meant to be shown globally. // If an error applies to an entire profile and not just to a tab then the @@ -20,7 +21,9 @@ class GlobalError; // - a sync error occurred class GlobalErrorService : public ProfileKeyedService { public: - GlobalErrorService(); + // Constructs a GlobalErrorService object for the given profile. The profile + // maybe NULL for tests. + explicit GlobalErrorService(Profile* profile); virtual ~GlobalErrorService(); // Adds the given error to the list of global errors and displays it on @@ -48,8 +51,14 @@ class GlobalErrorService : public ProfileKeyedService { // Gets all errors. const std::vector<GlobalError*>& errors() { return errors_; } + // Post a notification that a global error has changed and that the error UI + // should update it self. Pass NULL for the given error to mean all error UIs + // should update. + void NotifyErrorsChanged(GlobalError* error); + private: std::vector<GlobalError*> errors_; + Profile* profile_; DISALLOW_COPY_AND_ASSIGN(GlobalErrorService); }; diff --git a/chrome/browser/ui/global_error_service_factory.cc b/chrome/browser/ui/global_error_service_factory.cc index a0148eb..e2c69a5 100644 --- a/chrome/browser/ui/global_error_service_factory.cc +++ b/chrome/browser/ui/global_error_service_factory.cc @@ -27,7 +27,7 @@ GlobalErrorServiceFactory::~GlobalErrorServiceFactory() { ProfileKeyedService* GlobalErrorServiceFactory::BuildServiceInstanceFor( Profile* profile) const { - return new GlobalErrorService(); + return new GlobalErrorService(profile); } bool GlobalErrorServiceFactory::ServiceRedirectedInIncognito() { diff --git a/chrome/browser/ui/global_error_service_unittest.cc b/chrome/browser/ui/global_error_service_unittest.cc index 0135a9f..2c16bc2 100644 --- a/chrome/browser/ui/global_error_service_unittest.cc +++ b/chrome/browser/ui/global_error_service_unittest.cc @@ -108,7 +108,7 @@ class MenuError : public BaseError { // Test adding errors to the global error service. TEST(GlobalErrorServiceTest, AddError) { - scoped_ptr<GlobalErrorService> service(new GlobalErrorService); + scoped_ptr<GlobalErrorService> service(new GlobalErrorService(NULL)); EXPECT_EQ(0u, service->errors().size()); BaseError* error1 = new BaseError; @@ -130,7 +130,7 @@ TEST(GlobalErrorServiceTest, AddError) { // Test removing errors from the global error service. TEST(GlobalErrorServiceTest, RemoveError) { - scoped_ptr<GlobalErrorService> service(new GlobalErrorService); + scoped_ptr<GlobalErrorService> service(new GlobalErrorService(NULL)); BaseError error1; service->AddGlobalError(&error1); BaseError error2; @@ -155,7 +155,7 @@ TEST(GlobalErrorServiceTest, GetMenuItem) { MenuError* error2 = new MenuError(2); MenuError* error3 = new MenuError(3); - GlobalErrorService service; + GlobalErrorService service(NULL); service.AddGlobalError(error1); service.AddGlobalError(error2); service.AddGlobalError(error3); @@ -171,7 +171,7 @@ TEST(GlobalErrorServiceTest, GetBadgeID) { BadgeError error2(2); BadgeError* error3 = new BadgeError(3); - GlobalErrorService service; + GlobalErrorService service(NULL); EXPECT_EQ(0, service.GetFirstBadgeResourceID()); service.AddGlobalError(error1); diff --git a/chrome/browser/ui/gtk/browser_toolbar_gtk.cc b/chrome/browser/ui/gtk/browser_toolbar_gtk.cc index 8e64303..257be4d 100644 --- a/chrome/browser/ui/gtk/browser_toolbar_gtk.cc +++ b/chrome/browser/ui/gtk/browser_toolbar_gtk.cc @@ -100,6 +100,9 @@ BrowserToolbarGtk::BrowserToolbarGtk(Browser* browser, BrowserWindowGtk* window) registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED, NotificationService::AllSources()); + registrar_.Add(this, + chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED, + Source<Profile>(browser_->profile())); } BrowserToolbarGtk::~BrowserToolbarGtk() { @@ -380,7 +383,8 @@ void BrowserToolbarGtk::Observe(int type, } UpdateRoundedness(); - } else if (type == chrome::NOTIFICATION_UPGRADE_RECOMMENDED) { + } else if (type == chrome::NOTIFICATION_UPGRADE_RECOMMENDED || + type == chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED) { // Redraw the wrench menu to update the badge. gtk_widget_queue_draw(wrench_menu_button_->widget()); } else if (type == content::NOTIFICATION_ZOOM_LEVEL_CHANGED) { diff --git a/chrome/browser/ui/views/toolbar_view.cc b/chrome/browser/ui/views/toolbar_view.cc index 0ab4c94..6c6b5e2 100644 --- a/chrome/browser/ui/views/toolbar_view.cc +++ b/chrome/browser/ui/views/toolbar_view.cc @@ -112,6 +112,8 @@ ToolbarView::ToolbarView(Browser* browser) registrar_.Add(this, chrome::NOTIFICATION_MODULE_INCOMPATIBILITY_BADGE_CHANGE, NotificationService::AllSources()); + registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED, + Source<Profile>(browser_->profile())); } ToolbarView::~ToolbarView() { @@ -399,16 +401,22 @@ void ToolbarView::ButtonPressed(views::Button* sender, void ToolbarView::Observe(int type, const NotificationSource& source, const NotificationDetails& details) { - if (type == chrome::NOTIFICATION_PREF_CHANGED) { - std::string* pref_name = Details<std::string>(details).ptr(); - if (*pref_name == prefs::kShowHomeButton) { - Layout(); - SchedulePaint(); + switch (type) { + case chrome::NOTIFICATION_PREF_CHANGED: { + std::string* pref_name = Details<std::string>(details).ptr(); + if (*pref_name == prefs::kShowHomeButton) { + Layout(); + SchedulePaint(); + } + break; } - } else if ( - type == chrome::NOTIFICATION_UPGRADE_RECOMMENDED || - type == chrome::NOTIFICATION_MODULE_INCOMPATIBILITY_BADGE_CHANGE) { - UpdateAppMenuBadge(); + case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: + case chrome::NOTIFICATION_MODULE_INCOMPATIBILITY_BADGE_CHANGE: + case chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED: + UpdateAppMenuBadge(); + break; + default: + NOTREACHED(); } } diff --git a/chrome/common/chrome_notification_types.h b/chrome/common/chrome_notification_types.h index ca730fc..802db9f 100644 --- a/chrome/common/chrome_notification_types.h +++ b/chrome/common/chrome_notification_types.h @@ -900,6 +900,12 @@ enum NotificationType { // Sent when all nonblocking bounds animations are finished across panels. NOTIFICATION_PANEL_BOUNDS_ANIMATIONS_FINISHED, + // Sent when a global error has changed and the error UI should update it + // self. The source is a Source<Profile> containing the profile for the + // error. The detail is a GlobalError object that has changed or NULL if + // all error UIs should update. + NOTIFICATION_GLOBAL_ERRORS_CHANGED, + // Note:- // Currently only Content and Chrome define and use notifications. // Custom notifications not belonging to Content and Chrome should start |