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

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: Merge to head for commit 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 81
81 // The amount of left padding that the wrench menu should have. 82 // The amount of left padding that the wrench menu should have.
82 const CGFloat kWrenchMenuLeftPadding = 3.0; 83 const CGFloat kWrenchMenuLeftPadding = 3.0;
83 84
84 } // namespace 85 } // namespace
85 86
86 @interface ToolbarController() 87 @interface ToolbarController()
87 @property(assign, nonatomic) Browser* browser; 88 @property(assign, nonatomic) Browser* browser;
88 - (void)addAccessibilityDescriptions; 89 - (void)addAccessibilityDescriptions;
89 - (void)initCommandStatus:(CommandUpdater*)commands; 90 - (void)initCommandStatus:(CommandUpdater*)commands;
90 - (void)prefChanged:(std::string*)prefName; 91 - (void)prefChanged:(const std::string&)prefName;
91 - (BackgroundGradientView*)backgroundGradientView; 92 - (BackgroundGradientView*)backgroundGradientView;
92 - (void)toolbarFrameChanged; 93 - (void)toolbarFrameChanged;
93 - (void)pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:(BOOL)animate; 94 - (void)pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:(BOOL)animate;
94 - (void)maintainMinimumLocationBarWidth; 95 - (void)maintainMinimumLocationBarWidth;
95 - (void)adjustBrowserActionsContainerForNewWindow:(NSNotification*)notification; 96 - (void)adjustBrowserActionsContainerForNewWindow:(NSNotification*)notification;
96 - (void)browserActionsContainerDragged:(NSNotification*)notification; 97 - (void)browserActionsContainerDragged:(NSNotification*)notification;
97 - (void)browserActionsContainerDragFinished:(NSNotification*)notification; 98 - (void)browserActionsContainerDragFinished:(NSNotification*)notification;
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 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 setOverlayImageID:UpgradeDetector::GetInstance()->GetIconResourceID( 562 setOverlayImageID:UpgradeDetector::GetInstance()->GetIconResourceID(
557 UpgradeDetector::UPGRADE_ICON_TYPE_BADGE)]; 563 UpgradeDetector::UPGRADE_ICON_TYPE_BADGE)];
558 return; 564 return;
559 } 565 }
560 566
561 int error_badge_id = GlobalErrorServiceFactory::GetForProfile( 567 int error_badge_id = GlobalErrorServiceFactory::GetForProfile(
562 browser_->profile())->GetFirstBadgeResourceID(); 568 browser_->profile())->GetFirstBadgeResourceID();
563 [[wrenchButton_ cell] setOverlayImageID:error_badge_id]; 569 [[wrenchButton_ cell] setOverlayImageID:error_badge_id];
564 } 570 }
565 571
566 - (void)prefChanged:(std::string*)prefName { 572 - (void)prefChanged:(const std::string&)prefName {
567 if (!prefName) return; 573 if (prefName == prefs::kShowHomeButton) {
568 if (*prefName == prefs::kShowHomeButton) {
569 [self showOptionalHomeButton]; 574 [self showOptionalHomeButton];
570 } 575 }
571 } 576 }
572 577
573 - (void)createBrowserActionButtons { 578 - (void)createBrowserActionButtons {
574 if (!browserActionsController_.get()) { 579 if (!browserActionsController_.get()) {
575 browserActionsController_.reset([[BrowserActionsController alloc] 580 browserActionsController_.reset([[BrowserActionsController alloc]
576 initWithBrowser:browser_ 581 initWithBrowser:browser_
577 containerView:browserActionsContainerView_]); 582 containerView:browserActionsContainerView_]);
578 [[NSNotificationCenter defaultCenter] 583 [[NSNotificationCenter defaultCenter]
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 - (void)hideDropURLsIndicatorInView:(NSView*)view { 800 - (void)hideDropURLsIndicatorInView:(NSView*)view {
796 // Do nothing. 801 // Do nothing.
797 } 802 }
798 803
799 // (URLDropTargetController protocol) 804 // (URLDropTargetController protocol)
800 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { 805 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info {
801 return drag_util::IsUnsupportedDropData(profile_, info); 806 return drag_util::IsUnsupportedDropData(profile_, info);
802 } 807 }
803 808
804 @end 809 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698