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

Side by Side Diff: chrome/browser/dom_ui/new_tab_page_sync_handler.cc

Issue 270081: Facelifts to sync UI (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 #ifdef CHROME_PERSONALIZATION 5 #ifdef CHROME_PERSONALIZATION
6 6
7 #include "chrome/browser/dom_ui/new_tab_page_sync_handler.h" 7 #include "chrome/browser/dom_ui/new_tab_page_sync_handler.h"
8 8
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "base/json_writer.h" 10 #include "base/json_writer.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 73
74 NewTabPageSyncHandler::NewTabPageSyncHandler() : sync_service_(NULL), 74 NewTabPageSyncHandler::NewTabPageSyncHandler() : sync_service_(NULL),
75 waiting_for_initial_page_load_(true) { 75 waiting_for_initial_page_load_(true) {
76 } 76 }
77 77
78 NewTabPageSyncHandler::~NewTabPageSyncHandler() { 78 NewTabPageSyncHandler::~NewTabPageSyncHandler() {
79 if (sync_service_) 79 if (sync_service_)
80 sync_service_->RemoveObserver(this); 80 sync_service_->RemoveObserver(this);
81 } 81 }
82 82
83 // static
84 NewTabPageSyncHandler::MessageType
85 NewTabPageSyncHandler::FromSyncStatusMessageType(
86 SyncStatusUIHelper::MessageType type) {
87 switch (type) {
88 case SyncStatusUIHelper::SYNC_ERROR:
89 return SYNC_ERROR;
90 case SyncStatusUIHelper::PRE_SYNCED:
91 case SyncStatusUIHelper::SYNCED:
92 default:
93 return HIDE;
94 }
95 }
96
83 DOMMessageHandler* NewTabPageSyncHandler::Attach(DOMUI* dom_ui) { 97 DOMMessageHandler* NewTabPageSyncHandler::Attach(DOMUI* dom_ui) {
84 sync_service_ = dom_ui->GetProfile()->GetProfileSyncService(); 98 sync_service_ = dom_ui->GetProfile()->GetProfileSyncService();
85 DCHECK(sync_service_); // This shouldn't get called by an incognito NTP. 99 DCHECK(sync_service_); // This shouldn't get called by an incognito NTP.
86 sync_service_->AddObserver(this); 100 sync_service_->AddObserver(this);
87 return DOMMessageHandler::Attach(dom_ui); 101 return DOMMessageHandler::Attach(dom_ui);
88 } 102 }
89 103
90 void NewTabPageSyncHandler::RegisterMessages() { 104 void NewTabPageSyncHandler::RegisterMessages() {
91 dom_ui_->RegisterMessageCallback("GetSyncMessage", 105 dom_ui_->RegisterMessageCallback("GetSyncMessage",
92 NewCallback(this, &NewTabPageSyncHandler::HandleGetSyncMessage)); 106 NewCallback(this, &NewTabPageSyncHandler::HandleGetSyncMessage));
93 dom_ui_->RegisterMessageCallback("SyncLinkClicked", 107 dom_ui_->RegisterMessageCallback("SyncLinkClicked",
94 NewCallback(this, &NewTabPageSyncHandler::HandleSyncLinkClicked)); 108 NewCallback(this, &NewTabPageSyncHandler::HandleSyncLinkClicked));
95 } 109 }
96 110
97 void NewTabPageSyncHandler::HandleGetSyncMessage(const Value* value) { 111 void NewTabPageSyncHandler::HandleGetSyncMessage(const Value* value) {
98 waiting_for_initial_page_load_ = false; 112 waiting_for_initial_page_load_ = false;
99 BuildAndSendSyncStatus(); 113 BuildAndSendSyncStatus();
100 } 114 }
101 115
102 void NewTabPageSyncHandler::HideSyncStatusSection() { 116 void NewTabPageSyncHandler::HideSyncStatusSection() {
103 SendSyncMessageToPage(SyncStatusUIHelper::PRE_SYNCED, std::string(), 117 SendSyncMessageToPage(HIDE, std::string(), std::string());
104 std::string());
105 } 118 }
106 119
107 void NewTabPageSyncHandler::BuildAndSendSyncStatus() { 120 void NewTabPageSyncHandler::BuildAndSendSyncStatus() {
108 DCHECK(!waiting_for_initial_page_load_); 121 DCHECK(!waiting_for_initial_page_load_);
109 122
110 // Hide the sync status section if sync is disabled entirely. 123 // Hide the sync status section if sync is disabled entirely.
111 if (!sync_service_) { 124 if (!sync_service_) {
112 HideSyncStatusSection(); 125 HideSyncStatusSection();
113 return; 126 return;
114 } 127 }
115 128
116 // We show the sync promotion if sync has not been enabled and the user is 129 // We show the sync promotion if sync has not been enabled and the user is
117 // logged in to Google Accounts. If the user is not signed in to GA, we 130 // logged in to Google Accounts. If the user is not signed in to GA, we
118 // should hide the sync status section entirely. 131 // should hide the sync status section entirely.
119 if (!sync_service_->HasSyncSetupCompleted() && 132 if (!sync_service_->HasSyncSetupCompleted()) {
120 !sync_service_->SetupInProgress()) { 133 if(!sync_service_->SetupInProgress() && IsGoogleGAIACookieInstalled()) {
121 if (IsGoogleGAIACookieInstalled()) { 134 SendSyncMessageToPage(PROMOTION,
122 SendSyncMessageToPage(SyncStatusUIHelper::PRE_SYNCED,
123 WideToUTF8(l10n_util::GetString(IDS_SYNC_NTP_PROMOTION_MESSAGE)), 135 WideToUTF8(l10n_util::GetString(IDS_SYNC_NTP_PROMOTION_MESSAGE)),
124 WideToUTF8(l10n_util::GetString(IDS_SYNC_NTP_START_NOW_LINK_LABEL))); 136 WideToUTF8(l10n_util::GetString(IDS_SYNC_NTP_START_NOW_LINK_LABEL)));
125 } else {
126 HideSyncStatusSection();
127 } 137 }
128 return; 138 return;
129 } 139 }
130 140
131 // Once sync has been enabled, the supported "sync statuses" for the NNTP 141 // Once sync has been enabled, the supported "sync statuses" for the NNTP
132 // from the user's perspective are: 142 // from the user's perspective are:
133 // 143 //
134 // "Synced to foo@gmail.com", when we are successfully authenticated and
135 // connected to a sync server.
136 // "Sync error", when we can't authenticate or establish a connection with 144 // "Sync error", when we can't authenticate or establish a connection with
137 // the sync server (appropriate information appended to 145 // the sync server (appropriate information appended to
138 // message). 146 // message).
139 // "Authenticating", when credentials are in flight.
140 SyncStatusUIHelper::MessageType type(SyncStatusUIHelper::PRE_SYNCED);
141 std::wstring status_msg; 147 std::wstring status_msg;
142 std::wstring link_text; 148 std::wstring link_text;
143 type = SyncStatusUIHelper::GetLabels(sync_service_, &status_msg, &link_text); 149 SyncStatusUIHelper::MessageType type =
144 SendSyncMessageToPage(type, WideToUTF8(status_msg), WideToUTF8(link_text)); 150 SyncStatusUIHelper::GetLabels(sync_service_, &status_msg, &link_text);
151 SendSyncMessageToPage(FromSyncStatusMessageType(type),
152 WideToUTF8(status_msg), WideToUTF8(link_text));
145 } 153 }
146 154
147 void NewTabPageSyncHandler::HandleSyncLinkClicked(const Value* value) { 155 void NewTabPageSyncHandler::HandleSyncLinkClicked(const Value* value) {
148 DCHECK(!waiting_for_initial_page_load_); 156 DCHECK(!waiting_for_initial_page_load_);
149 DCHECK(sync_service_); 157 DCHECK(sync_service_);
150 if (sync_service_->HasSyncSetupCompleted()) { 158 if (sync_service_->HasSyncSetupCompleted()) {
151 // User clicked the 'Login again' link to re-authenticate. 159 // User clicked the 'Login again' link to re-authenticate.
152 sync_service_->ShowLoginDialog(); 160 sync_service_->ShowLoginDialog();
153 } else { 161 } else {
154 // User clicked the 'Start now' link to begin syncing. 162 // User clicked the 'Start now' link to begin syncing.
155 ProfileSyncService::SyncEvent(ProfileSyncService::START_FROM_NTP); 163 ProfileSyncService::SyncEvent(ProfileSyncService::START_FROM_NTP);
156 sync_service_->EnableForUser(); 164 sync_service_->EnableForUser();
157 } 165 }
158 } 166 }
159 167
160 void NewTabPageSyncHandler::OnStateChanged() { 168 void NewTabPageSyncHandler::OnStateChanged() {
161 // Don't do anything if the page has not yet loaded. 169 // Don't do anything if the page has not yet loaded.
162 if (waiting_for_initial_page_load_) 170 if (waiting_for_initial_page_load_)
163 return; 171 return;
164 BuildAndSendSyncStatus(); 172 BuildAndSendSyncStatus();
165 } 173 }
166 174
167 void NewTabPageSyncHandler::SendSyncMessageToPage( 175 void NewTabPageSyncHandler::SendSyncMessageToPage(
168 SyncStatusUIHelper::MessageType type, std::string msg, 176 MessageType type, std::string msg,
169 std::string linktext) { 177 std::string linktext) {
170 DictionaryValue value; 178 DictionaryValue value;
171 std::string msgtype; 179 std::string msgtype;
172 std::wstring user; 180 std::wstring user;
173 std::string title = 181 std::string title =
174 WideToUTF8(l10n_util::GetString(IDS_SYNC_NTP_SYNC_SECTION_TITLE)); 182 WideToUTF8(l10n_util::GetString(IDS_SYNC_NTP_SYNC_SECTION_TITLE));
175 std::string linkurl; 183 std::string linkurl;
176 switch (type) { 184 switch (type) {
177 case SyncStatusUIHelper::PRE_SYNCED: 185 case HIDE:
186 case PROMOTION:
178 msgtype = "presynced"; 187 msgtype = "presynced";
179 break; 188 break;
180 case SyncStatusUIHelper::SYNCED: 189 case SYNC_ERROR:
181 msgtype = "synced";
182 linktext =
183 WideToUTF8(l10n_util::GetString(IDS_SYNC_NTP_VIEW_ONLINE_LINK));
184 linkurl = kSyncDefaultViewOnlineUrl;
185 user = UTF16ToWide(sync_service_->GetAuthenticatedUsername());
186 msg = WideToUTF8(l10n_util::GetStringF(IDS_SYNC_NTP_SYNCED_TO, user));
187 break;
188 case SyncStatusUIHelper::SYNC_ERROR:
189 title = 190 title =
190 WideToUTF8( 191 WideToUTF8(
191 l10n_util::GetString(IDS_SYNC_NTP_SYNC_SECTION_ERROR_TITLE)); 192 l10n_util::GetString(IDS_SYNC_NTP_SYNC_SECTION_ERROR_TITLE));
192 msgtype = "error"; 193 msgtype = "error";
193 break; 194 break;
195 default:
196 NOTREACHED();
197 break;
194 } 198 }
195 199
196 // If there is no message to show, we should hide the sync section 200 // If there is no message to show, we should hide the sync section
197 // altogether. 201 // altogether.
198 if (msg.empty()) { 202 if (type == HIDE || msg.empty()) {
199 value.SetBoolean(L"syncsectionisvisible", false); 203 value.SetBoolean(L"syncsectionisvisible", false);
200 } else { 204 } else {
201 value.SetBoolean(L"syncsectionisvisible", true); 205 value.SetBoolean(L"syncsectionisvisible", true);
202 value.SetString(L"msg", msg); 206 value.SetString(L"msg", msg);
203 value.SetString(L"title", title); 207 value.SetString(L"title", title);
204 value.SetString(L"msgtype", msgtype); 208 value.SetString(L"msgtype", msgtype);
205 if (linktext.empty()) { 209 if (linktext.empty()) {
206 value.SetBoolean(L"linkisvisible", false); 210 value.SetBoolean(L"linkisvisible", false);
207 } else { 211 } else {
208 value.SetBoolean(L"linkisvisible", true); 212 value.SetBoolean(L"linkisvisible", true);
209 value.SetString(L"linktext", linktext); 213 value.SetString(L"linktext", linktext);
210 214
211 // The only time we set the URL is when the user is synced and we need to 215 // The only time we set the URL is when the user is synced and we need to
212 // show a link to a web interface (e.g. http://docs.google.com). When we 216 // show a link to a web interface (e.g. http://docs.google.com). When we
213 // set that URL, HandleSyncLinkClicked won't be called when the user 217 // set that URL, HandleSyncLinkClicked won't be called when the user
214 // clicks on the link. 218 // clicks on the link.
215 if (linkurl.empty()) { 219 if (linkurl.empty()) {
216 value.SetBoolean(L"linkurlisset", false); 220 value.SetBoolean(L"linkurlisset", false);
217 } else { 221 } else {
218 value.SetBoolean(L"linkurlisset", true); 222 value.SetBoolean(L"linkurlisset", true);
219 value.SetString(L"linkurl", linkurl); 223 value.SetString(L"linkurl", linkurl);
220 } 224 }
221 } 225 }
222 } 226 }
223 dom_ui_->CallJavascriptFunction(L"syncMessageChanged", value); 227 dom_ui_->CallJavascriptFunction(L"syncMessageChanged", value);
224 } 228 }
225 229
226 #endif // CHROME_PERSONALIZATION 230 #endif // CHROME_PERSONALIZATION
OLDNEW
« no previous file with comments | « chrome/browser/dom_ui/new_tab_page_sync_handler.h ('k') | chrome/browser/resources/new_new_tab.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698