OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/profile_resetter/resettable_settings_snapshot.h" | 5 #include "chrome/browser/profile_resetter/resettable_settings_snapshot.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 | 31 |
32 // Feedback bucket label. | 32 // Feedback bucket label. |
33 const char kProfileResetWebUIBucket[] = "ProfileResetReport"; | 33 const char kProfileResetWebUIBucket[] = "ProfileResetReport"; |
34 | 34 |
35 // Dictionary keys for feedback report. | 35 // Dictionary keys for feedback report. |
36 const char kDefaultSearchEnginePath[] = "default_search_engine"; | 36 const char kDefaultSearchEnginePath[] = "default_search_engine"; |
37 const char kEnabledExtensions[] = "enabled_extensions"; | 37 const char kEnabledExtensions[] = "enabled_extensions"; |
38 const char kHomepageIsNewTabPage[] = "homepage_is_ntp"; | 38 const char kHomepageIsNewTabPage[] = "homepage_is_ntp"; |
39 const char kHomepagePath[] = "homepage"; | 39 const char kHomepagePath[] = "homepage"; |
40 const char kShortcuts[] = "shortcuts"; | 40 const char kShortcuts[] = "shortcuts"; |
| 41 const char kShowHomeButton[] = "show_home_button"; |
41 const char kStartupTypePath[] = "startup_type"; | 42 const char kStartupTypePath[] = "startup_type"; |
42 const char kStartupURLPath[] = "startup_urls"; | 43 const char kStartupURLPath[] = "startup_urls"; |
43 | 44 |
44 template <class StringType> | 45 template <class StringType> |
45 void AddPair(base::ListValue* list, | 46 void AddPair(base::ListValue* list, |
46 const base::string16& key, | 47 const base::string16& key, |
47 const StringType& value) { | 48 const StringType& value) { |
48 base::DictionaryValue* results = new base::DictionaryValue(); | 49 base::DictionaryValue* results = new base::DictionaryValue(); |
49 results->SetString("key", key); | 50 results->SetString("key", key); |
50 results->SetString("value", value); | 51 results->SetString("value", value); |
51 list->Append(results); | 52 list->Append(results); |
52 } | 53 } |
53 | 54 |
54 } // namespace | 55 } // namespace |
55 | 56 |
56 ResettableSettingsSnapshot::ResettableSettingsSnapshot( | 57 ResettableSettingsSnapshot::ResettableSettingsSnapshot( |
57 Profile* profile) | 58 Profile* profile) |
58 : startup_(SessionStartupPref::GetStartupPref(profile)), | 59 : startup_(SessionStartupPref::GetStartupPref(profile)), |
59 shortcuts_determined_(false), | 60 shortcuts_determined_(false), |
60 weak_ptr_factory_(this) { | 61 weak_ptr_factory_(this) { |
61 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 62 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
62 // URLs are always stored sorted. | 63 // URLs are always stored sorted. |
63 std::sort(startup_.urls.begin(), startup_.urls.end()); | 64 std::sort(startup_.urls.begin(), startup_.urls.end()); |
64 | 65 |
65 PrefService* prefs = profile->GetPrefs(); | 66 PrefService* prefs = profile->GetPrefs(); |
66 DCHECK(prefs); | 67 DCHECK(prefs); |
67 homepage_ = prefs->GetString(prefs::kHomePage); | 68 homepage_ = prefs->GetString(prefs::kHomePage); |
68 homepage_is_ntp_ = prefs->GetBoolean(prefs::kHomePageIsNewTabPage); | 69 homepage_is_ntp_ = prefs->GetBoolean(prefs::kHomePageIsNewTabPage); |
| 70 show_home_button_ = prefs->GetBoolean(prefs::kShowHomeButton); |
69 | 71 |
70 TemplateURLService* service = | 72 TemplateURLService* service = |
71 TemplateURLServiceFactory::GetForProfile(profile); | 73 TemplateURLServiceFactory::GetForProfile(profile); |
72 DCHECK(service); | 74 DCHECK(service); |
73 TemplateURL* dse = service->GetDefaultSearchProvider(); | 75 TemplateURL* dse = service->GetDefaultSearchProvider(); |
74 if (dse) | 76 if (dse) |
75 dse_url_ = dse->url(); | 77 dse_url_ = dse->url(); |
76 | 78 |
77 const extensions::ExtensionSet& enabled_ext = | 79 const extensions::ExtensionSet& enabled_ext = |
78 extensions::ExtensionRegistry::Get(profile)->enabled_extensions(); | 80 extensions::ExtensionRegistry::Get(profile)->enabled_extensions(); |
(...skipping 24 matching lines...) Expand all Loading... |
103 int ResettableSettingsSnapshot::FindDifferentFields( | 105 int ResettableSettingsSnapshot::FindDifferentFields( |
104 const ResettableSettingsSnapshot& snapshot) const { | 106 const ResettableSettingsSnapshot& snapshot) const { |
105 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 107 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
106 int bit_mask = 0; | 108 int bit_mask = 0; |
107 | 109 |
108 if (startup_.type != snapshot.startup_.type || | 110 if (startup_.type != snapshot.startup_.type || |
109 startup_.urls != snapshot.startup_.urls) | 111 startup_.urls != snapshot.startup_.urls) |
110 bit_mask |= STARTUP_MODE; | 112 bit_mask |= STARTUP_MODE; |
111 | 113 |
112 if (homepage_is_ntp_ != snapshot.homepage_is_ntp_ || | 114 if (homepage_is_ntp_ != snapshot.homepage_is_ntp_ || |
113 homepage_ != snapshot.homepage_) | 115 homepage_ != snapshot.homepage_ || |
| 116 show_home_button_ != snapshot.show_home_button_) |
114 bit_mask |= HOMEPAGE; | 117 bit_mask |= HOMEPAGE; |
115 | 118 |
116 if (dse_url_ != snapshot.dse_url_) | 119 if (dse_url_ != snapshot.dse_url_) |
117 bit_mask |= DSE_URL; | 120 bit_mask |= DSE_URL; |
118 | 121 |
119 if (enabled_extensions_ != snapshot.enabled_extensions_) | 122 if (enabled_extensions_ != snapshot.enabled_extensions_) |
120 bit_mask |= EXTENSIONS; | 123 bit_mask |= EXTENSIONS; |
121 | 124 |
122 if (shortcuts_ != snapshot.shortcuts_) | 125 if (shortcuts_ != snapshot.shortcuts_) |
123 bit_mask |= SHORTCUTS; | 126 bit_mask |= SHORTCUTS; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 for (std::vector<GURL>::const_iterator i = urls.begin(); | 169 for (std::vector<GURL>::const_iterator i = urls.begin(); |
167 i != urls.end(); ++i) | 170 i != urls.end(); ++i) |
168 list->AppendString(i->spec()); | 171 list->AppendString(i->spec()); |
169 dict.Set(kStartupURLPath, list); | 172 dict.Set(kStartupURLPath, list); |
170 dict.SetInteger(kStartupTypePath, snapshot.startup_type()); | 173 dict.SetInteger(kStartupTypePath, snapshot.startup_type()); |
171 } | 174 } |
172 | 175 |
173 if (field_mask & ResettableSettingsSnapshot::HOMEPAGE) { | 176 if (field_mask & ResettableSettingsSnapshot::HOMEPAGE) { |
174 dict.SetString(kHomepagePath, snapshot.homepage()); | 177 dict.SetString(kHomepagePath, snapshot.homepage()); |
175 dict.SetBoolean(kHomepageIsNewTabPage, snapshot.homepage_is_ntp()); | 178 dict.SetBoolean(kHomepageIsNewTabPage, snapshot.homepage_is_ntp()); |
| 179 dict.SetBoolean(kShowHomeButton, snapshot.show_home_button()); |
176 } | 180 } |
177 | 181 |
178 if (field_mask & ResettableSettingsSnapshot::DSE_URL) | 182 if (field_mask & ResettableSettingsSnapshot::DSE_URL) |
179 dict.SetString(kDefaultSearchEnginePath, snapshot.dse_url()); | 183 dict.SetString(kDefaultSearchEnginePath, snapshot.dse_url()); |
180 | 184 |
181 if (field_mask & ResettableSettingsSnapshot::EXTENSIONS) { | 185 if (field_mask & ResettableSettingsSnapshot::EXTENSIONS) { |
182 base::ListValue* list = new base::ListValue; | 186 base::ListValue* list = new base::ListValue; |
183 const ResettableSettingsSnapshot::ExtensionList& extensions = | 187 const ResettableSettingsSnapshot::ExtensionList& extensions = |
184 snapshot.enabled_extensions(); | 188 snapshot.enabled_extensions(); |
185 for (ResettableSettingsSnapshot::ExtensionList::const_iterator i = | 189 for (ResettableSettingsSnapshot::ExtensionList::const_iterator i = |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 snapshot.homepage()); | 292 snapshot.homepage()); |
289 } | 293 } |
290 | 294 |
291 int is_ntp_message_id = snapshot.homepage_is_ntp() ? | 295 int is_ntp_message_id = snapshot.homepage_is_ntp() ? |
292 IDS_RESET_PROFILE_SETTINGS_HOMEPAGE_IS_NTP_TRUE : | 296 IDS_RESET_PROFILE_SETTINGS_HOMEPAGE_IS_NTP_TRUE : |
293 IDS_RESET_PROFILE_SETTINGS_HOMEPAGE_IS_NTP_FALSE; | 297 IDS_RESET_PROFILE_SETTINGS_HOMEPAGE_IS_NTP_FALSE; |
294 AddPair(list.get(), | 298 AddPair(list.get(), |
295 l10n_util::GetStringUTF16(IDS_RESET_PROFILE_SETTINGS_HOMEPAGE_IS_NTP), | 299 l10n_util::GetStringUTF16(IDS_RESET_PROFILE_SETTINGS_HOMEPAGE_IS_NTP), |
296 l10n_util::GetStringUTF16(is_ntp_message_id)); | 300 l10n_util::GetStringUTF16(is_ntp_message_id)); |
297 | 301 |
| 302 int show_home_button_id = snapshot.show_home_button() ? |
| 303 IDS_RESET_PROFILE_SETTINGS_SHOW_HOME_BUTTON_TRUE : |
| 304 IDS_RESET_PROFILE_SETTINGS_SHOW_HOME_BUTTON_FALSE; |
| 305 AddPair( |
| 306 list.get(), |
| 307 l10n_util::GetStringUTF16(IDS_RESET_PROFILE_SETTINGS_SHOW_HOME_BUTTON), |
| 308 l10n_util::GetStringUTF16(show_home_button_id)); |
| 309 |
298 TemplateURLService* service = | 310 TemplateURLService* service = |
299 TemplateURLServiceFactory::GetForProfile(profile); | 311 TemplateURLServiceFactory::GetForProfile(profile); |
300 DCHECK(service); | 312 DCHECK(service); |
301 TemplateURL* dse = service->GetDefaultSearchProvider(); | 313 TemplateURL* dse = service->GetDefaultSearchProvider(); |
302 if (dse) { | 314 if (dse) { |
303 AddPair(list.get(), | 315 AddPair(list.get(), |
304 l10n_util::GetStringUTF16(IDS_RESET_PROFILE_SETTINGS_DSE), | 316 l10n_util::GetStringUTF16(IDS_RESET_PROFILE_SETTINGS_DSE), |
305 dse->GenerateSearchURL(service->search_terms_data()).host()); | 317 dse->GenerateSearchURL(service->search_terms_data()).host()); |
306 } | 318 } |
307 | 319 |
(...skipping 28 matching lines...) Expand all Loading... |
336 extension_names += '\n'; | 348 extension_names += '\n'; |
337 extension_names += i->second; | 349 extension_names += i->second; |
338 } | 350 } |
339 if (!extension_names.empty()) { | 351 if (!extension_names.empty()) { |
340 AddPair(list.get(), | 352 AddPair(list.get(), |
341 l10n_util::GetStringUTF16(IDS_RESET_PROFILE_SETTINGS_EXTENSIONS), | 353 l10n_util::GetStringUTF16(IDS_RESET_PROFILE_SETTINGS_EXTENSIONS), |
342 extension_names); | 354 extension_names); |
343 } | 355 } |
344 return list.Pass(); | 356 return list.Pass(); |
345 } | 357 } |
OLD | NEW |