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

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

Issue 12088040: Add a SigninAllowed policy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Some bugfixes. Created 7 years, 10 months 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"
11 #include "chrome/browser/prefs/incognito_mode_prefs.h" 11 #include "chrome/browser/prefs/incognito_mode_prefs.h"
12 #include "chrome/browser/prefs/pref_service.h" 12 #include "chrome/browser/prefs/pref_service.h"
13 #include "chrome/browser/profiles/avatar_menu_model.h" 13 #include "chrome/browser/profiles/avatar_menu_model.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/profiles/profile_manager.h" 15 #include "chrome/browser/profiles/profile_manager.h"
16 #include "chrome/browser/sessions/tab_restore_service.h" 16 #include "chrome/browser/sessions/tab_restore_service.h"
17 #include "chrome/browser/sessions/tab_restore_service_factory.h" 17 #include "chrome/browser/sessions/tab_restore_service_factory.h"
18 #include "chrome/browser/shell_integration.h" 18 #include "chrome/browser/shell_integration.h"
19 #include "chrome/browser/signin/signin_manager.h"
20 #include "chrome/browser/signin/signin_manager_factory.h"
19 #include "chrome/browser/sync/profile_sync_service.h" 21 #include "chrome/browser/sync/profile_sync_service.h"
20 #include "chrome/browser/sync/profile_sync_service_factory.h" 22 #include "chrome/browser/sync/profile_sync_service_factory.h"
21 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" 23 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
22 #include "chrome/browser/ui/browser.h" 24 #include "chrome/browser/ui/browser.h"
23 #include "chrome/browser/ui/browser_commands.h" 25 #include "chrome/browser/ui/browser_commands.h"
24 #include "chrome/browser/ui/browser_window.h" 26 #include "chrome/browser/ui/browser_window.h"
25 #include "chrome/browser/ui/chrome_pages.h" 27 #include "chrome/browser/ui/chrome_pages.h"
26 #include "chrome/browser/ui/tabs/tab_strip_model.h" 28 #include "chrome/browser/ui/tabs/tab_strip_model.h"
27 #include "chrome/browser/ui/tabs/tab_strip_model_utils.h" 29 #include "chrome/browser/ui/tabs/tab_strip_model_utils.h"
28 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" 30 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h"
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 base::Unretained(this))); 205 base::Unretained(this)));
204 206
205 InitCommandState(); 207 InitCommandState();
206 208
207 TabRestoreService* tab_restore_service = 209 TabRestoreService* tab_restore_service =
208 TabRestoreServiceFactory::GetForProfile(profile()); 210 TabRestoreServiceFactory::GetForProfile(profile());
209 if (tab_restore_service) { 211 if (tab_restore_service) {
210 tab_restore_service->AddObserver(this); 212 tab_restore_service->AddObserver(this);
211 TabRestoreServiceChanged(tab_restore_service); 213 TabRestoreServiceChanged(tab_restore_service);
212 } 214 }
215
216 SigninManager* signin =
217 SigninManagerFactory::GetInstance()->GetForProfile(
218 profile()->GetOriginalProfile());
219 if (signin)
220 signin->AddSigninPrefObserver(this);
Andrew T Wilson (Slow) 2013/02/04 15:41:48 I don't think we want to define a new SigninPrefOb
Adrian Kuegel 2013/02/05 10:55:15 I removed the SigninPrefObserver now. You are righ
213 } 221 }
214 222
215 BrowserCommandController::~BrowserCommandController() { 223 BrowserCommandController::~BrowserCommandController() {
224 SigninManager* signin = SigninManagerFactory::GetInstance()->GetForProfile(
225 profile()->GetOriginalProfile());
226 if (signin)
227 signin->RemoveSigninPrefObserver(this);
228
216 // TabRestoreService may have been shutdown by the time we get here. Don't 229 // TabRestoreService may have been shutdown by the time we get here. Don't
217 // trigger creating it. 230 // trigger creating it.
218 TabRestoreService* tab_restore_service = 231 TabRestoreService* tab_restore_service =
219 TabRestoreServiceFactory::GetForProfileIfExisting(profile()); 232 TabRestoreServiceFactory::GetForProfileIfExisting(profile());
220 if (tab_restore_service) 233 if (tab_restore_service)
221 tab_restore_service->RemoveObserver(this); 234 tab_restore_service->RemoveObserver(this);
222 profile_pref_registrar_.RemoveAll(); 235 profile_pref_registrar_.RemoveAll();
223 local_pref_registrar_.RemoveAll(); 236 local_pref_registrar_.RemoveAll();
224 browser_->tab_strip_model()->RemoveObserver(this); 237 browser_->tab_strip_model()->RemoveObserver(this);
225 if (profile_manager_) 238 if (profile_manager_)
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 void BrowserCommandController::OnProfileNameChanged( 748 void BrowserCommandController::OnProfileNameChanged(
736 const FilePath& profile_path, 749 const FilePath& profile_path,
737 const string16& old_profile_name) { 750 const string16& old_profile_name) {
738 } 751 }
739 752
740 void BrowserCommandController::OnProfileAvatarChanged( 753 void BrowserCommandController::OnProfileAvatarChanged(
741 const FilePath& profile_path) { 754 const FilePath& profile_path) {
742 } 755 }
743 756
744 //////////////////////////////////////////////////////////////////////////////// 757 ////////////////////////////////////////////////////////////////////////////////
758 // BrowserCommandController, SigninPrefObserver implementation:
759
760 void BrowserCommandController::OnSigninAllowedPrefChange(bool signin_allowed) {
761 // For unit tests, we don't have a window.
762 if (!window())
763 return;
764 const bool show_main_ui = IsShowingMainUI(window()->IsFullscreen());
765 command_updater_.UpdateCommandEnabled(IDC_SHOW_SYNC_SETUP,
766 show_main_ui && signin_allowed);
767 }
768
745 // BrowserCommandController, TabStripModelObserver implementation: 769 // BrowserCommandController, TabStripModelObserver implementation:
746 770
747 void BrowserCommandController::TabInsertedAt(WebContents* contents, 771 void BrowserCommandController::TabInsertedAt(WebContents* contents,
748 int index, 772 int index,
749 bool foreground) { 773 bool foreground) {
750 AddInterstitialObservers(contents); 774 AddInterstitialObservers(contents);
751 } 775 }
752 776
753 void BrowserCommandController::TabDetachedAt(WebContents* contents, int index) { 777 void BrowserCommandController::TabDetachedAt(WebContents* contents, int index) {
754 RemoveInterstitialObservers(contents); 778 RemoveInterstitialObservers(contents);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 !profile()->IsGuestSession()); 898 !profile()->IsGuestSession());
875 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true); 899 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true);
876 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true); 900 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true);
877 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true); 901 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true);
878 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, 902 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU,
879 !profile()->IsGuestSession()); 903 !profile()->IsGuestSession());
880 command_updater_.UpdateCommandEnabled(IDC_RECENT_TABS_MENU, 904 command_updater_.UpdateCommandEnabled(IDC_RECENT_TABS_MENU,
881 !profile()->IsGuestSession() && 905 !profile()->IsGuestSession() &&
882 !profile()->IsOffTheRecord()); 906 !profile()->IsOffTheRecord());
883 907
884 command_updater_.UpdateCommandEnabled(IDC_SHOW_SIGNIN, true); 908 command_updater_.UpdateCommandEnabled(
909 IDC_SHOW_SYNC_SETUP,
910 profile()->GetOriginalProfile()->IsSigninAllowed());
885 911
886 // Initialize other commands based on the window type. 912 // Initialize other commands based on the window type.
887 bool normal_window = browser_->is_type_tabbed(); 913 bool normal_window = browser_->is_type_tabbed();
888 914
889 // Navigation commands 915 // Navigation commands
890 command_updater_.UpdateCommandEnabled(IDC_HOME, normal_window); 916 command_updater_.UpdateCommandEnabled(IDC_HOME, normal_window);
891 917
892 // Window management commands 918 // Window management commands
893 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window); 919 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window);
894 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, 920 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB,
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 command_updater_.UpdateCommandEnabled( 1135 command_updater_.UpdateCommandEnabled(
1110 IDC_FOCUS_NEXT_PANE, main_not_fullscreen); 1136 IDC_FOCUS_NEXT_PANE, main_not_fullscreen);
1111 command_updater_.UpdateCommandEnabled( 1137 command_updater_.UpdateCommandEnabled(
1112 IDC_FOCUS_PREVIOUS_PANE, main_not_fullscreen); 1138 IDC_FOCUS_PREVIOUS_PANE, main_not_fullscreen);
1113 command_updater_.UpdateCommandEnabled( 1139 command_updater_.UpdateCommandEnabled(
1114 IDC_FOCUS_BOOKMARKS, main_not_fullscreen); 1140 IDC_FOCUS_BOOKMARKS, main_not_fullscreen);
1115 1141
1116 // Show various bits of UI 1142 // Show various bits of UI
1117 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui); 1143 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui);
1118 command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui); 1144 command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui);
1145 command_updater_.UpdateCommandEnabled(IDC_SHOW_SYNC_SETUP,
1146 show_main_ui && profile()->GetOriginalProfile()->IsSigninAllowed());
1119 1147
1120 // Settings page/subpages are forced to open in normal mode. We disable these 1148 // Settings page/subpages are forced to open in normal mode. We disable these
1121 // commands when incognito is forced. 1149 // commands when incognito is forced.
1122 const bool options_enabled = show_main_ui && 1150 const bool options_enabled = show_main_ui &&
1123 IncognitoModePrefs::GetAvailability( 1151 IncognitoModePrefs::GetAvailability(
1124 profile()->GetPrefs()) != IncognitoModePrefs::FORCED; 1152 profile()->GetPrefs()) != IncognitoModePrefs::FORCED;
1125 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, options_enabled); 1153 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, options_enabled);
1126 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, options_enabled); 1154 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, options_enabled);
1127 1155
1128 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui); 1156 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1232 1260
1233 BrowserWindow* BrowserCommandController::window() { 1261 BrowserWindow* BrowserCommandController::window() {
1234 return browser_->window(); 1262 return browser_->window();
1235 } 1263 }
1236 1264
1237 Profile* BrowserCommandController::profile() { 1265 Profile* BrowserCommandController::profile() {
1238 return browser_->profile(); 1266 return browser_->profile();
1239 } 1267 }
1240 1268
1241 } // namespace chrome 1269 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698