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

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

Issue 1107863002: [chrome/browser/profile_resetter] favor DCHECK_CURRENTLY_ON for better logs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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
« no previous file with comments | « chrome/browser/profile_resetter/profile_resetter_browsertest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 list->Append(results); 53 list->Append(results);
54 } 54 }
55 55
56 } // namespace 56 } // namespace
57 57
58 ResettableSettingsSnapshot::ResettableSettingsSnapshot( 58 ResettableSettingsSnapshot::ResettableSettingsSnapshot(
59 Profile* profile) 59 Profile* profile)
60 : startup_(SessionStartupPref::GetStartupPref(profile)), 60 : startup_(SessionStartupPref::GetStartupPref(profile)),
61 shortcuts_determined_(false), 61 shortcuts_determined_(false),
62 weak_ptr_factory_(this) { 62 weak_ptr_factory_(this) {
63 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 63 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
64 // URLs are always stored sorted. 64 // URLs are always stored sorted.
65 std::sort(startup_.urls.begin(), startup_.urls.end()); 65 std::sort(startup_.urls.begin(), startup_.urls.end());
66 66
67 PrefService* prefs = profile->GetPrefs(); 67 PrefService* prefs = profile->GetPrefs();
68 DCHECK(prefs); 68 DCHECK(prefs);
69 homepage_ = prefs->GetString(prefs::kHomePage); 69 homepage_ = prefs->GetString(prefs::kHomePage);
70 homepage_is_ntp_ = prefs->GetBoolean(prefs::kHomePageIsNewTabPage); 70 homepage_is_ntp_ = prefs->GetBoolean(prefs::kHomePageIsNewTabPage);
71 show_home_button_ = prefs->GetBoolean(prefs::kShowHomeButton); 71 show_home_button_ = prefs->GetBoolean(prefs::kShowHomeButton);
72 72
73 TemplateURLService* service = 73 TemplateURLService* service =
74 TemplateURLServiceFactory::GetForProfile(profile); 74 TemplateURLServiceFactory::GetForProfile(profile);
75 DCHECK(service); 75 DCHECK(service);
76 TemplateURL* dse = service->GetDefaultSearchProvider(); 76 TemplateURL* dse = service->GetDefaultSearchProvider();
77 if (dse) 77 if (dse)
78 dse_url_ = dse->url(); 78 dse_url_ = dse->url();
79 79
80 const extensions::ExtensionSet& enabled_ext = 80 const extensions::ExtensionSet& enabled_ext =
81 extensions::ExtensionRegistry::Get(profile)->enabled_extensions(); 81 extensions::ExtensionRegistry::Get(profile)->enabled_extensions();
82 enabled_extensions_.reserve(enabled_ext.size()); 82 enabled_extensions_.reserve(enabled_ext.size());
83 83
84 for (extensions::ExtensionSet::const_iterator it = enabled_ext.begin(); 84 for (extensions::ExtensionSet::const_iterator it = enabled_ext.begin();
85 it != enabled_ext.end(); ++it) 85 it != enabled_ext.end(); ++it)
86 enabled_extensions_.push_back(std::make_pair((*it)->id(), (*it)->name())); 86 enabled_extensions_.push_back(std::make_pair((*it)->id(), (*it)->name()));
87 87
88 // ExtensionSet is sorted but it seems to be an implementation detail. 88 // ExtensionSet is sorted but it seems to be an implementation detail.
89 std::sort(enabled_extensions_.begin(), enabled_extensions_.end()); 89 std::sort(enabled_extensions_.begin(), enabled_extensions_.end());
90 } 90 }
91 91
92 ResettableSettingsSnapshot::~ResettableSettingsSnapshot() { 92 ResettableSettingsSnapshot::~ResettableSettingsSnapshot() {
93 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 93 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
94 if (cancellation_flag_.get()) 94 if (cancellation_flag_.get())
95 cancellation_flag_->data.Set(); 95 cancellation_flag_->data.Set();
96 } 96 }
97 97
98 void ResettableSettingsSnapshot::Subtract( 98 void ResettableSettingsSnapshot::Subtract(
99 const ResettableSettingsSnapshot& snapshot) { 99 const ResettableSettingsSnapshot& snapshot) {
100 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 100 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
101 ExtensionList extensions = base::STLSetDifference<ExtensionList>( 101 ExtensionList extensions = base::STLSetDifference<ExtensionList>(
102 enabled_extensions_, snapshot.enabled_extensions_); 102 enabled_extensions_, snapshot.enabled_extensions_);
103 enabled_extensions_.swap(extensions); 103 enabled_extensions_.swap(extensions);
104 } 104 }
105 105
106 int ResettableSettingsSnapshot::FindDifferentFields( 106 int ResettableSettingsSnapshot::FindDifferentFields(
107 const ResettableSettingsSnapshot& snapshot) const { 107 const ResettableSettingsSnapshot& snapshot) const {
108 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 108 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
109 int bit_mask = 0; 109 int bit_mask = 0;
110 110
111 if (startup_.type != snapshot.startup_.type || 111 if (startup_.type != snapshot.startup_.type ||
112 startup_.urls != snapshot.startup_.urls) 112 startup_.urls != snapshot.startup_.urls)
113 bit_mask |= STARTUP_MODE; 113 bit_mask |= STARTUP_MODE;
114 114
115 if (homepage_is_ntp_ != snapshot.homepage_is_ntp_ || 115 if (homepage_is_ntp_ != snapshot.homepage_is_ntp_ ||
116 homepage_ != snapshot.homepage_ || 116 homepage_ != snapshot.homepage_ ||
117 show_home_button_ != snapshot.show_home_button_) 117 show_home_button_ != snapshot.show_home_button_)
118 bit_mask |= HOMEPAGE; 118 bit_mask |= HOMEPAGE;
119 119
120 if (dse_url_ != snapshot.dse_url_) 120 if (dse_url_ != snapshot.dse_url_)
121 bit_mask |= DSE_URL; 121 bit_mask |= DSE_URL;
122 122
123 if (enabled_extensions_ != snapshot.enabled_extensions_) 123 if (enabled_extensions_ != snapshot.enabled_extensions_)
124 bit_mask |= EXTENSIONS; 124 bit_mask |= EXTENSIONS;
125 125
126 if (shortcuts_ != snapshot.shortcuts_) 126 if (shortcuts_ != snapshot.shortcuts_)
127 bit_mask |= SHORTCUTS; 127 bit_mask |= SHORTCUTS;
128 128
129 static_assert(ResettableSettingsSnapshot::ALL_FIELDS == 31, 129 static_assert(ResettableSettingsSnapshot::ALL_FIELDS == 31,
130 "new field needs to be added here"); 130 "new field needs to be added here");
131 131
132 return bit_mask; 132 return bit_mask;
133 } 133 }
134 134
135 void ResettableSettingsSnapshot::RequestShortcuts( 135 void ResettableSettingsSnapshot::RequestShortcuts(
136 const base::Closure& callback) { 136 const base::Closure& callback) {
137 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 137 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
138 DCHECK(!cancellation_flag_.get() && !shortcuts_determined()); 138 DCHECK(!cancellation_flag_.get() && !shortcuts_determined());
139 139
140 cancellation_flag_ = new SharedCancellationFlag; 140 cancellation_flag_ = new SharedCancellationFlag;
141 content::BrowserThread::PostTaskAndReplyWithResult( 141 content::BrowserThread::PostTaskAndReplyWithResult(
142 content::BrowserThread::FILE, 142 content::BrowserThread::FILE,
143 FROM_HERE, 143 FROM_HERE,
144 base::Bind(&GetChromeLaunchShortcuts, cancellation_flag_), 144 base::Bind(&GetChromeLaunchShortcuts, cancellation_flag_),
145 base::Bind(&ResettableSettingsSnapshot::SetShortcutsAndReport, 145 base::Bind(&ResettableSettingsSnapshot::SetShortcutsAndReport,
146 weak_ptr_factory_.GetWeakPtr(), 146 weak_ptr_factory_.GetWeakPtr(),
147 callback)); 147 callback));
148 } 148 }
149 149
150 void ResettableSettingsSnapshot::SetShortcutsAndReport( 150 void ResettableSettingsSnapshot::SetShortcutsAndReport(
151 const base::Closure& callback, 151 const base::Closure& callback,
152 const std::vector<ShortcutCommand>& shortcuts) { 152 const std::vector<ShortcutCommand>& shortcuts) {
153 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 153 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
154 shortcuts_ = shortcuts; 154 shortcuts_ = shortcuts;
155 shortcuts_determined_ = true; 155 shortcuts_determined_ = true;
156 cancellation_flag_ = NULL; 156 cancellation_flag_ = NULL;
157 157
158 if (!callback.is_null()) 158 if (!callback.is_null())
159 callback.Run(); 159 callback.Run();
160 } 160 }
161 161
162 std::string SerializeSettingsReport(const ResettableSettingsSnapshot& snapshot, 162 std::string SerializeSettingsReport(const ResettableSettingsSnapshot& snapshot,
163 int field_mask) { 163 int field_mask) {
164 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 164 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
165 base::DictionaryValue dict; 165 base::DictionaryValue dict;
166 166
167 if (field_mask & ResettableSettingsSnapshot::STARTUP_MODE) { 167 if (field_mask & ResettableSettingsSnapshot::STARTUP_MODE) {
168 base::ListValue* list = new base::ListValue; 168 base::ListValue* list = new base::ListValue;
169 const std::vector<GURL>& urls = snapshot.startup_urls(); 169 const std::vector<GURL>& urls = snapshot.startup_urls();
170 for (std::vector<GURL>::const_iterator i = urls.begin(); 170 for (std::vector<GURL>::const_iterator i = urls.begin();
171 i != urls.end(); ++i) 171 i != urls.end(); ++i)
172 list->AppendString(i->spec()); 172 list->AppendString(i->spec());
173 dict.Set(kStartupURLPath, list); 173 dict.Set(kStartupURLPath, list);
174 dict.SetInteger(kStartupTypePath, snapshot.startup_type()); 174 dict.SetInteger(kStartupTypePath, snapshot.startup_type());
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 feedback_data->set_page_url(""); 241 feedback_data->set_page_url("");
242 feedback_data->set_user_email(""); 242 feedback_data->set_user_email("");
243 243
244 feedback_util::SendReport(feedback_data); 244 feedback_util::SendReport(feedback_data);
245 } 245 }
246 246
247 scoped_ptr<base::ListValue> GetReadableFeedbackForSnapshot( 247 scoped_ptr<base::ListValue> GetReadableFeedbackForSnapshot(
248 Profile* profile, 248 Profile* profile,
249 const ResettableSettingsSnapshot& snapshot) { 249 const ResettableSettingsSnapshot& snapshot) {
250 DCHECK(profile); 250 DCHECK(profile);
251 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 251 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
252 scoped_ptr<base::ListValue> list(new base::ListValue); 252 scoped_ptr<base::ListValue> list(new base::ListValue);
253 AddPair(list.get(), 253 AddPair(list.get(),
254 l10n_util::GetStringUTF16(IDS_RESET_PROFILE_SETTINGS_LOCALE), 254 l10n_util::GetStringUTF16(IDS_RESET_PROFILE_SETTINGS_LOCALE),
255 g_browser_process->GetApplicationLocale()); 255 g_browser_process->GetApplicationLocale());
256 AddPair(list.get(), 256 AddPair(list.get(),
257 l10n_util::GetStringUTF16(IDS_RESET_PROFILE_SETTINGS_USER_AGENT), 257 l10n_util::GetStringUTF16(IDS_RESET_PROFILE_SETTINGS_USER_AGENT),
258 GetUserAgent()); 258 GetUserAgent());
259 chrome::VersionInfo version_info; 259 chrome::VersionInfo version_info;
260 std::string version = version_info.Version(); 260 std::string version = version_info.Version();
261 version += chrome::VersionInfo::GetVersionStringModifier(); 261 version += chrome::VersionInfo::GetVersionStringModifier();
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 extension_names += '\n'; 359 extension_names += '\n';
360 extension_names += i->second; 360 extension_names += i->second;
361 } 361 }
362 if (!extension_names.empty()) { 362 if (!extension_names.empty()) {
363 AddPair(list.get(), 363 AddPair(list.get(),
364 l10n_util::GetStringUTF16(IDS_RESET_PROFILE_SETTINGS_EXTENSIONS), 364 l10n_util::GetStringUTF16(IDS_RESET_PROFILE_SETTINGS_EXTENSIONS),
365 extension_names); 365 extension_names);
366 } 366 }
367 return list.Pass(); 367 return list.Pass();
368 } 368 }
OLDNEW
« no previous file with comments | « chrome/browser/profile_resetter/profile_resetter_browsertest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698