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

Side by Side Diff: chrome/browser/views/sync/sync_setup_flow.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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/views/sync/sync_setup_flow.h" 7 #include "chrome/browser/views/sync/sync_setup_flow.h"
8 8
9 #include "app/gfx/font.h" 9 #include "app/gfx/font.h"
10 #include "base/histogram.h" 10 #include "base/histogram.h"
11 #include "base/json_reader.h" 11 #include "base/json_reader.h"
12 #include "base/json_writer.h" 12 #include "base/json_writer.h"
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/browser.h" 15 #include "chrome/browser/browser.h"
16 #include "chrome/browser/browser_list.h" 16 #include "chrome/browser/browser_list.h"
17 #include "chrome/browser/renderer_host/render_view_host.h" 17 #include "chrome/browser/renderer_host/render_view_host.h"
18 #include "chrome/browser/sync/auth_error_state.h" 18 #include "chrome/browser/sync/auth_error_state.h"
19 #include "chrome/browser/sync/profile_sync_service.h" 19 #include "chrome/browser/sync/profile_sync_service.h"
20 #include "chrome/browser/tab_contents/tab_contents.h" 20 #include "chrome/browser/tab_contents/tab_contents.h"
21 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
22 #include "grit/locale_settings.h" 22 #include "grit/locale_settings.h"
23 #include "views/window/window.h" 23 #include "views/window/window.h"
24 24
25 // XPath expression for finding specific iframes. 25 // XPath expression for finding specific iframes.
26 static const wchar_t* kLoginIFrameXPath = L"//iframe[@id='login']"; 26 static const wchar_t* kLoginIFrameXPath = L"//iframe[@id='login']";
27 static const wchar_t* kMergeIFrameXPath = L"//iframe[@id='merge']"; 27 static const wchar_t* kMergeIFrameXPath = L"//iframe[@id='merge']";
28 static const wchar_t* kDoneIframeXPath = L"//iframe[@id='done']";
28 29
29 // Helper function to read the JSON string from the Value parameter. 30 // Helper function to read the JSON string from the Value parameter.
30 static std::string GetJsonResponse(const Value* content) { 31 static std::string GetJsonResponse(const Value* content) {
31 if (!content || !content->IsType(Value::TYPE_LIST)) { 32 if (!content || !content->IsType(Value::TYPE_LIST)) {
32 NOTREACHED(); 33 NOTREACHED();
33 return std::string(); 34 return std::string();
34 } 35 }
35 const ListValue* args = static_cast<const ListValue*>(content); 36 const ListValue* args = static_cast<const ListValue*>(content);
36 if (args->GetSize() != 1) { 37 if (args->GetSize() != 1) {
37 NOTREACHED(); 38 NOTREACHED();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 void FlowHandler::ShowGaiaSuccessAndSettingUp() { 108 void FlowHandler::ShowGaiaSuccessAndSettingUp() {
108 ExecuteJavascriptInIFrame(kLoginIFrameXPath, 109 ExecuteJavascriptInIFrame(kLoginIFrameXPath,
109 L"showGaiaSuccessAndSettingUp();"); 110 L"showGaiaSuccessAndSettingUp();");
110 } 111 }
111 112
112 void FlowHandler::ShowMergeAndSync() { 113 void FlowHandler::ShowMergeAndSync() {
113 if (dom_ui_) // NULL during testing. 114 if (dom_ui_) // NULL during testing.
114 dom_ui_->CallJavascriptFunction(L"showMergeAndSync"); 115 dom_ui_->CallJavascriptFunction(L"showMergeAndSync");
115 } 116 }
116 117
117 void FlowHandler::ShowMergeAndSyncDone() { 118 void FlowHandler::ShowSetupDone(const std::wstring& user) {
118 ExecuteJavascriptInIFrame(kMergeIFrameXPath, L"showMergeAndSyncDone();"); 119 StringValue synced_to_string(WideToUTF8(l10n_util::GetStringF(
120 IDS_SYNC_NTP_SYNCED_TO, user)));
121 std::string json;
122 JSONWriter::Write(&synced_to_string, false, &json);
123 std::wstring javascript = std::wstring(L"setSyncedToUser") +
124 L"(" + UTF8ToWide(json) + L");";
125 ExecuteJavascriptInIFrame(kDoneIframeXPath, javascript);
126
127 if (dom_ui_)
128 dom_ui_->CallJavascriptFunction(L"showSetupDone", synced_to_string);
129 }
130
131 void FlowHandler::ShowFirstTimeDone(const std::wstring& user) {
132 ExecuteJavascriptInIFrame(kDoneIframeXPath,
133 L"setShowFirstTimeSetupSummary();");
134 ShowSetupDone(user);
119 } 135 }
120 136
121 void FlowHandler::ShowMergeAndSyncError() { 137 void FlowHandler::ShowMergeAndSyncError() {
122 ExecuteJavascriptInIFrame(kMergeIFrameXPath, L"showMergeAndSyncError();"); 138 ExecuteJavascriptInIFrame(kMergeIFrameXPath, L"showMergeAndSyncError();");
123 } 139 }
124 140
125 void FlowHandler::ExecuteJavascriptInIFrame(const std::wstring& iframe_xpath, 141 void FlowHandler::ExecuteJavascriptInIFrame(const std::wstring& iframe_xpath,
126 const std::wstring& js) { 142 const std::wstring& js) {
127 if (dom_ui_) { 143 if (dom_ui_) {
128 RenderViewHost* rvh = dom_ui_->tab_contents()->render_view_host(); 144 RenderViewHost* rvh = dom_ui_->tab_contents()->render_view_host();
(...skipping 17 matching lines...) Expand all
146 approximate_web_font); 162 approximate_web_font);
147 163
148 size->set_width(s.width()); 164 size->set_width(s.width());
149 size->set_height(s.height()); 165 size->set_height(s.height());
150 } 166 }
151 167
152 // A callback to notify the delegate that the dialog closed. 168 // A callback to notify the delegate that the dialog closed.
153 void SyncSetupFlow::OnDialogClosed(const std::string& json_retval) { 169 void SyncSetupFlow::OnDialogClosed(const std::string& json_retval) {
154 DCHECK(json_retval.empty()); 170 DCHECK(json_retval.empty());
155 container_->set_flow(NULL); // Sever ties from the wizard. 171 container_->set_flow(NULL); // Sever ties from the wizard.
156 if (current_state_ == SyncSetupWizard::DONE) { 172 if (current_state_ == SyncSetupWizard::DONE ||
173 current_state_ == SyncSetupWizard::DONE_FIRST_TIME) {
157 service_->SetSyncSetupCompleted(); 174 service_->SetSyncSetupCompleted();
158 } 175 }
159 176
160 // Record the state at which the user cancelled the signon dialog. 177 // Record the state at which the user cancelled the signon dialog.
161 switch (current_state_) { 178 switch (current_state_) {
162 case SyncSetupWizard::GAIA_LOGIN: 179 case SyncSetupWizard::GAIA_LOGIN:
163 ProfileSyncService::SyncEvent( 180 ProfileSyncService::SyncEvent(
164 ProfileSyncService::CANCEL_FROM_SIGNON_WITHOUT_AUTH); 181 ProfileSyncService::CANCEL_FROM_SIGNON_WITHOUT_AUTH);
165 break; 182 break;
166 case SyncSetupWizard::GAIA_SUCCESS: 183 case SyncSetupWizard::GAIA_SUCCESS:
167 ProfileSyncService::SyncEvent( 184 ProfileSyncService::SyncEvent(
168 ProfileSyncService::CANCEL_DURING_SIGNON); 185 ProfileSyncService::CANCEL_DURING_SIGNON);
169 break; 186 break;
170 case SyncSetupWizard::MERGE_AND_SYNC: 187 case SyncSetupWizard::MERGE_AND_SYNC:
171 ProfileSyncService::SyncEvent( 188 ProfileSyncService::SyncEvent(
172 ProfileSyncService::CANCEL_DURING_SIGNON_AFTER_MERGE); 189 ProfileSyncService::CANCEL_DURING_SIGNON_AFTER_MERGE);
173 break; 190 break;
191 case SyncSetupWizard::DONE_FIRST_TIME:
174 case SyncSetupWizard::DONE: 192 case SyncSetupWizard::DONE:
175 UMA_HISTOGRAM_MEDIUM_TIMES("Sync.UserPerceivedAuthorizationTime", 193 UMA_HISTOGRAM_MEDIUM_TIMES("Sync.UserPerceivedAuthorizationTime",
176 base::TimeTicks::Now() - login_start_time_); 194 base::TimeTicks::Now() - login_start_time_);
177 break; 195 break;
178 default: 196 default:
179 break; 197 break;
180 } 198 }
181 199
182 service_->OnUserCancelledDialog(); 200 service_->OnUserCancelledDialog();
183 delete this; 201 delete this;
(...skipping 21 matching lines...) Expand all
205 bool SyncSetupFlow::ShouldAdvance(SyncSetupWizard::State state) { 223 bool SyncSetupFlow::ShouldAdvance(SyncSetupWizard::State state) {
206 switch (state) { 224 switch (state) {
207 case SyncSetupWizard::GAIA_LOGIN: 225 case SyncSetupWizard::GAIA_LOGIN:
208 return current_state_ == SyncSetupWizard::GAIA_LOGIN; 226 return current_state_ == SyncSetupWizard::GAIA_LOGIN;
209 case SyncSetupWizard::GAIA_SUCCESS: 227 case SyncSetupWizard::GAIA_SUCCESS:
210 return current_state_ == SyncSetupWizard::GAIA_LOGIN; 228 return current_state_ == SyncSetupWizard::GAIA_LOGIN;
211 case SyncSetupWizard::MERGE_AND_SYNC: 229 case SyncSetupWizard::MERGE_AND_SYNC:
212 return current_state_ == SyncSetupWizard::GAIA_SUCCESS; 230 return current_state_ == SyncSetupWizard::GAIA_SUCCESS;
213 case SyncSetupWizard::FATAL_ERROR: 231 case SyncSetupWizard::FATAL_ERROR:
214 return true; // You can always hit the panic button. 232 return true; // You can always hit the panic button.
233 case SyncSetupWizard::DONE_FIRST_TIME:
215 case SyncSetupWizard::DONE: 234 case SyncSetupWizard::DONE:
216 return current_state_ == SyncSetupWizard::MERGE_AND_SYNC || 235 return current_state_ == SyncSetupWizard::MERGE_AND_SYNC ||
217 current_state_ == SyncSetupWizard::GAIA_SUCCESS; 236 current_state_ == SyncSetupWizard::GAIA_SUCCESS;
218 default: 237 default:
219 NOTREACHED() << "Unhandled State: " << state; 238 NOTREACHED() << "Unhandled State: " << state;
220 return false; 239 return false;
221 } 240 }
222 } 241 }
223 242
224 void SyncSetupFlow::Advance(SyncSetupWizard::State advance_state) { 243 void SyncSetupFlow::Advance(SyncSetupWizard::State advance_state) {
(...skipping 12 matching lines...) Expand all
237 else 256 else
238 flow_handler_->ShowGaiaSuccessAndSettingUp(); 257 flow_handler_->ShowGaiaSuccessAndSettingUp();
239 break; 258 break;
240 case SyncSetupWizard::MERGE_AND_SYNC: 259 case SyncSetupWizard::MERGE_AND_SYNC:
241 flow_handler_->ShowMergeAndSync(); 260 flow_handler_->ShowMergeAndSync();
242 break; 261 break;
243 case SyncSetupWizard::FATAL_ERROR: 262 case SyncSetupWizard::FATAL_ERROR:
244 if (current_state_ == SyncSetupWizard::MERGE_AND_SYNC) 263 if (current_state_ == SyncSetupWizard::MERGE_AND_SYNC)
245 flow_handler_->ShowMergeAndSyncError(); 264 flow_handler_->ShowMergeAndSyncError();
246 break; 265 break;
266 case SyncSetupWizard::DONE_FIRST_TIME:
267 flow_handler_->ShowFirstTimeDone(service_->GetAuthenticatedUsername());
268 break;
247 case SyncSetupWizard::DONE: 269 case SyncSetupWizard::DONE:
248 if (current_state_ == SyncSetupWizard::MERGE_AND_SYNC) 270 flow_handler_->ShowSetupDone(service_->GetAuthenticatedUsername());
249 flow_handler_->ShowMergeAndSyncDone();
250 else if (current_state_ == SyncSetupWizard::GAIA_SUCCESS)
251 flow_handler_->ShowGaiaSuccessAndClose();
252 break; 271 break;
253 default: 272 default:
254 NOTREACHED() << "Invalid advance state: " << advance_state; 273 NOTREACHED() << "Invalid advance state: " << advance_state;
255 } 274 }
256 current_state_ = advance_state; 275 current_state_ = advance_state;
257 } 276 }
258 277
259 // static 278 // static
260 SyncSetupFlow* SyncSetupFlow::Run(ProfileSyncService* service, 279 SyncSetupFlow* SyncSetupFlow::Run(ProfileSyncService* service,
261 SyncSetupFlowContainer* container, 280 SyncSetupFlowContainer* container,
(...skipping 11 matching lines...) Expand all
273 292
274 FlowHandler* handler = new FlowHandler(); 293 FlowHandler* handler = new FlowHandler();
275 SyncSetupFlow* flow = new SyncSetupFlow(start, end, json_args, 294 SyncSetupFlow* flow = new SyncSetupFlow(start, end, json_args,
276 container, handler, service); 295 container, handler, service);
277 handler->set_flow(flow); 296 handler->set_flow(flow);
278 b->BrowserShowHtmlDialog(flow, NULL); 297 b->BrowserShowHtmlDialog(flow, NULL);
279 return flow; 298 return flow;
280 } 299 }
281 300
282 #endif // CHROME_PERSONALIZATION 301 #endif // CHROME_PERSONALIZATION
OLDNEW
« no previous file with comments | « chrome/browser/views/sync/sync_setup_flow.h ('k') | chrome/browser/views/sync/sync_setup_wizard.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698