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

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: New icon 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 std::string ext = i->first + ";";
156 // Replace "\"" to simplify server-side analysis.
157 std::replace_copy(i->second.begin(), i->second.end(),
158 std::back_inserter(ext), '\"', '\'');
battre 2013/09/16 14:25:44 I would prefer this: std::string& ext_id = i->firs
vasilii 2013/09/16 14:38:02 Done.
159 list->AppendString(ext);
160 }
141 dict.Set(kEnabledExtensions, list); 161 dict.Set(kEnabledExtensions, list);
142 } 162 }
143 163
144 COMPILE_ASSERT(ResettableSettingsSnapshot::ALL_FIELDS == 63, 164 COMPILE_ASSERT(ResettableSettingsSnapshot::ALL_FIELDS == 63,
145 serialize_new_field_here); 165 serialize_new_field_here);
146 166
147 std::string json; 167 std::string json;
148 base::JSONWriter::Write(&dict, &json); 168 base::JSONWriter::Write(&dict, &json);
149 return json; 169 return json;
150 } 170 }
151 171
152 void SendSettingsFeedback(const std::string& report, Profile* profile) { 172 void SendSettingsFeedback(const std::string& report, Profile* profile) {
153 scoped_refptr<FeedbackData> feedback_data = new FeedbackData(); 173 scoped_refptr<FeedbackData> feedback_data = new FeedbackData();
154 feedback_data->set_category_tag(kProfileResetFeedbackBucket); 174 feedback_data->set_category_tag(kProfileResetFeedbackBucket);
155 feedback_data->set_description(report); 175 feedback_data->set_description(report);
156 176
157 feedback_data->set_image(scoped_ptr<std::string>(new std::string)); 177 feedback_data->set_image(scoped_ptr<std::string>(new std::string));
158 feedback_data->set_profile(profile); 178 feedback_data->set_profile(profile);
159 179
160 feedback_data->set_page_url(""); 180 feedback_data->set_page_url("");
161 feedback_data->set_user_email(""); 181 feedback_data->set_user_email("");
162 182
163 feedback_util::SendReport(feedback_data); 183 feedback_util::SendReport(feedback_data);
164 } 184 }
185
186 ListValue* GetReadableFeedback(Profile* profile) {
187 DCHECK(profile);
188 ListValue* list = new ListValue;
189 AddPair(list, l10n_util::GetStringUTF16(IDS_RESET_PROFILE_SETTINGS_LOCALE),
190 ASCIIToUTF16(g_browser_process->GetApplicationLocale()));
191 AddPair(list,
192 l10n_util::GetStringUTF16(IDS_RESET_PROFILE_SETTINGS_USER_AGENT),
193 ASCIIToUTF16(content::GetUserAgent(GURL())));
194 chrome::VersionInfo version_info;
195 std::string version = version_info.Version();
196 version += chrome::VersionInfo::GetVersionStringModifier();
197 AddPair(list,
198 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME),
199 ASCIIToUTF16(version));
200
201 // Add snapshot data.
202 ResettableSettingsSnapshot snapshot(profile);
203 const std::vector<GURL>& urls = snapshot.startup_urls();
204 std::string startup_urls;
205 for (std::vector<GURL>::const_iterator i = urls.begin();
206 i != urls.end(); ++i) {
207 (startup_urls += i->host()) += ' ';
208 }
209 if (!startup_urls.empty()) {
210 startup_urls.erase(startup_urls.end() - 1);
211 AddPair(list,
212 l10n_util::GetStringUTF16(IDS_RESET_PROFILE_SETTINGS_STARTUP_URLS),
213 ASCIIToUTF16(startup_urls));
214 }
215
216 string16 startup_type;
217 switch (snapshot.startup_type()) {
218 case SessionStartupPref::DEFAULT:
219 startup_type = l10n_util::GetStringUTF16(IDS_OPTIONS_STARTUP_SHOW_NEWTAB);
220 break;
221 case SessionStartupPref::LAST:
222 startup_type = l10n_util::GetStringUTF16(
223 IDS_OPTIONS_STARTUP_RESTORE_LAST_SESSION);
224 break;
225 case SessionStartupPref::URLS:
226 startup_type = l10n_util::GetStringUTF16(IDS_OPTIONS_STARTUP_SHOW_PAGES);
227 break;
228 default:
229 break;
230 }
231 AddPair(list,
232 l10n_util::GetStringUTF16(IDS_RESET_PROFILE_SETTINGS_STARTUP_TYPE),
233 startup_type);
234
235 if (!snapshot.homepage().empty()) {
236 AddPair(list,
237 l10n_util::GetStringUTF16(IDS_RESET_PROFILE_SETTINGS_HOMEPAGE),
238 ASCIIToUTF16(snapshot.homepage()));
239 }
240
241 int is_ntp_message_id = snapshot.homepage_is_ntp() ?
242 IDS_RESET_PROFILE_SETTINGS_HOMEPAGE_IS_NTP_TRUE :
243 IDS_RESET_PROFILE_SETTINGS_HOMEPAGE_IS_NTP_FALSE;
244 AddPair(list,
245 l10n_util::GetStringUTF16(IDS_RESET_PROFILE_SETTINGS_HOMEPAGE_IS_NTP),
246 l10n_util::GetStringUTF16(is_ntp_message_id));
247
248 TemplateURLService* service =
249 TemplateURLServiceFactory::GetForProfile(profile);
250 DCHECK(service);
251 TemplateURL* dse = service->GetDefaultSearchProvider();
252 if (dse) {
253 AddPair(list,
254 l10n_util::GetStringUTF16(IDS_RESET_PROFILE_SETTINGS_DSE),
255 ASCIIToUTF16(TemplateURLService::GenerateSearchURL(dse).host()));
256 }
257
258 const ResettableSettingsSnapshot::ExtensionList& extensions =
259 snapshot.enabled_extensions();
260 std::string extension_ids;
261 for (ResettableSettingsSnapshot::ExtensionList::const_iterator i =
262 extensions.begin(); i != extensions.end(); ++i) {
263 (extension_ids += i->second) += '\n';
264 }
265 if (!extension_ids.empty()) {
266 extension_ids.erase(extension_ids.end() - 1);
267 AddPair(list,
268 l10n_util::GetStringUTF16(IDS_RESET_PROFILE_SETTINGS_EXTENSIONS),
269 ASCIIToUTF16(extension_ids));
270 }
271 return list;
272 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698