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

Side by Side Diff: chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm

Issue 11345008: Remove content::NotificationObserver dependency from most Prefs code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" 5 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/mac/bundle_locations.h" 9 #include "base/mac/bundle_locations.h"
10 #include "base/mac/mac_util.h" 10 #include "base/mac/mac_util.h"
11 #include "base/memory/singleton.h" 11 #include "base/memory/singleton.h"
12 #include "base/prefs/public/pref_observer.h"
12 #include "base/string_util.h" 13 #include "base/string_util.h"
13 #include "base/sys_string_conversions.h" 14 #include "base/sys_string_conversions.h"
14 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
15 #include "chrome/app/chrome_command_ids.h" 16 #include "chrome/app/chrome_command_ids.h"
16 #include "chrome/browser/autocomplete/autocomplete_classifier.h" 17 #include "chrome/browser/autocomplete/autocomplete_classifier.h"
17 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" 18 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
18 #include "chrome/browser/autocomplete/autocomplete_match.h" 19 #include "chrome/browser/autocomplete/autocomplete_match.h"
19 #include "chrome/browser/command_updater.h" 20 #include "chrome/browser/command_updater.h"
20 #include "chrome/browser/net/url_fixer_upper.h" 21 #include "chrome/browser/net/url_fixer_upper.h"
21 #include "chrome/browser/prefs/pref_service.h" 22 #include "chrome/browser/prefs/pref_service.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 - (void)browserActionsVisibilityChanged:(NSNotification*)notification; 99 - (void)browserActionsVisibilityChanged:(NSNotification*)notification;
99 - (void)adjustLocationSizeBy:(CGFloat)dX animate:(BOOL)animate; 100 - (void)adjustLocationSizeBy:(CGFloat)dX animate:(BOOL)animate;
100 - (void)badgeWrenchMenuIfNeeded; 101 - (void)badgeWrenchMenuIfNeeded;
101 @end 102 @end
102 103
103 namespace ToolbarControllerInternal { 104 namespace ToolbarControllerInternal {
104 105
105 // A class registered for C++ notifications. This is used to detect changes in 106 // A class registered for C++ notifications. This is used to detect changes in
106 // preferences and upgrade available notifications. Bridges the notification 107 // preferences and upgrade available notifications. Bridges the notification
107 // back to the ToolbarController. 108 // back to the ToolbarController.
108 class NotificationBridge : public content::NotificationObserver { 109 class NotificationBridge
110 : public content::NotificationObserver,
111 public PrefObserver {
109 public: 112 public:
110 explicit NotificationBridge(ToolbarController* controller) 113 explicit NotificationBridge(ToolbarController* controller)
111 : controller_(controller) { 114 : controller_(controller) {
112 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED, 115 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
113 content::NotificationService::AllSources()); 116 content::NotificationService::AllSources());
114 registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED, 117 registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED,
115 content::Source<Profile>([controller browser]->profile())); 118 content::Source<Profile>([controller browser]->profile()));
116 } 119 }
117 120
118 // Overridden from content::NotificationObserver: 121 // Overridden from content::NotificationObserver:
119 virtual void Observe(int type, 122 virtual void Observe(int type,
120 const content::NotificationSource& source, 123 const content::NotificationSource& source,
121 const content::NotificationDetails& details) { 124 const content::NotificationDetails& details) OVERRIDE {
122 switch (type) { 125 switch (type) {
123 case chrome::NOTIFICATION_PREF_CHANGED:
124 [controller_ prefChanged:content::Details<std::string>(details).ptr()];
125 break;
126 case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: 126 case chrome::NOTIFICATION_UPGRADE_RECOMMENDED:
127 case chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED: 127 case chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED:
128 [controller_ badgeWrenchMenuIfNeeded]; 128 [controller_ badgeWrenchMenuIfNeeded];
129 break; 129 break;
130 default: 130 default:
131 NOTREACHED(); 131 NOTREACHED();
132 } 132 }
133 } 133 }
134 134
135 // Overridden from PrefObserver:
136 virtual void OnPreferenceChanged(PrefServiceBase* service,
137 const std::string& pref_name) OVERRIDE {
138 [controller_ prefChanged:&pref_name];
139 }
140
135 private: 141 private:
136 ToolbarController* controller_; // weak, owns us 142 ToolbarController* controller_; // weak, owns us
137 143
138 content::NotificationRegistrar registrar_; 144 content::NotificationRegistrar registrar_;
139 }; 145 };
140 146
141 } // namespace ToolbarControllerInternal 147 } // namespace ToolbarControllerInternal
142 148
143 @implementation ToolbarController 149 @implementation ToolbarController
144 150
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 - (void)hideDropURLsIndicatorInView:(NSView*)view { 801 - (void)hideDropURLsIndicatorInView:(NSView*)view {
796 // Do nothing. 802 // Do nothing.
797 } 803 }
798 804
799 // (URLDropTargetController protocol) 805 // (URLDropTargetController protocol)
800 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { 806 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info {
801 return drag_util::IsUnsupportedDropData(profile_, info); 807 return drag_util::IsUnsupportedDropData(profile_, info);
802 } 808 }
803 809
804 @end 810 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698