| OLD | NEW |
| 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" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 } // namespace | 79 } // namespace |
| 80 | 80 |
| 81 NTPLoginHandler::NTPLoginHandler() { | 81 NTPLoginHandler::NTPLoginHandler() { |
| 82 } | 82 } |
| 83 | 83 |
| 84 NTPLoginHandler::~NTPLoginHandler() { | 84 NTPLoginHandler::~NTPLoginHandler() { |
| 85 } | 85 } |
| 86 | 86 |
| 87 void NTPLoginHandler::RegisterMessages() { | 87 void NTPLoginHandler::RegisterMessages() { |
| 88 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); | 88 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); |
| 89 username_pref_.Init(prefs::kGoogleServicesUsername, | |
| 90 pref_service, | |
| 91 base::Bind(&NTPLoginHandler::UpdateLogin, | |
| 92 base::Unretained(this))); | |
| 93 signin_allowed_pref_.Init(prefs::kSigninAllowed, | 89 signin_allowed_pref_.Init(prefs::kSigninAllowed, |
| 94 pref_service, | 90 pref_service, |
| 95 base::Bind(&NTPLoginHandler::UpdateLogin, | 91 base::Bind(&NTPLoginHandler::UpdateLogin, |
| 96 base::Unretained(this))); | 92 base::Unretained(this))); |
| 97 | 93 |
| 98 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, | 94 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, |
| 99 content::NotificationService::AllSources()); | 95 content::NotificationService::AllSources()); |
| 100 | 96 |
| 101 web_ui()->RegisterMessageCallback("initializeSyncLogin", | 97 web_ui()->RegisterMessageCallback("initializeSyncLogin", |
| 102 base::Bind(&NTPLoginHandler::HandleInitializeSyncLogin, | 98 base::Bind(&NTPLoginHandler::HandleInitializeSyncLogin, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 118 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, type); | 114 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, type); |
| 119 UpdateLogin(); | 115 UpdateLogin(); |
| 120 } | 116 } |
| 121 | 117 |
| 122 void NTPLoginHandler::HandleInitializeSyncLogin(const base::ListValue* args) { | 118 void NTPLoginHandler::HandleInitializeSyncLogin(const base::ListValue* args) { |
| 123 UpdateLogin(); | 119 UpdateLogin(); |
| 124 } | 120 } |
| 125 | 121 |
| 126 void NTPLoginHandler::HandleShowSyncLoginUI(const base::ListValue* args) { | 122 void NTPLoginHandler::HandleShowSyncLoginUI(const base::ListValue* args) { |
| 127 Profile* profile = Profile::FromWebUI(web_ui()); | 123 Profile* profile = Profile::FromWebUI(web_ui()); |
| 128 std::string username = profile->GetPrefs()->GetString( | 124 std::string username = |
| 129 prefs::kGoogleServicesUsername); | 125 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedUsername(); |
| 130 content::WebContents* web_contents = web_ui()->GetWebContents(); | 126 content::WebContents* web_contents = web_ui()->GetWebContents(); |
| 131 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | 127 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
| 132 if (!browser) | 128 if (!browser) |
| 133 return; | 129 return; |
| 134 | 130 |
| 135 if (username.empty()) { | 131 if (username.empty()) { |
| 136 // The user isn't signed in, show the sign in promo. | 132 // The user isn't signed in, show the sign in promo. |
| 137 if (signin::ShouldShowPromo(profile)) { | 133 if (signin::ShouldShowPromo(profile)) { |
| 138 signin::Source source = | 134 signin::Source source = |
| 139 (web_contents->GetURL().spec() == chrome::kChromeUIAppsURL) ? | 135 (web_contents->GetURL().spec() == chrome::kChromeUIAppsURL) ? |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 | 184 |
| 189 void NTPLoginHandler::HandleShowAdvancedLoginUI(const base::ListValue* args) { | 185 void NTPLoginHandler::HandleShowAdvancedLoginUI(const base::ListValue* args) { |
| 190 Browser* browser = | 186 Browser* browser = |
| 191 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents()); | 187 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents()); |
| 192 if (browser) | 188 if (browser) |
| 193 chrome::ShowBrowserSignin(browser, signin::SOURCE_NTP_LINK); | 189 chrome::ShowBrowserSignin(browser, signin::SOURCE_NTP_LINK); |
| 194 } | 190 } |
| 195 | 191 |
| 196 void NTPLoginHandler::UpdateLogin() { | 192 void NTPLoginHandler::UpdateLogin() { |
| 197 Profile* profile = Profile::FromWebUI(web_ui()); | 193 Profile* profile = Profile::FromWebUI(web_ui()); |
| 198 std::string username = profile->GetPrefs()->GetString( | 194 std::string username = |
| 199 prefs::kGoogleServicesUsername); | 195 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedUsername(); |
| 200 | 196 |
| 201 base::string16 header, sub_header; | 197 base::string16 header, sub_header; |
| 202 std::string icon_url; | 198 std::string icon_url; |
| 203 if (!username.empty()) { | 199 if (!username.empty()) { |
| 204 ProfileInfoCache& cache = | 200 ProfileInfoCache& cache = |
| 205 g_browser_process->profile_manager()->GetProfileInfoCache(); | 201 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 206 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | 202 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); |
| 207 if (profile_index != std::string::npos) { | 203 if (profile_index != std::string::npos) { |
| 208 // Only show the profile picture and full name for the single profile | 204 // Only show the profile picture and full name for the single profile |
| 209 // case. In the multi-profile case the profile picture is visible in the | 205 // case. In the multi-profile case the profile picture is visible in the |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 values->SetString("login_status_message", message); | 271 values->SetString("login_status_message", message); |
| 276 values->SetString("login_status_url", | 272 values->SetString("login_status_url", |
| 277 hide_sync ? std::string() : chrome::kSyncLearnMoreURL); | 273 hide_sync ? std::string() : chrome::kSyncLearnMoreURL); |
| 278 values->SetString("login_status_advanced", | 274 values->SetString("login_status_advanced", |
| 279 hide_sync ? base::string16() : | 275 hide_sync ? base::string16() : |
| 280 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_ADVANCED)); | 276 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_ADVANCED)); |
| 281 values->SetString("login_status_dismiss", | 277 values->SetString("login_status_dismiss", |
| 282 hide_sync ? base::string16() : | 278 hide_sync ? base::string16() : |
| 283 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_OK)); | 279 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_OK)); |
| 284 } | 280 } |
| OLD | NEW |