OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ui/webui/options/reset_profile_settings_handler.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/bind_helpers.h" | |
9 #include "base/prefs/pref_service.h" | |
10 #include "base/string16.h" | |
11 #include "base/values.h" | |
12 #include "chrome/browser/google/google_util.h" | |
13 #include "chrome/browser/profile_resetter/profile_resetter.h" | |
14 #include "chrome/browser/profiles/profile.h" | |
15 #include "chrome/common/pref_names.h" | |
16 #include "content/public/browser/web_ui.h" | |
17 #include "grit/generated_resources.h" | |
18 #include "ui/base/l10n/l10n_util.h" | |
19 | |
20 namespace { | |
21 const char kResetProfileSettingsLearnMoreUrl[] = | |
22 "https://support.google.com/chrome/?p=settings_reset_profile_settings"; | |
23 } // namespace | |
24 | |
25 namespace options { | |
26 | |
27 ResetProfileSettingsHandler::ResetProfileSettingsHandler() | |
28 : resetter_(NULL) { | |
Dan Beam
2013/05/23 19:46:43
^ not necessary
battre
2013/05/24 09:15:46
Done.
| |
29 } | |
30 | |
31 ResetProfileSettingsHandler::~ResetProfileSettingsHandler() { | |
32 } | |
33 | |
34 void ResetProfileSettingsHandler::InitializeHandler() { | |
35 Profile* profile = Profile::FromWebUI(web_ui()); | |
36 resetter_.reset(new ProfileResetter(profile)); | |
37 } | |
38 | |
39 void ResetProfileSettingsHandler::GetLocalizedValues( | |
40 DictionaryValue* localized_strings) { | |
41 DCHECK(localized_strings); | |
42 | |
43 static OptionsStringResource resources[] = { | |
44 { "resetProfileSettingsLabel", IDS_RESET_PROFILE_SETTINGS_LABEL }, | |
45 { "resetDefaultSearchEngineCheckbox", | |
46 IDS_RESET_PROFILE_DEFAULT_SEARCH_ENGINE_CHECKBOX }, | |
47 { "resetHomepageCheckbox", IDS_RESET_PROFILE_HOMEPAGE_CHECKBOX }, | |
48 { "resetContentSettingsCheckbox", | |
49 IDS_RESET_PROFILE_CONTENT_SETTINGS_CHECKBOX }, | |
50 { "resetCookiesAndSiteDataCheckbox", IDS_RESET_PROFILE_COOKIES_CHECKBOX }, | |
51 { "resetExtensionsCheckbox", IDS_RESET_PROFILE_EXTENSIONS_CHECKBOX }, | |
52 { "resetProfileSettingsCommit", IDS_RESET_PROFILE_SETTINGS_COMMIT_BUTTON }, | |
53 }; | |
54 | |
55 RegisterStrings(localized_strings, resources, arraysize(resources)); | |
56 RegisterTitle(localized_strings, "resetProfileSettingsOverlay", | |
57 IDS_RESET_PROFILE_SETTINGS_TITLE); | |
58 localized_strings->SetString( | |
59 "resetProfileSettingsLearnMoreUrl", | |
60 google_util::StringAppendGoogleLocaleParam( | |
61 kResetProfileSettingsLearnMoreUrl)); | |
62 | |
63 ListValue* reset_extensions_handling = new ListValue; | |
Dan Beam
2013/05/23 19:46:43
nit: scoped_ptr<ListValue> ptr -> ptr.release()
battre
2013/05/24 09:15:46
Done.
| |
64 for (int i = 0; i < 2; i++) { | |
65 string16 label_string; | |
66 switch (i) { | |
67 case 0: | |
68 label_string = l10n_util::GetStringUTF16( | |
69 IDS_RESET_PROFILE_EXTENSIONS_DISABLE); | |
70 break; | |
71 case 1: | |
72 label_string = l10n_util::GetStringUTF16( | |
73 IDS_RESET_PROFILE_EXTENSIONS_UNINSTALL); | |
74 break; | |
75 } | |
76 ListValue* option = new ListValue(); | |
Dan Beam
2013/05/23 19:46:43
same
battre
2013/05/24 09:15:46
Done.
| |
77 option->Append(new base::FundamentalValue(i)); | |
78 option->Append(new base::StringValue(label_string)); | |
79 reset_extensions_handling->Append(option); | |
80 } | |
81 localized_strings->Set("resetExtensionsHandling", reset_extensions_handling); | |
82 } | |
83 | |
84 void ResetProfileSettingsHandler::RegisterMessages() { | |
85 // Setup handlers specific to this panel. | |
86 web_ui()->RegisterMessageCallback("performResetProfileSettings", | |
87 base::Bind(&ResetProfileSettingsHandler::HandleResetProfileSettings, | |
88 base::Unretained(this))); | |
89 } | |
90 | |
91 void ResetProfileSettingsHandler::HandleResetProfileSettings( | |
92 const ListValue* /*value*/) { | |
Dan Beam
2013/05/23 19:46:43
why commented?
battre
2013/05/24 09:15:46
http://google-styleguide.googlecode.com/svn/trunk/
Dan Beam
2013/05/24 19:13:03
"The more you know..."
| |
93 DCHECK(resetter_); | |
94 DCHECK(!resetter_->IsActive()); | |
95 | |
96 Profile* profile = Profile::FromWebUI(web_ui()); | |
97 PrefService* prefs = profile->GetPrefs(); | |
98 | |
99 ProfileResetter::ResettableFlags reset_mask = 0; | |
100 | |
101 struct { | |
102 const char* flag_name; | |
103 ProfileResetter::Resettable mask; | |
104 } name_to_flag[] = { | |
105 {prefs::kResetDefaultSearchEngine, ProfileResetter::DEFAULT_SEARCH_ENGINE}, | |
Dan Beam
2013/05/23 19:46:43
nit: { prefs:: ... ENGINE } (spaces before or afte
battre
2013/05/24 09:15:46
Done.
| |
106 {prefs::kResetHomepage, ProfileResetter::HOMEPAGE}, | |
107 {prefs::kResetContentSettings, ProfileResetter::CONTENT_SETTINGS}, | |
108 {prefs::kResetCookiesAndSiteData, ProfileResetter::COOKIES_AND_SITE_DATA}, | |
109 {prefs::kResetExtensions, ProfileResetter::EXTENSIONS}, | |
110 }; | |
111 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(name_to_flag); ++i) { | |
112 if (prefs->GetBoolean(name_to_flag[i].flag_name)) | |
113 reset_mask |= name_to_flag[i].mask; | |
114 } | |
115 | |
116 ProfileResetter::ExtensionHandling extension_handling = | |
117 (prefs->GetInteger(prefs::kResetExtensionsHandling) == 0) | |
Dan Beam
2013/05/23 19:46:43
nit: drop ()
battre
2013/05/24 09:15:46
I think this is a case of "Feel free to insert ext
| |
118 ? ProfileResetter::DISABLE_EXTENSIONS | |
119 : ProfileResetter::UNINSTALL_EXTENSIONS; | |
120 | |
121 resetter_->Reset( | |
122 reset_mask, | |
123 extension_handling, | |
124 base::Bind(&ResetProfileSettingsHandler::OnResetProfileSettingsDone, | |
125 AsWeakPtr())); | |
126 } | |
127 | |
128 void ResetProfileSettingsHandler::OnResetProfileSettingsDone() { | |
129 web_ui()->CallJavascriptFunction("ResetProfileSettingsOverlay.doneResetting"); | |
130 } | |
131 | |
132 } // namespace options | |
OLD | NEW |