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

Side by Side Diff: chrome/browser/ui/browser_command_controller.cc

Issue 11280115: Remove PrefObserver usages, batch 12. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix removal of PrefServiceObserver usage. Created 8 years 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 #include "chrome/browser/ui/browser_command_controller.h" 5 #include "chrome/browser/ui/browser_command_controller.h"
6 6
7 #include "chrome/app/chrome_command_ids.h" 7 #include "chrome/app/chrome_command_ids.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/defaults.h" 9 #include "chrome/browser/defaults.h"
10 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 BrowserCommandController::BrowserCommandController(Browser* browser) 152 BrowserCommandController::BrowserCommandController(Browser* browser)
153 : browser_(browser), 153 : browser_(browser),
154 ALLOW_THIS_IN_INITIALIZER_LIST(command_updater_(this)), 154 ALLOW_THIS_IN_INITIALIZER_LIST(command_updater_(this)),
155 block_command_execution_(false), 155 block_command_execution_(false),
156 last_blocked_command_id_(-1), 156 last_blocked_command_id_(-1),
157 last_blocked_command_disposition_(CURRENT_TAB) { 157 last_blocked_command_disposition_(CURRENT_TAB) {
158 browser_->tab_strip_model()->AddObserver(this); 158 browser_->tab_strip_model()->AddObserver(this);
159 PrefService* local_state = g_browser_process->local_state(); 159 PrefService* local_state = g_browser_process->local_state();
160 if (local_state) { 160 if (local_state) {
161 local_pref_registrar_.Init(local_state); 161 local_pref_registrar_.Init(local_state);
162 local_pref_registrar_.Add(prefs::kAllowFileSelectionDialogs, this); 162 local_pref_registrar_.Add(
163 local_pref_registrar_.Add(prefs::kInManagedMode, this); 163 prefs::kAllowFileSelectionDialogs,
164 base::Bind(
165 &BrowserCommandController::UpdateCommandsForFileSelectionDialogs,
166 base::Unretained(this)));
167 local_pref_registrar_.Add(
168 prefs::kInManagedMode,
169 base::Bind(
170 &BrowserCommandController::UpdateCommandsForMultipleProfiles,
171 base::Unretained(this)));
164 } 172 }
165 173
166 profile_pref_registrar_.Init(profile()->GetPrefs()); 174 profile_pref_registrar_.Init(profile()->GetPrefs());
167 profile_pref_registrar_.Add(prefs::kDevToolsDisabled, this); 175 profile_pref_registrar_.Add(
168 profile_pref_registrar_.Add(prefs::kEditBookmarksEnabled, this); 176 prefs::kDevToolsDisabled,
169 profile_pref_registrar_.Add(prefs::kShowBookmarkBar, this); 177 base::Bind(&BrowserCommandController::UpdateCommandsForDevTools,
170 profile_pref_registrar_.Add(prefs::kIncognitoModeAvailability, this); 178 base::Unretained(this)));
171 profile_pref_registrar_.Add(prefs::kPrintingEnabled, this); 179 profile_pref_registrar_.Add(
180 prefs::kEditBookmarksEnabled,
181 base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkEditing,
182 base::Unretained(this)));
183 profile_pref_registrar_.Add(
184 prefs::kShowBookmarkBar,
185 base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkBar,
186 base::Unretained(this)));
187 profile_pref_registrar_.Add(
188 prefs::kIncognitoModeAvailability,
189 base::Bind(
190 &BrowserCommandController::UpdateCommandsForIncognitoAvailability,
191 base::Unretained(this)));
192 profile_pref_registrar_.Add(
193 prefs::kPrintingEnabled,
194 base::Bind(&BrowserCommandController::UpdatePrintingState,
195 base::Unretained(this)));
172 196
173 InitCommandState(); 197 InitCommandState();
174 198
175 TabRestoreService* tab_restore_service = 199 TabRestoreService* tab_restore_service =
176 TabRestoreServiceFactory::GetForProfile(profile()); 200 TabRestoreServiceFactory::GetForProfile(profile());
177 if (tab_restore_service) { 201 if (tab_restore_service) {
178 tab_restore_service->AddObserver(this); 202 tab_restore_service->AddObserver(this);
179 TabRestoreServiceChanged(tab_restore_service); 203 TabRestoreServiceChanged(tab_restore_service);
180 } 204 }
181 205
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 case content::NOTIFICATION_INTERSTITIAL_DETACHED: 701 case content::NOTIFICATION_INTERSTITIAL_DETACHED:
678 UpdateCommandsForTabState(); 702 UpdateCommandsForTabState();
679 break; 703 break;
680 704
681 default: 705 default:
682 NOTREACHED() << "Got a notification we didn't register for."; 706 NOTREACHED() << "Got a notification we didn't register for.";
683 } 707 }
684 } 708 }
685 709
686 //////////////////////////////////////////////////////////////////////////////// 710 ////////////////////////////////////////////////////////////////////////////////
687 // PrefObserver implementation:
688
689 void BrowserCommandController::OnPreferenceChanged(
690 PrefServiceBase* service,
691 const std::string& pref_name) {
692 if (pref_name == prefs::kPrintingEnabled) {
693 UpdatePrintingState();
694 } else if (pref_name == prefs::kIncognitoModeAvailability) {
695 UpdateCommandsForIncognitoAvailability();
696 } else if (pref_name == prefs::kDevToolsDisabled) {
697 UpdateCommandsForDevTools();
698 } else if (pref_name == prefs::kEditBookmarksEnabled) {
699 UpdateCommandsForBookmarkEditing();
700 } else if (pref_name == prefs::kShowBookmarkBar) {
701 UpdateCommandsForBookmarkBar();
702 } else if (pref_name == prefs::kAllowFileSelectionDialogs) {
703 UpdateSaveAsState();
704 UpdateOpenFileState();
705 } else if (pref_name == prefs::kInManagedMode) {
706 UpdateCommandsForMultipleProfiles();
707 } else {
708 NOTREACHED();
709 }
710 }
711
712 ////////////////////////////////////////////////////////////////////////////////
713 // BrowserCommandController, TabStripModelObserver implementation: 711 // BrowserCommandController, TabStripModelObserver implementation:
714 712
715 void BrowserCommandController::TabInsertedAt(WebContents* contents, 713 void BrowserCommandController::TabInsertedAt(WebContents* contents,
716 int index, 714 int index,
717 bool foreground) { 715 bool foreground) {
718 AddInterstitialObservers(contents); 716 AddInterstitialObservers(contents);
719 } 717 }
720 718
721 void BrowserCommandController::TabDetachedAt(WebContents* contents, int index) { 719 void BrowserCommandController::TabDetachedAt(WebContents* contents, int index) {
722 RemoveInterstitialObservers(contents); 720 RemoveInterstitialObservers(contents);
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
1045 1043
1046 void BrowserCommandController::UpdateCommandsForBookmarkBar() { 1044 void BrowserCommandController::UpdateCommandsForBookmarkBar() {
1047 const bool show_main_ui = 1045 const bool show_main_ui =
1048 IsShowingMainUI(window() && window()->IsFullscreen()); 1046 IsShowingMainUI(window() && window()->IsFullscreen());
1049 command_updater_.UpdateCommandEnabled(IDC_SHOW_BOOKMARK_BAR, 1047 command_updater_.UpdateCommandEnabled(IDC_SHOW_BOOKMARK_BAR,
1050 browser_defaults::bookmarks_enabled && 1048 browser_defaults::bookmarks_enabled &&
1051 !profile()->GetPrefs()->IsManagedPreference(prefs::kShowBookmarkBar) && 1049 !profile()->GetPrefs()->IsManagedPreference(prefs::kShowBookmarkBar) &&
1052 show_main_ui); 1050 show_main_ui);
1053 } 1051 }
1054 1052
1053 void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() {
1054 UpdateSaveAsState();
1055 UpdateOpenFileState();
1056 }
1057
1055 void BrowserCommandController::UpdateCommandsForFullscreenMode( 1058 void BrowserCommandController::UpdateCommandsForFullscreenMode(
1056 FullScreenMode fullscreen_mode) { 1059 FullScreenMode fullscreen_mode) {
1057 const bool show_main_ui = 1060 const bool show_main_ui =
1058 IsShowingMainUI(fullscreen_mode != FULLSCREEN_DISABLED); 1061 IsShowingMainUI(fullscreen_mode != FULLSCREEN_DISABLED);
1059 bool main_not_fullscreen = show_main_ui && 1062 bool main_not_fullscreen = show_main_ui &&
1060 (fullscreen_mode == FULLSCREEN_DISABLED); 1063 (fullscreen_mode == FULLSCREEN_DISABLED);
1061 1064
1062 // Navigation commands 1065 // Navigation commands
1063 command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui); 1066 command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui);
1064 1067
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1197 1200
1198 BrowserWindow* BrowserCommandController::window() { 1201 BrowserWindow* BrowserCommandController::window() {
1199 return browser_->window(); 1202 return browser_->window();
1200 } 1203 }
1201 1204
1202 Profile* BrowserCommandController::profile() { 1205 Profile* BrowserCommandController::profile() {
1203 return browser_->profile(); 1206 return browser_->profile();
1204 } 1207 }
1205 1208
1206 } // namespace chrome 1209 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_command_controller.h ('k') | chrome/browser/ui/cocoa/browser_window_cocoa.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698