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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, type); | 114 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, type); |
115 UpdateLogin(); | 115 UpdateLogin(); |
116 } | 116 } |
117 | 117 |
118 void NTPLoginHandler::HandleInitializeSyncLogin(const base::ListValue* args) { | 118 void NTPLoginHandler::HandleInitializeSyncLogin(const base::ListValue* args) { |
119 UpdateLogin(); | 119 UpdateLogin(); |
120 } | 120 } |
121 | 121 |
122 void NTPLoginHandler::HandleShowSyncLoginUI(const base::ListValue* args) { | 122 void NTPLoginHandler::HandleShowSyncLoginUI(const base::ListValue* args) { |
123 Profile* profile = Profile::FromWebUI(web_ui()); | 123 Profile* profile = Profile::FromWebUI(web_ui()); |
| 124 if (!signin::ShouldShowPromo(profile)) |
| 125 return; |
| 126 |
124 std::string username = | 127 std::string username = |
125 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedUsername(); | 128 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedUsername(); |
| 129 if (!username.empty()) |
| 130 return; |
| 131 |
126 content::WebContents* web_contents = web_ui()->GetWebContents(); | 132 content::WebContents* web_contents = web_ui()->GetWebContents(); |
127 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | 133 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
128 if (!browser) | 134 if (!browser) |
129 return; | 135 return; |
130 | 136 |
131 if (username.empty()) { | 137 // The user isn't signed in, show the sign in promo. |
132 // The user isn't signed in, show the sign in promo. | 138 signin::Source source = |
133 if (signin::ShouldShowPromo(profile)) { | 139 web_contents->GetURL().spec() == chrome::kChromeUIAppsURL ? |
134 signin::Source source = | 140 signin::SOURCE_APPS_PAGE_LINK : |
135 (web_contents->GetURL().spec() == chrome::kChromeUIAppsURL) ? | 141 signin::SOURCE_NTP_LINK; |
136 signin::SOURCE_APPS_PAGE_LINK : | 142 chrome::ShowBrowserSignin(browser, source); |
137 signin::SOURCE_NTP_LINK; | 143 RecordInHistogram(NTP_SIGN_IN_PROMO_CLICKED); |
138 chrome::ShowBrowserSignin(browser, source); | |
139 RecordInHistogram(NTP_SIGN_IN_PROMO_CLICKED); | |
140 } | |
141 } else if (args->GetSize() == 4) { | |
142 // The user is signed in, show the profiles menu. | |
143 double x = 0; | |
144 double y = 0; | |
145 double width = 0; | |
146 double height = 0; | |
147 bool success = args->GetDouble(0, &x); | |
148 DCHECK(success); | |
149 success = args->GetDouble(1, &y); | |
150 DCHECK(success); | |
151 success = args->GetDouble(2, &width); | |
152 DCHECK(success); | |
153 success = args->GetDouble(3, &height); | |
154 DCHECK(success); | |
155 | |
156 double zoom = content::ZoomLevelToZoomFactor( | |
157 ui_zoom::ZoomController::FromWebContents(web_contents)->GetZoomLevel()); | |
158 gfx::Rect rect(x * zoom, y * zoom, width * zoom, height * zoom); | |
159 | |
160 browser->window()->ShowAvatarBubble(web_ui()->GetWebContents(), rect); | |
161 ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::NTP_AVATAR_BUBBLE); | |
162 } | |
163 } | 144 } |
164 | 145 |
165 void NTPLoginHandler::RecordInHistogram(int type) { | 146 void NTPLoginHandler::RecordInHistogram(int type) { |
166 // Invalid type to record. | 147 // Invalid type to record. |
167 if (type < NTP_SIGN_IN_PROMO_VIEWED || | 148 if (type < NTP_SIGN_IN_PROMO_VIEWED || |
168 type > NTP_SIGN_IN_PROMO_CLICKED) { | 149 type > NTP_SIGN_IN_PROMO_CLICKED) { |
169 NOTREACHED(); | 150 NOTREACHED(); |
170 } else { | 151 } else { |
171 UMA_HISTOGRAM_ENUMERATION("SyncPromo.NTPPromo", type, | 152 UMA_HISTOGRAM_ENUMERATION("SyncPromo.NTPPromo", type, |
172 NTP_SIGN_IN_PROMO_BUCKET_BOUNDARY); | 153 NTP_SIGN_IN_PROMO_BUCKET_BOUNDARY); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 values->SetString("login_status_message", message); | 252 values->SetString("login_status_message", message); |
272 values->SetString("login_status_url", | 253 values->SetString("login_status_url", |
273 hide_sync ? std::string() : chrome::kSyncLearnMoreURL); | 254 hide_sync ? std::string() : chrome::kSyncLearnMoreURL); |
274 values->SetString("login_status_advanced", | 255 values->SetString("login_status_advanced", |
275 hide_sync ? base::string16() : | 256 hide_sync ? base::string16() : |
276 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_ADVANCED)); | 257 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_ADVANCED)); |
277 values->SetString("login_status_dismiss", | 258 values->SetString("login_status_dismiss", |
278 hide_sync ? base::string16() : | 259 hide_sync ? base::string16() : |
279 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_OK)); | 260 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_OK)); |
280 } | 261 } |
OLD | NEW |