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

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

Issue 8363035: NTP4/Sync Promo: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged, fixed, unit tests and quick smoke test passing Created 9 years, 1 month 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 const content::NotificationSource& source, 57 const content::NotificationSource& source,
58 const content::NotificationDetails& details) { 58 const content::NotificationDetails& details) {
59 DCHECK(type == chrome::NOTIFICATION_PREF_CHANGED); 59 DCHECK(type == chrome::NOTIFICATION_PREF_CHANGED);
60 std::string* name = content::Details<std::string>(details).ptr(); 60 std::string* name = content::Details<std::string>(details).ptr();
61 if (prefs::kGoogleServicesUsername == *name) 61 if (prefs::kGoogleServicesUsername == *name)
62 UpdateLogin(); 62 UpdateLogin();
63 } 63 }
64 64
65 void NTPLoginHandler::HandleInitializeSyncLogin(const ListValue* args) { 65 void NTPLoginHandler::HandleInitializeSyncLogin(const ListValue* args) {
66 UpdateLogin(); 66 UpdateLogin();
67 UMA_HISTOGRAM_ENUMERATION("SyncPromo.NTPPromo",
68 SYNC_PROMO_NTP_PROMO_VIEWED,
69 SYNC_PROMO_NTP_PROMO_BUCKET_BOUNDARY);
70 } 67 }
71 68
72 void NTPLoginHandler::HandleShowSyncLoginUI(const ListValue* args) { 69 void NTPLoginHandler::HandleShowSyncLoginUI(const ListValue* args) {
73 Profile* profile = Profile::FromWebUI(web_ui_); 70 Profile* profile = Profile::FromWebUI(web_ui_);
74 std::string username = profile->GetPrefs()->GetString( 71 std::string username = profile->GetPrefs()->GetString(
75 prefs::kGoogleServicesUsername); 72 prefs::kGoogleServicesUsername);
76 73
77 if (username.empty()) { 74 if (username.empty()) {
78 // The user isn't signed in, show the sync promo. 75 // The user isn't signed in, show the sync promo.
79 if (SyncPromoUI::ShouldShowSyncPromo(profile)) { 76 if (SyncPromoUI::ShouldShowSyncPromo(profile)) {
80 UMA_HISTOGRAM_ENUMERATION("SyncPromo.NTPPromo",
81 SYNC_PROMO_NTP_PROMO_CLICKED,
82 SYNC_PROMO_NTP_PROMO_BUCKET_BOUNDARY);
83 web_ui_->tab_contents()->OpenURL(GURL(chrome::kChromeUISyncPromoURL), 77 web_ui_->tab_contents()->OpenURL(GURL(chrome::kChromeUISyncPromoURL),
84 GURL(), CURRENT_TAB, 78 GURL(), CURRENT_TAB,
85 content::PAGE_TRANSITION_LINK); 79 content::PAGE_TRANSITION_LINK);
80 RecordInHistogram(NTP_SIGN_IN_PROMO_CLICKED);
86 } 81 }
87 } else if (args->GetSize() == 4) { 82 } else if (args->GetSize() == 4) {
88 // The user is signed in, show the profiles menu. 83 // The user is signed in, show the profiles menu.
89 Browser* browser = 84 Browser* browser =
90 BrowserList::FindBrowserWithTabContents(web_ui_->tab_contents()); 85 BrowserList::FindBrowserWithTabContents(web_ui_->tab_contents());
91 if (!browser) 86 if (!browser)
92 return; 87 return;
93 double x = 0; 88 double x = 0;
94 double y = 0; 89 double y = 0;
95 double width = 0; 90 double width = 0;
96 double height = 0; 91 double height = 0;
97 bool success = args->GetDouble(0, &x); 92 bool success = args->GetDouble(0, &x);
98 DCHECK(success); 93 DCHECK(success);
99 success = args->GetDouble(1, &y); 94 success = args->GetDouble(1, &y);
100 DCHECK(success); 95 DCHECK(success);
101 success = args->GetDouble(2, &width); 96 success = args->GetDouble(2, &width);
102 DCHECK(success); 97 DCHECK(success);
103 success = args->GetDouble(3, &height); 98 success = args->GetDouble(3, &height);
104 DCHECK(success); 99 DCHECK(success);
105 gfx::Rect rect(x, y, width, height); 100 gfx::Rect rect(x, y, width, height);
106 browser->window()->ShowAvatarBubble(web_ui_->tab_contents(), rect); 101 browser->window()->ShowAvatarBubble(web_ui_->tab_contents(), rect);
107 } 102 }
108 } 103 }
109 104
105 void NTPLoginHandler::RecordInHistogram(int type) {
106 // Invalid type to record.
107 if (type < NTP_SIGN_IN_PROMO_VIEWED ||
108 type > NTP_SIGN_IN_PROMO_CLICKED) {
109 NOTREACHED();
110 } else {
111 UMA_HISTOGRAM_ENUMERATION("SyncPromo.NTPPromo", type,
112 NTP_SIGN_IN_PROMO_BUCKET_BOUNDARY);
113 }
114 }
115
110 void NTPLoginHandler::UpdateLogin() { 116 void NTPLoginHandler::UpdateLogin() {
111 Profile* profile = Profile::FromWebUI(web_ui_); 117 Profile* profile = Profile::FromWebUI(web_ui_);
112 std::string username = profile->GetPrefs()->GetString( 118 std::string username = profile->GetPrefs()->GetString(
113 prefs::kGoogleServicesUsername); 119 prefs::kGoogleServicesUsername);
114 string16 header, sub_header; 120 string16 header, sub_header;
115 if (!username.empty()) { 121 if (!username.empty()) {
116 header = UTF8ToUTF16(username); 122 header = UTF8ToUTF16(username);
117 } else if (SyncPromoUI::ShouldShowSyncPromo(profile) && 123 } else if (SyncPromoUI::ShouldShowSyncPromo(profile) &&
118 (SyncPromoUI::UserHasSeenSyncPromoAtStartup(profile) || 124 (SyncPromoUI::UserHasSeenSyncPromoAtStartup(profile) ||
119 PromoResourceService::CanShowSyncPromo(profile))) { 125 PromoResourceService::CanShowNTPSignInPromo(profile))) {
120 string16 signed_in_link = l10n_util::GetStringUTF16( 126 string16 signed_in_link = l10n_util::GetStringUTF16(
121 IDS_SYNC_PROMO_NOT_SIGNED_IN_STATUS_LINK); 127 IDS_SYNC_PROMO_NOT_SIGNED_IN_STATUS_LINK);
122 signed_in_link = ASCIIToUTF16("<span class='link-span'>") + signed_in_link + 128 signed_in_link = ASCIIToUTF16("<span class='link-span'>") + signed_in_link +
123 ASCIIToUTF16("</span>"); 129 ASCIIToUTF16("</span>");
124 header = l10n_util::GetStringFUTF16( 130 header = l10n_util::GetStringFUTF16(
125 IDS_SYNC_PROMO_NOT_SIGNED_IN_STATUS_HEADER, 131 IDS_SYNC_PROMO_NOT_SIGNED_IN_STATUS_HEADER,
126 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); 132 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME));
127 sub_header = l10n_util::GetStringFUTF16( 133 sub_header = l10n_util::GetStringFUTF16(
128 IDS_SYNC_PROMO_NOT_SIGNED_IN_STATUS_SUB_HEADER, signed_in_link); 134 IDS_SYNC_PROMO_NOT_SIGNED_IN_STATUS_SUB_HEADER, signed_in_link);
135 // Record that the user was shown the promo.
136 RecordInHistogram(NTP_SIGN_IN_PROMO_VIEWED);
129 } 137 }
130 138
131 StringValue header_value(header); 139 StringValue header_value(header);
132 StringValue sub_header_value(sub_header); 140 StringValue sub_header_value(sub_header);
133 web_ui_->CallJavascriptFunction( 141 web_ui_->CallJavascriptFunction(
134 "updateLogin", header_value, sub_header_value); 142 "updateLogin", header_value, sub_header_value);
135 } 143 }
136 144
145 // static
137 bool NTPLoginHandler::ShouldShow(Profile* profile) { 146 bool NTPLoginHandler::ShouldShow(Profile* profile) {
138 #if defined(OS_CHROMEOS) 147 #if defined(OS_CHROMEOS)
139 // For now we don't care about showing sync status on Chrome OS. The promo 148 // For now we don't care about showing sync status on Chrome OS. The promo
140 // UI and the avatar menu don't exist on that platform. 149 // UI and the avatar menu don't exist on that platform.
141 return false; 150 return false;
142 #else 151 #else
143 if (profile->IsOffTheRecord()) 152 if (profile->IsOffTheRecord())
144 return false; 153 return false;
145 154
146 return profile->GetOriginalProfile()->IsSyncAccessible(); 155 return profile->GetOriginalProfile()->IsSyncAccessible();
147 #endif 156 #endif
148 } 157 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698