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

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

Issue 11308295: Revert 170483 - Remove PrefObserver usages, batch 12. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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( 162 local_pref_registrar_.Add(prefs::kAllowFileSelectionDialogs, this);
163 prefs::kAllowFileSelectionDialogs, 163 local_pref_registrar_.Add(prefs::kInManagedMode, this);
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)));
172 } 164 }
173 165
174 profile_pref_registrar_.Init(profile()->GetPrefs()); 166 profile_pref_registrar_.Init(profile()->GetPrefs());
175 profile_pref_registrar_.Add( 167 profile_pref_registrar_.Add(prefs::kDevToolsDisabled, this);
176 prefs::kDevToolsDisabled, 168 profile_pref_registrar_.Add(prefs::kEditBookmarksEnabled, this);
177 base::Bind(&BrowserCommandController::UpdateCommandsForDevTools, 169 profile_pref_registrar_.Add(prefs::kShowBookmarkBar, this);
178 base::Unretained(this))); 170 profile_pref_registrar_.Add(prefs::kIncognitoModeAvailability, this);
179 profile_pref_registrar_.Add( 171 profile_pref_registrar_.Add(prefs::kPrintingEnabled, this);
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)));
196 172
197 InitCommandState(); 173 InitCommandState();
198 174
199 TabRestoreService* tab_restore_service = 175 TabRestoreService* tab_restore_service =
200 TabRestoreServiceFactory::GetForProfile(profile()); 176 TabRestoreServiceFactory::GetForProfile(profile());
201 if (tab_restore_service) { 177 if (tab_restore_service) {
202 tab_restore_service->AddObserver(this); 178 tab_restore_service->AddObserver(this);
203 TabRestoreServiceChanged(tab_restore_service); 179 TabRestoreServiceChanged(tab_restore_service);
204 } 180 }
205 181
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 case content::NOTIFICATION_INTERSTITIAL_DETACHED: 677 case content::NOTIFICATION_INTERSTITIAL_DETACHED:
702 UpdateCommandsForTabState(); 678 UpdateCommandsForTabState();
703 break; 679 break;
704 680
705 default: 681 default:
706 NOTREACHED() << "Got a notification we didn't register for."; 682 NOTREACHED() << "Got a notification we didn't register for.";
707 } 683 }
708 } 684 }
709 685
710 //////////////////////////////////////////////////////////////////////////////// 686 ////////////////////////////////////////////////////////////////////////////////
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 ////////////////////////////////////////////////////////////////////////////////
711 // BrowserCommandController, TabStripModelObserver implementation: 713 // BrowserCommandController, TabStripModelObserver implementation:
712 714
713 void BrowserCommandController::TabInsertedAt(WebContents* contents, 715 void BrowserCommandController::TabInsertedAt(WebContents* contents,
714 int index, 716 int index,
715 bool foreground) { 717 bool foreground) {
716 AddInterstitialObservers(contents); 718 AddInterstitialObservers(contents);
717 } 719 }
718 720
719 void BrowserCommandController::TabDetachedAt(WebContents* contents, int index) { 721 void BrowserCommandController::TabDetachedAt(WebContents* contents, int index) {
720 RemoveInterstitialObservers(contents); 722 RemoveInterstitialObservers(contents);
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
1043 1045
1044 void BrowserCommandController::UpdateCommandsForBookmarkBar() { 1046 void BrowserCommandController::UpdateCommandsForBookmarkBar() {
1045 const bool show_main_ui = 1047 const bool show_main_ui =
1046 IsShowingMainUI(window() && window()->IsFullscreen()); 1048 IsShowingMainUI(window() && window()->IsFullscreen());
1047 command_updater_.UpdateCommandEnabled(IDC_SHOW_BOOKMARK_BAR, 1049 command_updater_.UpdateCommandEnabled(IDC_SHOW_BOOKMARK_BAR,
1048 browser_defaults::bookmarks_enabled && 1050 browser_defaults::bookmarks_enabled &&
1049 !profile()->GetPrefs()->IsManagedPreference(prefs::kShowBookmarkBar) && 1051 !profile()->GetPrefs()->IsManagedPreference(prefs::kShowBookmarkBar) &&
1050 show_main_ui); 1052 show_main_ui);
1051 } 1053 }
1052 1054
1053 void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() {
1054 UpdateSaveAsState();
1055 UpdateOpenFileState();
1056 }
1057
1058 void BrowserCommandController::UpdateCommandsForFullscreenMode( 1055 void BrowserCommandController::UpdateCommandsForFullscreenMode(
1059 FullScreenMode fullscreen_mode) { 1056 FullScreenMode fullscreen_mode) {
1060 const bool show_main_ui = 1057 const bool show_main_ui =
1061 IsShowingMainUI(fullscreen_mode != FULLSCREEN_DISABLED); 1058 IsShowingMainUI(fullscreen_mode != FULLSCREEN_DISABLED);
1062 bool main_not_fullscreen = show_main_ui && 1059 bool main_not_fullscreen = show_main_ui &&
1063 (fullscreen_mode == FULLSCREEN_DISABLED); 1060 (fullscreen_mode == FULLSCREEN_DISABLED);
1064 1061
1065 // Navigation commands 1062 // Navigation commands
1066 command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui); 1063 command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui);
1067 1064
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1200 1197
1201 BrowserWindow* BrowserCommandController::window() { 1198 BrowserWindow* BrowserCommandController::window() {
1202 return browser_->window(); 1199 return browser_->window();
1203 } 1200 }
1204 1201
1205 Profile* BrowserCommandController::profile() { 1202 Profile* BrowserCommandController::profile() {
1206 return browser_->profile(); 1203 return browser_->profile();
1207 } 1204 }
1208 1205
1209 } // namespace chrome 1206 } // 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