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

Side by Side Diff: chrome/browser/profile_resetter/resettable_settings_snapshot.cc

Issue 23450021: Profile Reset dialog: the new section with detailed feedback information (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed compilation Created 7 years, 3 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) 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/utf_string_conversions.h"
10 #include "base/values.h"
11 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/extensions/extension_service.h" 12 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/feedback/feedback_data.h" 13 #include "chrome/browser/feedback/feedback_data.h"
11 #include "chrome/browser/feedback/feedback_util.h" 14 #include "chrome/browser/feedback/feedback_util.h"
12 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/search_engines/template_url_service.h" 16 #include "chrome/browser/search_engines/template_url_service.h"
14 #include "chrome/browser/search_engines/template_url_service_factory.h" 17 #include "chrome/browser/search_engines/template_url_service_factory.h"
18 #include "chrome/common/chrome_version_info.h"
15 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
20 #include "grit/generated_resources.h"
21 #include "grit/google_chrome_strings.h"
22 #include "ui/base/l10n/l10n_util.h"
16 23
17 namespace { 24 namespace {
18 25
19 // Feedback bucket label. 26 // Feedback bucket label.
20 const char kProfileResetFeedbackBucket[] = "ProfileResetReport"; 27 const char kProfileResetFeedbackBucket[] = "ProfileResetReport";
21 28
22 // Dictionary keys for feedback report. 29 // Dictionary keys for feedback report.
23 const char kDefaultSearchEnginePath[] = "default_search_engine"; 30 const char kDefaultSearchEnginePath[] = "default_search_engine";
24 const char kEnabledExtensions[] = "enabled_extensions"; 31 const char kEnabledExtensions[] = "enabled_extensions";
25 const char kHomepageIsNewTabPage[] = "homepage_is_ntp"; 32 const char kHomepageIsNewTabPage[] = "homepage_is_ntp";
26 const char kHomepagePath[] = "homepage"; 33 const char kHomepagePath[] = "homepage";
27 const char kStartupTypePath[] = "startup_type"; 34 const char kStartupTypePath[] = "startup_type";
28 const char kStartupURLPath[] = "startup_urls"; 35 const char kStartupURLPath[] = "startup_urls";
29 36
37 void AddPair(ListValue* list, const string16& key, const string16& value) {
38 DictionaryValue* results = new DictionaryValue();
39 results->SetString("key", key);
40 results->SetString("value", value);
41 list->Append(results);
42 }
43
30 } // namespace 44 } // namespace
31 45
32 ResettableSettingsSnapshot::ResettableSettingsSnapshot(Profile* profile) 46 ResettableSettingsSnapshot::ResettableSettingsSnapshot(Profile* profile)
33 : startup_(SessionStartupPref::GetStartupPref(profile)) { 47 : startup_(SessionStartupPref::GetStartupPref(profile)) {
34 // URLs are always stored sorted. 48 // URLs are always stored sorted.
35 std::sort(startup_.urls.begin(), startup_.urls.end()); 49 std::sort(startup_.urls.begin(), startup_.urls.end());
36 50
37 PrefService* prefs = profile->GetPrefs(); 51 PrefService* prefs = profile->GetPrefs();
38 DCHECK(prefs); 52 DCHECK(prefs);
39 homepage_ = prefs->GetString(prefs::kHomePage); 53 homepage_ = prefs->GetString(prefs::kHomePage);
40 homepage_is_ntp_ = prefs->GetBoolean(prefs::kHomePageIsNewTabPage); 54 homepage_is_ntp_ = prefs->GetBoolean(prefs::kHomePageIsNewTabPage);
41 55
42 TemplateURLService* service = 56 TemplateURLService* service =
43 TemplateURLServiceFactory::GetForProfile(profile); 57 TemplateURLServiceFactory::GetForProfile(profile);
44 DCHECK(service); 58 DCHECK(service);
45 TemplateURL* dse = service->GetDefaultSearchProvider(); 59 TemplateURL* dse = service->GetDefaultSearchProvider();
46 if (dse) 60 if (dse)
47 dse_url_ = dse->url(); 61 dse_url_ = dse->url();
48 62
49 ExtensionService* extension_service = profile->GetExtensionService(); 63 ExtensionService* extension_service = profile->GetExtensionService();
50 DCHECK(extension_service); 64 DCHECK(extension_service);
51 const ExtensionSet* enabled_ext = extension_service->extensions(); 65 const ExtensionSet* enabled_ext = extension_service->extensions();
52 enabled_extensions_.reserve(enabled_ext->size()); 66 enabled_extensions_.reserve(enabled_ext->size());
53 67
54 for (ExtensionSet::const_iterator it = enabled_ext->begin(); 68 for (ExtensionSet::const_iterator it = enabled_ext->begin();
55 it != enabled_ext->end(); ++it) 69 it != enabled_ext->end(); ++it)
56 enabled_extensions_.push_back((*it)->id()); 70 enabled_extensions_.push_back(std::make_pair((*it)->id(), (*it)->name()));
57 71
58 // ExtensionSet is sorted but it seems to be an implementation detail. 72 // ExtensionSet is sorted but it seems to be an implementation detail.
59 std::sort(enabled_extensions_.begin(), enabled_extensions_.end()); 73 std::sort(enabled_extensions_.begin(), enabled_extensions_.end());
60 } 74 }
61 75
62 ResettableSettingsSnapshot::~ResettableSettingsSnapshot() {} 76 ResettableSettingsSnapshot::~ResettableSettingsSnapshot() {}
63 77
64 void ResettableSettingsSnapshot::Subtract( 78 void ResettableSettingsSnapshot::Subtract(
65 const ResettableSettingsSnapshot& snapshot) { 79 const ResettableSettingsSnapshot& snapshot) {
66 std::vector<GURL> urls; 80 std::vector<GURL> urls;
67 std::set_difference(startup_.urls.begin(), startup_.urls.end(), 81 std::set_difference(startup_.urls.begin(), startup_.urls.end(),
68 snapshot.startup_.urls.begin(), 82 snapshot.startup_.urls.begin(),
69 snapshot.startup_.urls.end(), 83 snapshot.startup_.urls.end(),
70 std::back_inserter(urls)); 84 std::back_inserter(urls));
71 startup_.urls.swap(urls); 85 startup_.urls.swap(urls);
72 86
73 std::vector<std::string> extensions; 87 ExtensionList extensions;
74 std::set_difference(enabled_extensions_.begin(), enabled_extensions_.end(), 88 std::set_difference(enabled_extensions_.begin(), enabled_extensions_.end(),
75 snapshot.enabled_extensions_.begin(), 89 snapshot.enabled_extensions_.begin(),
76 snapshot.enabled_extensions_.end(), 90 snapshot.enabled_extensions_.end(),
77 std::back_inserter(extensions)); 91 std::back_inserter(extensions));
78 enabled_extensions_.swap(extensions); 92 enabled_extensions_.swap(extensions);
79 } 93 }
80 94
81 int ResettableSettingsSnapshot::FindDifferentFields( 95 int ResettableSettingsSnapshot::FindDifferentFields(
82 const ResettableSettingsSnapshot& snapshot) const { 96 const ResettableSettingsSnapshot& snapshot) const {
83 int bit_mask = 0; 97 int bit_mask = 0;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 dict.SetString(kHomepagePath, snapshot.homepage()); 141 dict.SetString(kHomepagePath, snapshot.homepage());
128 142
129 if (field_mask & ResettableSettingsSnapshot::HOMEPAGE_IS_NTP) 143 if (field_mask & ResettableSettingsSnapshot::HOMEPAGE_IS_NTP)
130 dict.SetBoolean(kHomepageIsNewTabPage, snapshot.homepage_is_ntp()); 144 dict.SetBoolean(kHomepageIsNewTabPage, snapshot.homepage_is_ntp());
131 145
132 if (field_mask & ResettableSettingsSnapshot::DSE_URL) 146 if (field_mask & ResettableSettingsSnapshot::DSE_URL)
133 dict.SetString(kDefaultSearchEnginePath, snapshot.dse_url()); 147 dict.SetString(kDefaultSearchEnginePath, snapshot.dse_url());
134 148
135 if (field_mask & ResettableSettingsSnapshot::EXTENSIONS) { 149 if (field_mask & ResettableSettingsSnapshot::EXTENSIONS) {
136 ListValue* list = new ListValue; 150 ListValue* list = new ListValue;
137 const std::vector<std::string>& extensions = snapshot.enabled_extensions(); 151 const ResettableSettingsSnapshot::ExtensionList& extensions =
138 for (std::vector<std::string>::const_iterator i = extensions.begin(); 152 snapshot.enabled_extensions();
139 i != extensions.end(); ++i) 153 for (ResettableSettingsSnapshot::ExtensionList::const_iterator i =
140 list->AppendString(*i); 154 extensions.begin(); i != extensions.end(); ++i)
155 list->AppendString(i->first + ";" + i->second);
battre 2013/09/13 08:59:02 One more request: Can you strip quotes (") from i-
vasilii 2013/09/16 13:58:02 Done.
141 dict.Set(kEnabledExtensions, list); 156 dict.Set(kEnabledExtensions, list);
142 } 157 }
143 158
144 COMPILE_ASSERT(ResettableSettingsSnapshot::ALL_FIELDS == 63, 159 COMPILE_ASSERT(ResettableSettingsSnapshot::ALL_FIELDS == 63,
145 serialize_new_field_here); 160 serialize_new_field_here);
146 161
147 std::string json; 162 std::string json;
148 base::JSONWriter::Write(&dict, &json); 163 base::JSONWriter::Write(&dict, &json);
149 return json; 164 return json;
150 } 165 }
151 166
152 void SendSettingsFeedback(const std::string& report, Profile* profile) { 167 void SendSettingsFeedback(const std::string& report, Profile* profile) {
153 scoped_refptr<FeedbackData> feedback_data = new FeedbackData(); 168 scoped_refptr<FeedbackData> feedback_data = new FeedbackData();
154 feedback_data->set_category_tag(kProfileResetFeedbackBucket); 169 feedback_data->set_category_tag(kProfileResetFeedbackBucket);
155 feedback_data->set_description(report); 170 feedback_data->set_description(report);
156 171
157 feedback_data->set_image(scoped_ptr<std::string>(new std::string)); 172 feedback_data->set_image(scoped_ptr<std::string>(new std::string));
158 feedback_data->set_profile(profile); 173 feedback_data->set_profile(profile);
159 174
160 feedback_data->set_page_url(""); 175 feedback_data->set_page_url("");
161 feedback_data->set_user_email(""); 176 feedback_data->set_user_email("");
162 177
163 feedback_util::SendReport(feedback_data); 178 feedback_util::SendReport(feedback_data);
164 } 179 }
180
181 ListValue* GetReadableFeedback(Profile* profile) {
182 DCHECK(profile);
183 ListValue* list = new ListValue;
184 AddPair(list, l10n_util::GetStringUTF16(IDS_RESET_PROFILE_SETTINGS_LOCALE),
185 ASCIIToUTF16(g_browser_process->GetApplicationLocale()));
186 AddPair(list,
187 l10n_util::GetStringUTF16(IDS_RESET_PROFILE_SETTINGS_USER_AGENT),
188 ASCIIToUTF16(content::GetUserAgent(GURL())));
189 chrome::VersionInfo version_info;
190 std::string version = version_info.Version();
191 version += chrome::VersionInfo::GetVersionStringModifier();
192 AddPair(list,
193 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME),
194 ASCIIToUTF16(version));
195
196 // Add snapshot data.
197 ResettableSettingsSnapshot snapshot(profile);
198 const std::vector<GURL>& urls = snapshot.startup_urls();
199 std::string startup_urls;
200 for (std::vector<GURL>::const_iterator i = urls.begin();
201 i != urls.end(); ++i) {
202 (startup_urls += i->host()) += ' ';
203 }
204 if (!startup_urls.empty()) {
205 AddPair(list,
206 l10n_util::GetStringUTF16(IDS_RESET_PROFILE_SETTINGS_STARTUP_URLS),
207 ASCIIToUTF16(startup_urls));
208 }
209
210 string16 startup_type;
211 switch (snapshot.startup_type()) {
212 case SessionStartupPref::DEFAULT:
213 startup_type = l10n_util::GetStringUTF16(IDS_OPTIONS_STARTUP_SHOW_NEWTAB);
214 break;
215 case SessionStartupPref::LAST:
216 startup_type = l10n_util::GetStringUTF16(
217 IDS_OPTIONS_STARTUP_RESTORE_LAST_SESSION);
218 break;
219 case SessionStartupPref::URLS:
220 startup_type = l10n_util::GetStringUTF16(IDS_OPTIONS_STARTUP_SHOW_PAGES);
221 break;
222 default:
223 break;
224 }
225 AddPair(list,
226 l10n_util::GetStringUTF16(IDS_RESET_PROFILE_SETTINGS_STARTUP_TYPE),
227 startup_type);
228
229 if (!snapshot.homepage().empty()) {
230 AddPair(list,
231 l10n_util::GetStringUTF16(IDS_RESET_PROFILE_SETTINGS_HOMEPAGE),
232 ASCIIToUTF16(snapshot.homepage()));
233 }
234
235 int is_ntp_message_id = snapshot.homepage_is_ntp() ?
236 IDS_RESET_PROFILE_SETTINGS_HOMEPAGE_IS_NTP_TRUE :
237 IDS_RESET_PROFILE_SETTINGS_HOMEPAGE_IS_NTP_FALSE;
238 AddPair(list,
239 l10n_util::GetStringUTF16(IDS_RESET_PROFILE_SETTINGS_HOMEPAGE_IS_NTP),
240 l10n_util::GetStringUTF16(is_ntp_message_id));
241
242 TemplateURLService* service =
243 TemplateURLServiceFactory::GetForProfile(profile);
244 DCHECK(service);
245 TemplateURL* dse = service->GetDefaultSearchProvider();
246 if (dse) {
247 AddPair(list,
248 l10n_util::GetStringUTF16(IDS_RESET_PROFILE_SETTINGS_DSE),
249 ASCIIToUTF16(TemplateURLService::GenerateSearchURL(dse).host()));
250 }
251
252 const ResettableSettingsSnapshot::ExtensionList& extensions =
253 snapshot.enabled_extensions();
254 std::string extension_ids;
255 for (ResettableSettingsSnapshot::ExtensionList::const_iterator i =
256 extensions.begin(); i != extensions.end(); ++i) {
257 (extension_ids += i->second) += '\n';
258 }
259 if (!extension_ids.empty()) {
260 extension_ids.erase(extension_ids.end() - 1);
battre 2013/09/12 14:03:14 do you want to do that for startup_urls as well?
vasilii 2013/09/16 13:58:02 Done.
261 AddPair(list,
262 l10n_util::GetStringUTF16(IDS_RESET_PROFILE_SETTINGS_EXTENSIONS),
263 ASCIIToUTF16(extension_ids));
264 }
265 return list;
266 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698