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

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: Fix indentation issues. 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/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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 header_value, sub_header_value, icon_url_value, is_user_signed_in); 249 header_value, sub_header_value, icon_url_value, is_user_signed_in);
244 } 250 }
245 251
246 // static 252 // static
247 bool NTPLoginHandler::ShouldShow(Profile* profile) { 253 bool NTPLoginHandler::ShouldShow(Profile* profile) {
248 #if defined(OS_CHROMEOS) 254 #if defined(OS_CHROMEOS)
249 // For now we don't care about showing sync status on Chrome OS. The promo 255 // For now we don't care about showing sync status on Chrome OS. The promo
250 // UI and the avatar menu don't exist on that platform. 256 // UI and the avatar menu don't exist on that platform.
251 return false; 257 return false;
252 #else 258 #else
253 return !profile->IsOffTheRecord(); 259 SigninManager* signin = SigninManagerFactory::GetForProfile(profile);
260 return !profile->IsOffTheRecord() && signin && signin->IsSigninAllowed();
254 #endif 261 #endif
255 } 262 }
256 263
257 // static 264 // static
258 void NTPLoginHandler::GetLocalizedValues(Profile* profile, 265 void NTPLoginHandler::GetLocalizedValues(Profile* profile,
259 DictionaryValue* values) { 266 DictionaryValue* values) {
260 PrefService* prefs = profile->GetPrefs(); 267 PrefService* prefs = profile->GetPrefs();
261 std::string error_message = prefs->GetString(prefs::kSyncPromoErrorMessage); 268 std::string error_message = prefs->GetString(prefs::kSyncPromoErrorMessage);
262 bool hide_sync = !prefs->GetBoolean(prefs::kSyncPromoShowNTPBubble); 269 bool hide_sync = !prefs->GetBoolean(prefs::kSyncPromoShowNTPBubble);
263 270
264 string16 message = 271 string16 message =
265 hide_sync ? string16() : 272 hide_sync ? string16() :
266 !error_message.empty() ? UTF8ToUTF16(error_message) : 273 !error_message.empty() ? UTF8ToUTF16(error_message) :
267 l10n_util::GetStringFUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_MESSAGE, 274 l10n_util::GetStringFUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_MESSAGE,
268 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); 275 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME));
269 276
270 values->SetString("login_status_message", message); 277 values->SetString("login_status_message", message);
271 values->SetString("login_status_url", 278 values->SetString("login_status_url",
272 hide_sync ? std::string() : chrome::kSyncLearnMoreURL); 279 hide_sync ? std::string() : chrome::kSyncLearnMoreURL);
273 values->SetString("login_status_advanced", 280 values->SetString("login_status_advanced",
274 hide_sync || !error_message.empty() ? string16() : 281 hide_sync || !error_message.empty() ? string16() :
275 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_ADVANCED)); 282 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_ADVANCED));
276 values->SetString("login_status_dismiss", 283 values->SetString("login_status_dismiss",
277 hide_sync ? string16() : 284 hide_sync ? string16() :
278 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_OK)); 285 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_OK));
279 } 286 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698