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

Side by Side Diff: chrome/browser/ui/webui/sync_setup_handler.cc

Issue 1421893005: Settings Rewrite: Fork SyncSetupHandler for MD-Settings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
OLDNEW
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/options/sync_setup_handler.h" 5 #include "chrome/browser/ui/webui/sync_setup_handler.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/i18n/time_formatting.h" 12 #include "base/i18n/time_formatting.h"
13 #include "base/json/json_reader.h" 13 #include "base/json/json_reader.h"
14 #include "base/json/json_writer.h" 14 #include "base/json/json_writer.h"
15 #include "base/metrics/histogram.h" 15 #include "base/metrics/histogram.h"
16 #include "base/prefs/pref_service.h" 16 #include "base/prefs/pref_service.h"
17 #include "base/strings/utf_string_conversions.h"
18 #include "base/values.h" 17 #include "base/values.h"
19 #include "chrome/app/chrome_command_ids.h"
20 #include "chrome/browser/browser_process.h"
21 #include "chrome/browser/lifetime/application_lifetime.h" 18 #include "chrome/browser/lifetime/application_lifetime.h"
22 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/profiles/profile_info_cache.h" 20 #include "chrome/browser/profiles/profile_info_cache.h"
24 #include "chrome/browser/profiles/profile_metrics.h" 21 #include "chrome/browser/profiles/profile_metrics.h"
25 #include "chrome/browser/signin/chrome_signin_helper.h" 22 #include "chrome/browser/signin/chrome_signin_helper.h"
26 #include "chrome/browser/signin/signin_error_controller_factory.h" 23 #include "chrome/browser/signin/signin_error_controller_factory.h"
27 #include "chrome/browser/signin/signin_manager_factory.h" 24 #include "chrome/browser/signin/signin_manager_factory.h"
28 #include "chrome/browser/signin/signin_promo.h" 25 #include "chrome/browser/signin/signin_promo.h"
29 #include "chrome/browser/sync/profile_sync_service.h" 26 #include "chrome/browser/sync/profile_sync_service.h"
30 #include "chrome/browser/sync/profile_sync_service_factory.h" 27 #include "chrome/browser/sync/profile_sync_service_factory.h"
31 #include "chrome/browser/ui/browser_finder.h" 28 #include "chrome/browser/ui/browser_finder.h"
32 #include "chrome/browser/ui/browser_window.h" 29 #include "chrome/browser/ui/browser_window.h"
33 #include "chrome/browser/ui/singleton_tabs.h" 30 #include "chrome/browser/ui/singleton_tabs.h"
34 #include "chrome/browser/ui/webui/options/options_handlers_helper.h" 31 #include "chrome/browser/ui/webui/options/options_handlers_helper.h"
35 #include "chrome/browser/ui/webui/signin/login_ui_service.h" 32 #include "chrome/browser/ui/webui/signin/login_ui_service.h"
36 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" 33 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
37 #include "chrome/common/chrome_switches.h" 34 #include "chrome/common/chrome_switches.h"
38 #include "chrome/common/url_constants.h"
39 #include "chrome/grit/chromium_strings.h"
40 #include "chrome/grit/generated_resources.h" 35 #include "chrome/grit/generated_resources.h"
41 #include "chrome/grit/locale_settings.h"
42 #include "components/google/core/browser/google_util.h"
43 #include "components/signin/core/browser/signin_error_controller.h" 36 #include "components/signin/core/browser/signin_error_controller.h"
44 #include "components/signin/core/browser/signin_header_helper.h" 37 #include "components/signin/core/browser/signin_header_helper.h"
45 #include "components/signin/core/browser/signin_metrics.h" 38 #include "components/signin/core/browser/signin_metrics.h"
46 #include "components/signin/core/common/profile_management_switches.h" 39 #include "components/signin/core/common/profile_management_switches.h"
47 #include "components/sync_driver/sync_prefs.h" 40 #include "components/sync_driver/sync_prefs.h"
48 #include "content/public/browser/render_view_host.h" 41 #include "content/public/browser/render_view_host.h"
49 #include "content/public/browser/web_contents.h" 42 #include "content/public/browser/web_contents.h"
50 #include "content/public/browser/web_contents_delegate.h" 43 #include "content/public/browser/web_contents_delegate.h"
51 #include "google_apis/gaia/gaia_auth_util.h" 44 #include "google_apis/gaia/gaia_auth_util.h"
52 #include "google_apis/gaia/gaia_constants.h" 45 #include "google_apis/gaia/gaia_constants.h"
53 #include "grit/components_strings.h"
54 #include "net/base/url_util.h" 46 #include "net/base/url_util.h"
55 #include "ui/base/l10n/l10n_util.h" 47 #include "ui/base/l10n/l10n_util.h"
56 48
57 #if defined(OS_CHROMEOS) 49 #if defined(OS_CHROMEOS)
58 #include "components/signin/core/browser/signin_manager_base.h" 50 #include "components/signin/core/browser/signin_manager_base.h"
59 #else 51 #else
60 #include "components/signin/core/browser/signin_manager.h" 52 #include "components/signin/core/browser/signin_manager.h"
61 #endif 53 #endif
62 54
63 using content::WebContents; 55 using content::WebContents;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 if (!result->GetString("passphrase", &config->passphrase)) { 137 if (!result->GetString("passphrase", &config->passphrase)) {
146 DLOG(ERROR) << "GetConfiguration() not passed a passphrase value"; 138 DLOG(ERROR) << "GetConfiguration() not passed a passphrase value";
147 return false; 139 return false;
148 } 140 }
149 } 141 }
150 return true; 142 return true;
151 } 143 }
152 144
153 } // namespace 145 } // namespace
154 146
155 SyncSetupHandler::SyncSetupHandler() 147 SyncSetupHandler::SyncSetupHandler(content::WebUI* web_ui)
156 : configuring_sync_(false) { 148 : content::WebUIMessageHandler(web_ui), configuring_sync_(false) {
157 } 149 }
158 150
159 SyncSetupHandler::~SyncSetupHandler() { 151 SyncSetupHandler::~SyncSetupHandler() {
160 // Just exit if running unit tests (no actual WebUI is attached). 152 // Just exit if running unit tests (no actual WebUI is attached).
161 if (!web_ui()) 153 if (!web_ui())
162 return; 154 return;
163 155
164 // This case is hit when the user performs a back navigation. 156 // This case is hit when the user performs a back navigation.
165 CloseSyncSetup(); 157 CloseSyncSetup();
166 } 158 }
167 159
168 void SyncSetupHandler::GetLocalizedValues(
169 base::DictionaryValue* localized_strings) {
170 GetStaticLocalizedValues(localized_strings, web_ui());
171 }
172
173 void SyncSetupHandler::GetStaticLocalizedValues(
174 base::DictionaryValue* localized_strings,
175 content::WebUI* web_ui) {
176 DCHECK(localized_strings);
177
178 base::string16 product_name(GetStringUTF16(IDS_PRODUCT_NAME));
179 localized_strings->SetString(
180 "chooseDataTypesInstructions",
181 GetStringFUTF16(IDS_SYNC_CHOOSE_DATATYPES_INSTRUCTIONS, product_name));
182 localized_strings->SetString(
183 "encryptionInstructions",
184 GetStringFUTF16(IDS_SYNC_ENCRYPTION_INSTRUCTIONS, product_name));
185 localized_strings->SetString(
186 "encryptionHelpURL", chrome::kSyncEncryptionHelpURL);
187 localized_strings->SetString(
188 "encryptionSectionMessage",
189 GetStringFUTF16(IDS_SYNC_ENCRYPTION_SECTION_MESSAGE, product_name));
190 localized_strings->SetString(
191 "passphraseRecover",
192 GetStringFUTF16(
193 IDS_SYNC_PASSPHRASE_RECOVER,
194 base::ASCIIToUTF16(
195 google_util::AppendGoogleLocaleParam(
196 GURL(chrome::kSyncGoogleDashboardURL),
197 g_browser_process->GetApplicationLocale()).spec())));
198 localized_strings->SetString(
199 "stopSyncingExplanation",
200 l10n_util::GetStringFUTF16(
201 IDS_SYNC_STOP_SYNCING_EXPLANATION_LABEL,
202 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME),
203 base::ASCIIToUTF16(
204 google_util::AppendGoogleLocaleParam(
205 GURL(chrome::kSyncGoogleDashboardURL),
206 g_browser_process->GetApplicationLocale()).spec())));
207 localized_strings->SetString("deleteProfileLabel",
208 l10n_util::GetStringUTF16(IDS_SYNC_STOP_DELETE_PROFILE_LABEL));
209 localized_strings->SetString("stopSyncingTitle",
210 l10n_util::GetStringUTF16(IDS_SYNC_STOP_SYNCING_DIALOG_TITLE));
211 localized_strings->SetString("stopSyncingConfirm",
212 l10n_util::GetStringUTF16(IDS_SYNC_STOP_SYNCING_CONFIRM_BUTTON_LABEL));
213
214 localized_strings->SetString(
215 "syncEverythingHelpURL", chrome::kSyncEverythingLearnMoreURL);
216 localized_strings->SetString(
217 "syncErrorHelpURL", chrome::kSyncErrorsHelpURL);
218
219 static OptionsStringResource resources[] = {
220 { "syncSetupConfigureTitle", IDS_SYNC_SETUP_CONFIGURE_TITLE },
221 { "syncSetupSpinnerTitle", IDS_SYNC_SETUP_SPINNER_TITLE },
222 { "syncSetupTimeoutTitle", IDS_SYNC_SETUP_TIME_OUT_TITLE },
223 { "syncSetupTimeoutContent", IDS_SYNC_SETUP_TIME_OUT_CONTENT },
224 { "errorLearnMore", IDS_LEARN_MORE },
225 { "cancel", IDS_CANCEL },
226 { "loginSuccess", IDS_SYNC_SUCCESS },
227 { "settingUp", IDS_SYNC_LOGIN_SETTING_UP },
228 { "syncAllDataTypes", IDS_SYNC_EVERYTHING },
229 { "chooseDataTypes", IDS_SYNC_CHOOSE_DATATYPES },
230 { "syncNothing", IDS_SYNC_NOTHING },
231 { "bookmarks", IDS_SYNC_DATATYPE_BOOKMARKS },
232 { "preferences", IDS_SYNC_DATATYPE_PREFERENCES },
233 { "autofill", IDS_SYNC_DATATYPE_AUTOFILL },
234 { "themes", IDS_SYNC_DATATYPE_THEMES },
235 { "passwords", IDS_SYNC_DATATYPE_PASSWORDS },
236 { "extensions", IDS_SYNC_DATATYPE_EXTENSIONS },
237 { "typedURLs", IDS_SYNC_DATATYPE_TYPED_URLS },
238 { "apps", IDS_SYNC_DATATYPE_APPS },
239 { "wifiCredentials", IDS_SYNC_DATATYPE_WIFI_CREDENTIALS },
240 { "openTabs", IDS_SYNC_DATATYPE_TABS },
241 { "serviceUnavailableError", IDS_SYNC_SETUP_ABORTED_BY_PENDING_CLEAR },
242 { "confirmLabel", IDS_SYNC_CONFIRM_PASSPHRASE_LABEL },
243 { "emptyErrorMessage", IDS_SYNC_EMPTY_PASSPHRASE_ERROR },
244 { "mismatchErrorMessage", IDS_SYNC_PASSPHRASE_MISMATCH_ERROR },
245 { "customizeLinkLabel", IDS_SYNC_CUSTOMIZE_LINK_LABEL },
246 { "confirmSyncPreferences", IDS_SYNC_CONFIRM_SYNC_PREFERENCES },
247 { "syncEverything", IDS_SYNC_SYNC_EVERYTHING },
248 { "useDefaultSettings", IDS_SYNC_USE_DEFAULT_SETTINGS },
249 { "enterPassphraseBody", IDS_SYNC_ENTER_PASSPHRASE_BODY },
250 { "enterGooglePassphraseBody", IDS_SYNC_ENTER_GOOGLE_PASSPHRASE_BODY },
251 { "passphraseLabel", IDS_SYNC_PASSPHRASE_LABEL },
252 { "incorrectPassphrase", IDS_SYNC_INCORRECT_PASSPHRASE },
253 { "passphraseWarning", IDS_SYNC_PASSPHRASE_WARNING },
254 { "yes", IDS_SYNC_PASSPHRASE_CANCEL_YES },
255 { "no", IDS_SYNC_PASSPHRASE_CANCEL_NO },
256 { "sectionExplicitMessagePrefix", IDS_SYNC_PASSPHRASE_MSG_EXPLICIT_PREFIX },
257 { "sectionExplicitMessagePostfix",
258 IDS_SYNC_PASSPHRASE_MSG_EXPLICIT_POSTFIX },
259 // TODO(rogerta): browser/resource/sync_promo/sync_promo.html and related
260 // file may not be needed any more. If not, then the following promo
261 // strings can also be removed.
262 { "promoPageTitle", IDS_SYNC_PROMO_TAB_TITLE },
263 { "promoSkipButton", IDS_SYNC_PROMO_SKIP_BUTTON },
264 { "promoAdvanced", IDS_SYNC_PROMO_ADVANCED },
265 { "promoLearnMore", IDS_LEARN_MORE },
266 { "promoTitleShort", IDS_SYNC_PROMO_MESSAGE_TITLE_SHORT },
267 { "encryptionSectionTitle", IDS_SYNC_ENCRYPTION_SECTION_TITLE },
268 { "basicEncryptionOption", IDS_SYNC_BASIC_ENCRYPTION_DATA },
269 { "fullEncryptionOption", IDS_SYNC_FULL_ENCRYPTION_DATA },
270 };
271
272 RegisterStrings(localized_strings, resources, arraysize(resources));
273 RegisterTitle(localized_strings, "syncSetupOverlay", IDS_SYNC_SETUP_TITLE);
274 }
275
276 void SyncSetupHandler::ConfigureSyncDone() { 160 void SyncSetupHandler::ConfigureSyncDone() {
277 base::StringValue page("done"); 161 base::StringValue page("done");
278 web_ui()->CallJavascriptFunction( 162 web_ui()->CallJavascriptFunction(
279 "SyncSetupOverlay.showSyncSetupPage", page); 163 "SyncSetupOverlay.showSyncSetupPage", page);
280 164
281 // Suppress the sign in promo once the user starts sync. This way the user 165 // Suppress the sign in promo once the user starts sync. This way the user
282 // doesn't see the sign in promo even if they sign out later on. 166 // doesn't see the sign in promo even if they sign out later on.
283 signin::SetUserSkippedPromo(GetProfile()); 167 signin::SetUserSkippedPromo(GetProfile());
284 168
285 ProfileSyncService* service = GetSyncService(); 169 ProfileSyncService* service = GetSyncService();
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 backend_start_timer_.reset(); 346 backend_start_timer_.reset();
463 347
464 DisplayConfigureSync(false); 348 DisplayConfigureSync(false);
465 } 349 }
466 350
467 Profile* SyncSetupHandler::GetProfile() const { 351 Profile* SyncSetupHandler::GetProfile() const {
468 return Profile::FromWebUI(web_ui()); 352 return Profile::FromWebUI(web_ui());
469 } 353 }
470 354
471 ProfileSyncService* SyncSetupHandler::GetSyncService() const { 355 ProfileSyncService* SyncSetupHandler::GetSyncService() const {
472 Profile* profile = GetProfile(); 356 return GetProfile()->IsSyncAllowed() ?
473 return profile->IsSyncAllowed() ?
474 ProfileSyncServiceFactory::GetForProfile(GetProfile()) : NULL; 357 ProfileSyncServiceFactory::GetForProfile(GetProfile()) : NULL;
475 } 358 }
476 359
477 void SyncSetupHandler::HandleConfigure(const base::ListValue* args) { 360 void SyncSetupHandler::HandleConfigure(const base::ListValue* args) {
478 DCHECK(!sync_startup_tracker_); 361 DCHECK(!sync_startup_tracker_);
479 std::string json; 362 std::string json;
480 if (!args->GetString(0, &json)) { 363 if (!args->GetString(0, &json)) {
481 NOTREACHED() << "Could not read JSON argument"; 364 NOTREACHED() << "Could not read JSON argument";
482 return; 365 return;
483 } 366 }
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 "SyncSetupOverlay.showSyncSetupPage", page, args); 802 "SyncSetupOverlay.showSyncSetupPage", page, args);
920 803
921 // Make sure the tab used for the Gaia sign in does not cover the settings 804 // Make sure the tab used for the Gaia sign in does not cover the settings
922 // tab. 805 // tab.
923 FocusUI(); 806 FocusUI();
924 } 807 }
925 808
926 LoginUIService* SyncSetupHandler::GetLoginUIService() const { 809 LoginUIService* SyncSetupHandler::GetLoginUIService() const {
927 return LoginUIServiceFactory::GetForProfile(GetProfile()); 810 return LoginUIServiceFactory::GetForProfile(GetProfile());
928 } 811 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698