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

Side by Side Diff: chrome/browser/ui/webui/ntp/ntp_login_handler.cc

Issue 12088040: Add a SigninAllowed policy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address nits and rebase to ToT. Created 7 years, 9 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/webui/ntp/ntp_login_handler.h" 5 #include "chrome/browser/ui/webui/ntp/ntp_login_handler.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/prefs/pref_notifier.h" 12 #include "base/prefs/pref_notifier.h"
13 #include "base/prefs/pref_service.h" 13 #include "base/prefs/pref_service.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "chrome/app/chrome_command_ids.h" 16 #include "chrome/app/chrome_command_ids.h"
17 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/managed_mode/managed_mode.h" 18 #include "chrome/browser/managed_mode/managed_mode.h"
19 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/profiles/profile_info_cache.h" 20 #include "chrome/browser/profiles/profile_info_cache.h"
21 #include "chrome/browser/profiles/profile_manager.h" 21 #include "chrome/browser/profiles/profile_manager.h"
22 #include "chrome/browser/profiles/profile_metrics.h" 22 #include "chrome/browser/profiles/profile_metrics.h"
23 #include "chrome/browser/signin/signin_manager.h"
24 #include "chrome/browser/signin/signin_manager_factory.h"
23 #include "chrome/browser/sync/profile_sync_service.h" 25 #include "chrome/browser/sync/profile_sync_service.h"
24 #include "chrome/browser/sync/profile_sync_service_factory.h" 26 #include "chrome/browser/sync/profile_sync_service_factory.h"
25 #include "chrome/browser/ui/browser.h" 27 #include "chrome/browser/ui/browser.h"
26 #include "chrome/browser/ui/browser_commands.h" 28 #include "chrome/browser/ui/browser_commands.h"
27 #include "chrome/browser/ui/browser_finder.h" 29 #include "chrome/browser/ui/browser_finder.h"
28 #include "chrome/browser/ui/browser_window.h" 30 #include "chrome/browser/ui/browser_window.h"
29 #include "chrome/browser/ui/chrome_pages.h" 31 #include "chrome/browser/ui/chrome_pages.h"
30 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" 32 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
31 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" 33 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h"
32 #include "chrome/browser/web_resource/promo_resource_service.h" 34 #include "chrome/browser/web_resource/promo_resource_service.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 86
85 NTPLoginHandler::~NTPLoginHandler() { 87 NTPLoginHandler::~NTPLoginHandler() {
86 } 88 }
87 89
88 void NTPLoginHandler::RegisterMessages() { 90 void NTPLoginHandler::RegisterMessages() {
89 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); 91 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
90 username_pref_.Init(prefs::kGoogleServicesUsername, 92 username_pref_.Init(prefs::kGoogleServicesUsername,
91 pref_service, 93 pref_service,
92 base::Bind(&NTPLoginHandler::UpdateLogin, 94 base::Bind(&NTPLoginHandler::UpdateLogin,
93 base::Unretained(this))); 95 base::Unretained(this)));
96 signin_allowed_pref_.Init(prefs::kSigninAllowed,
97 pref_service,
98 base::Bind(&NTPLoginHandler::UpdateLogin,
99 base::Unretained(this)));
94 100
95 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, 101 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
96 content::NotificationService::AllSources()); 102 content::NotificationService::AllSources());
97 103
98 web_ui()->RegisterMessageCallback("initializeSyncLogin", 104 web_ui()->RegisterMessageCallback("initializeSyncLogin",
99 base::Bind(&NTPLoginHandler::HandleInitializeSyncLogin, 105 base::Bind(&NTPLoginHandler::HandleInitializeSyncLogin,
100 base::Unretained(this))); 106 base::Unretained(this)));
101 web_ui()->RegisterMessageCallback("showSyncLoginUI", 107 web_ui()->RegisterMessageCallback("showSyncLoginUI",
102 base::Bind(&NTPLoginHandler::HandleShowSyncLoginUI, 108 base::Bind(&NTPLoginHandler::HandleShowSyncLoginUI,
103 base::Unretained(this))); 109 base::Unretained(this)));
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 header_value, sub_header_value, icon_url_value, is_user_signed_in); 251 header_value, sub_header_value, icon_url_value, is_user_signed_in);
246 } 252 }
247 253
248 // static 254 // static
249 bool NTPLoginHandler::ShouldShow(Profile* profile) { 255 bool NTPLoginHandler::ShouldShow(Profile* profile) {
250 #if defined(OS_CHROMEOS) 256 #if defined(OS_CHROMEOS)
251 // For now we don't care about showing sync status on Chrome OS. The promo 257 // For now we don't care about showing sync status on Chrome OS. The promo
252 // UI and the avatar menu don't exist on that platform. 258 // UI and the avatar menu don't exist on that platform.
253 return false; 259 return false;
254 #else 260 #else
255 return !profile->IsOffTheRecord(); 261 SigninManager* signin = SigninManagerFactory::GetForProfile(profile);
262 return !profile->IsOffTheRecord() && signin && signin->IsSigninAllowed();
256 #endif 263 #endif
257 } 264 }
258 265
259 // static 266 // static
260 void NTPLoginHandler::GetLocalizedValues(Profile* profile, 267 void NTPLoginHandler::GetLocalizedValues(Profile* profile,
261 DictionaryValue* values) { 268 DictionaryValue* values) {
262 PrefService* prefs = profile->GetPrefs(); 269 PrefService* prefs = profile->GetPrefs();
263 std::string error_message = prefs->GetString(prefs::kSyncPromoErrorMessage); 270 std::string error_message = prefs->GetString(prefs::kSyncPromoErrorMessage);
264 bool hide_sync = !prefs->GetBoolean(prefs::kSyncPromoShowNTPBubble); 271 bool hide_sync = !prefs->GetBoolean(prefs::kSyncPromoShowNTPBubble);
265 272
266 string16 message = 273 string16 message =
267 hide_sync ? string16() : 274 hide_sync ? string16() :
268 !error_message.empty() ? UTF8ToUTF16(error_message) : 275 !error_message.empty() ? UTF8ToUTF16(error_message) :
269 l10n_util::GetStringFUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_MESSAGE, 276 l10n_util::GetStringFUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_MESSAGE,
270 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); 277 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME));
271 278
272 values->SetString("login_status_message", message); 279 values->SetString("login_status_message", message);
273 values->SetString("login_status_url", 280 values->SetString("login_status_url",
274 hide_sync ? std::string() : chrome::kSyncLearnMoreURL); 281 hide_sync ? std::string() : chrome::kSyncLearnMoreURL);
275 values->SetString("login_status_advanced", 282 values->SetString("login_status_advanced",
276 hide_sync || !error_message.empty() ? string16() : 283 hide_sync || !error_message.empty() ? string16() :
277 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_ADVANCED)); 284 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_ADVANCED));
278 values->SetString("login_status_dismiss", 285 values->SetString("login_status_dismiss",
279 hide_sync ? string16() : 286 hide_sync ? string16() :
280 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_OK)); 287 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_OK));
281 } 288 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/ntp/ntp_login_handler.h ('k') | chrome/browser/ui/webui/options/browser_options_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698