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" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/app/chrome_command_ids.h" | 14 #include "chrome/app/chrome_command_ids.h" |
15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/managed_mode.h" | 16 #include "chrome/browser/managed_mode.h" |
17 #include "chrome/browser/prefs/pref_notifier.h" | 17 #include "chrome/browser/prefs/pref_notifier.h" |
18 #include "chrome/browser/prefs/pref_service.h" | 18 #include "chrome/browser/prefs/pref_service.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/sync/profile_sync_service.h" | 23 #include "chrome/browser/sync/profile_sync_service.h" |
24 #include "chrome/browser/sync/profile_sync_service_factory.h" | 24 #include "chrome/browser/sync/profile_sync_service_factory.h" |
25 #include "chrome/browser/ui/browser.h" | 25 #include "chrome/browser/ui/browser.h" |
26 #include "chrome/browser/ui/browser_list.h" | 26 #include "chrome/browser/ui/browser_finder.h" |
27 #include "chrome/browser/ui/browser_window.h" | 27 #include "chrome/browser/ui/browser_window.h" |
28 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 28 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
29 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" | 29 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
30 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" | 30 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" |
31 #include "chrome/browser/ui/webui/web_ui_util.h" | 31 #include "chrome/browser/ui/webui/web_ui_util.h" |
32 #include "chrome/browser/web_resource/promo_resource_service.h" | 32 #include "chrome/browser/web_resource/promo_resource_service.h" |
33 #include "chrome/common/chrome_notification_types.h" | 33 #include "chrome/common/chrome_notification_types.h" |
34 #include "chrome/common/pref_names.h" | 34 #include "chrome/common/pref_names.h" |
35 #include "chrome/common/url_constants.h" | 35 #include "chrome/common/url_constants.h" |
36 #include "content/public/browser/notification_details.h" | 36 #include "content/public/browser/notification_details.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 | 120 |
121 void NTPLoginHandler::HandleInitializeSyncLogin(const ListValue* args) { | 121 void NTPLoginHandler::HandleInitializeSyncLogin(const ListValue* args) { |
122 UpdateLogin(); | 122 UpdateLogin(); |
123 } | 123 } |
124 | 124 |
125 void NTPLoginHandler::HandleShowSyncLoginUI(const ListValue* args) { | 125 void NTPLoginHandler::HandleShowSyncLoginUI(const ListValue* args) { |
126 Profile* profile = Profile::FromWebUI(web_ui()); | 126 Profile* profile = Profile::FromWebUI(web_ui()); |
127 std::string username = profile->GetPrefs()->GetString( | 127 std::string username = profile->GetPrefs()->GetString( |
128 prefs::kGoogleServicesUsername); | 128 prefs::kGoogleServicesUsername); |
129 content::WebContents* web_contents = web_ui()->GetWebContents(); | 129 content::WebContents* web_contents = web_ui()->GetWebContents(); |
130 Browser* browser = BrowserList::FindBrowserWithWebContents(web_contents); | 130 Browser* browser = browser::FindBrowserWithWebContents(web_contents); |
131 if (!browser) | 131 if (!browser) |
132 return; | 132 return; |
133 | 133 |
134 if (username.empty()) { | 134 if (username.empty()) { |
135 #if !defined(OS_ANDROID) | 135 #if !defined(OS_ANDROID) |
136 // The user isn't signed in, show the sync promo. | 136 // The user isn't signed in, show the sync promo. |
137 if (SyncPromoUI::ShouldShowSyncPromo(profile)) { | 137 if (SyncPromoUI::ShouldShowSyncPromo(profile)) { |
138 browser->ShowSyncSetup(SyncPromoUI::SOURCE_NTP_LINK); | 138 browser->ShowSyncSetup(SyncPromoUI::SOURCE_NTP_LINK); |
139 RecordInHistogram(NTP_SIGN_IN_PROMO_CLICKED); | 139 RecordInHistogram(NTP_SIGN_IN_PROMO_CLICKED); |
140 } | 140 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 | 178 |
179 void NTPLoginHandler::HandleLoginMessageSeen(const ListValue* args) { | 179 void NTPLoginHandler::HandleLoginMessageSeen(const ListValue* args) { |
180 Profile::FromWebUI(web_ui())->GetPrefs()->SetBoolean( | 180 Profile::FromWebUI(web_ui())->GetPrefs()->SetBoolean( |
181 prefs::kSyncPromoShowNTPBubble, false); | 181 prefs::kSyncPromoShowNTPBubble, false); |
182 NewTabUI* ntp_ui = NewTabUI::FromWebUIController(web_ui()->GetController()); | 182 NewTabUI* ntp_ui = NewTabUI::FromWebUIController(web_ui()->GetController()); |
183 ntp_ui->set_showing_sync_bubble(true); | 183 ntp_ui->set_showing_sync_bubble(true); |
184 } | 184 } |
185 | 185 |
186 void NTPLoginHandler::HandleShowAdvancedLoginUI(const ListValue* args) { | 186 void NTPLoginHandler::HandleShowAdvancedLoginUI(const ListValue* args) { |
187 Browser* browser = | 187 Browser* browser = |
188 BrowserList::FindBrowserWithWebContents(web_ui()->GetWebContents()); | 188 browser::FindBrowserWithWebContents(web_ui()->GetWebContents()); |
189 if (browser) | 189 if (browser) |
190 browser->ShowSyncSetup(SyncPromoUI::SOURCE_NTP_LINK); | 190 browser->ShowSyncSetup(SyncPromoUI::SOURCE_NTP_LINK); |
191 } | 191 } |
192 | 192 |
193 void NTPLoginHandler::UpdateLogin() { | 193 void NTPLoginHandler::UpdateLogin() { |
194 Profile* profile = Profile::FromWebUI(web_ui()); | 194 Profile* profile = Profile::FromWebUI(web_ui()); |
195 std::string username = profile->GetPrefs()->GetString( | 195 std::string username = profile->GetPrefs()->GetString( |
196 prefs::kGoogleServicesUsername); | 196 prefs::kGoogleServicesUsername); |
197 | 197 |
198 string16 header, sub_header; | 198 string16 header, sub_header; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME))); | 270 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME))); |
271 values->SetString("login_status_url", | 271 values->SetString("login_status_url", |
272 hide_sync ? std::string() : chrome::kSyncLearnMoreURL); | 272 hide_sync ? std::string() : chrome::kSyncLearnMoreURL); |
273 values->SetString("login_status_advanced", | 273 values->SetString("login_status_advanced", |
274 hide_sync ? string16() : | 274 hide_sync ? string16() : |
275 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_ADVANCED)); | 275 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_ADVANCED)); |
276 values->SetString("login_status_dismiss", | 276 values->SetString("login_status_dismiss", |
277 hide_sync ? string16() : | 277 hide_sync ? string16() : |
278 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_OK)); | 278 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_OK)); |
279 } | 279 } |
OLD | NEW |