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

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: Extract managed user specific stuff into another changelist. 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 base::Unretained(this))); 197 base::Unretained(this)));
196 profile_pref_registrar_.Add( 198 profile_pref_registrar_.Add(
197 prefs::kIncognitoModeAvailability, 199 prefs::kIncognitoModeAvailability,
198 base::Bind( 200 base::Bind(
199 &BrowserCommandController::UpdateCommandsForIncognitoAvailability, 201 &BrowserCommandController::UpdateCommandsForIncognitoAvailability,
200 base::Unretained(this))); 202 base::Unretained(this)));
201 profile_pref_registrar_.Add( 203 profile_pref_registrar_.Add(
202 prefs::kPrintingEnabled, 204 prefs::kPrintingEnabled,
203 base::Bind(&BrowserCommandController::UpdatePrintingState, 205 base::Bind(&BrowserCommandController::UpdatePrintingState,
204 base::Unretained(this))); 206 base::Unretained(this)));
207 pref_signin_allowed_.Init(prefs::kSigninAllowed,
208 profile()->GetOriginalProfile()->GetPrefs(),
209 base::Bind(&BrowserCommandController::OnSigninAllowedPrefChange,
210 base::Unretained(this)));
205 211
206 InitCommandState(); 212 InitCommandState();
207 213
208 TabRestoreService* tab_restore_service = 214 TabRestoreService* tab_restore_service =
209 TabRestoreServiceFactory::GetForProfile(profile()); 215 TabRestoreServiceFactory::GetForProfile(profile());
210 if (tab_restore_service) { 216 if (tab_restore_service) {
211 tab_restore_service->AddObserver(this); 217 tab_restore_service->AddObserver(this);
212 TabRestoreServiceChanged(tab_restore_service); 218 TabRestoreServiceChanged(tab_restore_service);
213 } 219 }
214 } 220 }
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 void BrowserCommandController::OnProfileNameChanged( 742 void BrowserCommandController::OnProfileNameChanged(
737 const FilePath& profile_path, 743 const FilePath& profile_path,
738 const string16& old_profile_name) { 744 const string16& old_profile_name) {
739 } 745 }
740 746
741 void BrowserCommandController::OnProfileAvatarChanged( 747 void BrowserCommandController::OnProfileAvatarChanged(
742 const FilePath& profile_path) { 748 const FilePath& profile_path) {
743 } 749 }
744 750
745 //////////////////////////////////////////////////////////////////////////////// 751 ////////////////////////////////////////////////////////////////////////////////
752 // BrowserCommandController, SigninPrefObserver implementation:
753
754 void BrowserCommandController::OnSigninAllowedPrefChange() {
755 // For unit tests, we don't have a window.
756 if (!window())
757 return;
758 const bool show_main_ui = IsShowingMainUI(window()->IsFullscreen());
759 command_updater_.UpdateCommandEnabled(IDC_SHOW_SYNC_SETUP,
sail 2013/02/08 20:18:57 Move the code to update this state into a single f
Adrian Kuegel 2013/02/11 16:47:30 Done. Note that I had to pass show_main_ui as a pa
760 show_main_ui && pref_signin_allowed_.GetValue());
761 }
762
746 // BrowserCommandController, TabStripModelObserver implementation: 763 // BrowserCommandController, TabStripModelObserver implementation:
747 764
748 void BrowserCommandController::TabInsertedAt(WebContents* contents, 765 void BrowserCommandController::TabInsertedAt(WebContents* contents,
749 int index, 766 int index,
750 bool foreground) { 767 bool foreground) {
751 AddInterstitialObservers(contents); 768 AddInterstitialObservers(contents);
752 } 769 }
753 770
754 void BrowserCommandController::TabDetachedAt(WebContents* contents, int index) { 771 void BrowserCommandController::TabDetachedAt(WebContents* contents, int index) {
755 RemoveInterstitialObservers(contents); 772 RemoveInterstitialObservers(contents);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 !profile()->IsGuestSession()); 893 !profile()->IsGuestSession());
877 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true); 894 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true);
878 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true); 895 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true);
879 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true); 896 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true);
880 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, 897 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU,
881 !profile()->IsGuestSession()); 898 !profile()->IsGuestSession());
882 command_updater_.UpdateCommandEnabled(IDC_RECENT_TABS_MENU, 899 command_updater_.UpdateCommandEnabled(IDC_RECENT_TABS_MENU,
883 !profile()->IsGuestSession() && 900 !profile()->IsGuestSession() &&
884 !profile()->IsOffTheRecord()); 901 !profile()->IsOffTheRecord());
885 902
886 command_updater_.UpdateCommandEnabled(IDC_SHOW_SIGNIN, true); 903 command_updater_.UpdateCommandEnabled(
904 IDC_SHOW_SYNC_SETUP,
905 profile()->GetOriginalProfile()->IsSigninAllowed());
887 906
888 // Initialize other commands based on the window type. 907 // Initialize other commands based on the window type.
889 bool normal_window = browser_->is_type_tabbed(); 908 bool normal_window = browser_->is_type_tabbed();
890 909
891 // Navigation commands 910 // Navigation commands
892 command_updater_.UpdateCommandEnabled(IDC_HOME, normal_window); 911 command_updater_.UpdateCommandEnabled(IDC_HOME, normal_window);
893 912
894 // Window management commands 913 // Window management commands
895 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window); 914 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window);
896 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, 915 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB,
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 command_updater_.UpdateCommandEnabled( 1130 command_updater_.UpdateCommandEnabled(
1112 IDC_FOCUS_NEXT_PANE, main_not_fullscreen); 1131 IDC_FOCUS_NEXT_PANE, main_not_fullscreen);
1113 command_updater_.UpdateCommandEnabled( 1132 command_updater_.UpdateCommandEnabled(
1114 IDC_FOCUS_PREVIOUS_PANE, main_not_fullscreen); 1133 IDC_FOCUS_PREVIOUS_PANE, main_not_fullscreen);
1115 command_updater_.UpdateCommandEnabled( 1134 command_updater_.UpdateCommandEnabled(
1116 IDC_FOCUS_BOOKMARKS, main_not_fullscreen); 1135 IDC_FOCUS_BOOKMARKS, main_not_fullscreen);
1117 1136
1118 // Show various bits of UI 1137 // Show various bits of UI
1119 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui); 1138 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui);
1120 command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui); 1139 command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui);
1140 command_updater_.UpdateCommandEnabled(IDC_SHOW_SYNC_SETUP,
1141 show_main_ui && profile()->GetOriginalProfile()->IsSigninAllowed());
1121 1142
1122 // Settings page/subpages are forced to open in normal mode. We disable these 1143 // Settings page/subpages are forced to open in normal mode. We disable these
1123 // commands when incognito is forced. 1144 // commands when incognito is forced.
1124 const bool options_enabled = show_main_ui && 1145 const bool options_enabled = show_main_ui &&
1125 IncognitoModePrefs::GetAvailability( 1146 IncognitoModePrefs::GetAvailability(
1126 profile()->GetPrefs()) != IncognitoModePrefs::FORCED; 1147 profile()->GetPrefs()) != IncognitoModePrefs::FORCED;
1127 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, options_enabled); 1148 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, options_enabled);
1128 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, options_enabled); 1149 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, options_enabled);
1129 1150
1130 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui); 1151 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1234 1255
1235 BrowserWindow* BrowserCommandController::window() { 1256 BrowserWindow* BrowserCommandController::window() {
1236 return browser_->window(); 1257 return browser_->window();
1237 } 1258 }
1238 1259
1239 Profile* BrowserCommandController::profile() { 1260 Profile* BrowserCommandController::profile() {
1240 return browser_->profile(); 1261 return browser_->profile();
1241 } 1262 }
1242 1263
1243 } // namespace chrome 1264 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698