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

Side by Side Diff: chrome/browser/shell_integration.cc

Issue 2888693003: Remove the usage of BrowserThread::FILE in the shell_integration* files (Closed)
Patch Set: Stuff Created 3 years, 6 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/shell_integration.h" 5 #include "chrome/browser/shell_integration.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "base/task_scheduler/post_task.h"
14 #include "base/threading/thread_restrictions.h" 15 #include "base/threading/thread_restrictions.h"
15 #include "build/build_config.h" 16 #include "build/build_config.h"
16 #include "chrome/browser/policy/policy_path_parser.h" 17 #include "chrome/browser/policy/policy_path_parser.h"
17 #include "chrome/common/chrome_paths.h" 18 #include "chrome/common/chrome_paths.h"
18 #include "chrome/common/chrome_switches.h" 19 #include "chrome/common/chrome_switches.h"
19 #include "components/prefs/pref_service.h" 20 #include "components/prefs/pref_service.h"
20 #include "components/version_info/version_info.h" 21 #include "components/version_info/version_info.h"
21 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
22 23
23 #if defined(OS_CHROMEOS) 24 #if defined(OS_CHROMEOS)
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 return l10n_util::GetStringUTF16(IDS_APP_SHORTCUTS_SUBDIR_NAME_CANARY); 130 return l10n_util::GetStringUTF16(IDS_APP_SHORTCUTS_SUBDIR_NAME_CANARY);
130 return l10n_util::GetStringUTF16(IDS_APP_SHORTCUTS_SUBDIR_NAME); 131 return l10n_util::GetStringUTF16(IDS_APP_SHORTCUTS_SUBDIR_NAME);
131 } 132 }
132 #endif // !defined(OS_WIN) 133 #endif // !defined(OS_WIN)
133 134
134 /////////////////////////////////////////////////////////////////////////////// 135 ///////////////////////////////////////////////////////////////////////////////
135 // DefaultWebClientWorker 136 // DefaultWebClientWorker
136 // 137 //
137 138
138 void DefaultWebClientWorker::StartCheckIsDefault() { 139 void DefaultWebClientWorker::StartCheckIsDefault() {
139 BrowserThread::PostTask( 140 GetTaskRunner()->PostTask(
140 BrowserThread::FILE, FROM_HERE, 141 FROM_HERE,
141 base::Bind(&DefaultWebClientWorker::CheckIsDefault, this, false)); 142 base::Bind(&DefaultWebClientWorker::CheckIsDefault, this, false));
142 } 143 }
143 144
144 void DefaultWebClientWorker::StartSetAsDefault() { 145 void DefaultWebClientWorker::StartSetAsDefault() {
145 BrowserThread::PostTask( 146 GetTaskRunner()->PostTask(
146 BrowserThread::FILE, FROM_HERE, 147 FROM_HERE, base::Bind(&DefaultWebClientWorker::SetAsDefault, this));
147 base::Bind(&DefaultWebClientWorker::SetAsDefault, this));
148 } 148 }
149 149
150 /////////////////////////////////////////////////////////////////////////////// 150 ///////////////////////////////////////////////////////////////////////////////
151 // DefaultWebClientWorker, protected: 151 // DefaultWebClientWorker, protected:
152 152
153 DefaultWebClientWorker::DefaultWebClientWorker( 153 DefaultWebClientWorker::DefaultWebClientWorker(
154 const DefaultWebClientWorkerCallback& callback, 154 const DefaultWebClientWorkerCallback& callback,
155 const char* worker_name) 155 const char* worker_name)
156 : callback_(callback), worker_name_(worker_name) {} 156 : callback_(callback), worker_name_(worker_name) {}
157 157
158 DefaultWebClientWorker::~DefaultWebClientWorker() = default; 158 DefaultWebClientWorker::~DefaultWebClientWorker() = default;
159 159
160 void DefaultWebClientWorker::OnCheckIsDefaultComplete( 160 void DefaultWebClientWorker::OnCheckIsDefaultComplete(
161 DefaultWebClientState state, 161 DefaultWebClientState state,
162 bool is_following_set_as_default) { 162 bool is_following_set_as_default) {
163 DCHECK_CURRENTLY_ON(BrowserThread::UI); 163 DCHECK_CURRENTLY_ON(BrowserThread::UI);
164 UpdateUI(state); 164 UpdateUI(state);
165 165
166 if (is_following_set_as_default) 166 if (is_following_set_as_default)
167 ReportSetDefaultResult(state); 167 ReportSetDefaultResult(state);
168 } 168 }
169 169
170 /////////////////////////////////////////////////////////////////////////////// 170 ///////////////////////////////////////////////////////////////////////////////
171 // DefaultWebClientWorker, private: 171 // DefaultWebClientWorker, private:
172 172
173 scoped_refptr<base::SequencedTaskRunner>
174 DefaultWebClientWorker::GetTaskRunner() {
175 DCHECK_CURRENTLY_ON(BrowserThread::UI);
176
177 static scoped_refptr<base::SequencedTaskRunner>* task_runner = nullptr;
gab 2017/05/30 19:22:21 I think this can just be a static scoped_refptr<b
Patrick Monette 2017/05/31 16:13:57 As per offline discussion, keeping this as a point
robliao 2017/07/14 21:13:13 Wait, why must function static variables be POD? A
Patrick Monette 2017/07/14 21:25:34 Prescribed by the style guide. https://google.gith
robliao 2017/07/14 21:30:57 Got it. I thought that only applied at the global
178
179 if (!task_runner) {
180 #if defined(OS_WIN)
181 if (base::win::GetVersion() >= base::win::VERSION_WIN10) {
182 // TODO(pmonette): Windows 10's implementation uses a base::Timer which
183 // currently still requires a SingleThreadTaskRunner. Change this to a
184 // SequencedTaskRunner when crbug.com/552633 is fixed.
185 task_runner = new scoped_refptr<base::SequencedTaskRunner>(
gab 2017/05/30 19:22:21 and then here you can forgo this new
Patrick Monette 2017/05/31 16:13:57 Acknowledged.
186 base::CreateSingleThreadTaskRunnerWithTraits({base::MayBlock()}));
187 } else {
188 task_runner = new scoped_refptr<base::SequencedTaskRunner>(
189 base::CreateSequencedTaskRunnerWithTraits({base::MayBlock()}));
190 }
191 #else // defined(OS_WIN)
192 task_runner = new scoped_refptr<base::SequencedTaskRunner>(
193 base::CreateSequencedTaskRunnerWithTraits({base::MayBlock()}));
194 #endif // defined(OS_WIN)
195 }
196
197 return *task_runner;
198 }
199
173 void DefaultWebClientWorker::CheckIsDefault(bool is_following_set_as_default) { 200 void DefaultWebClientWorker::CheckIsDefault(bool is_following_set_as_default) {
174 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 201 base::ThreadRestrictions::AssertIOAllowed();
202
175 DefaultWebClientState state = CheckIsDefaultImpl(); 203 DefaultWebClientState state = CheckIsDefaultImpl();
176 BrowserThread::PostTask( 204 BrowserThread::PostTask(
177 BrowserThread::UI, FROM_HERE, 205 BrowserThread::UI, FROM_HERE,
178 base::Bind(&DefaultBrowserWorker::OnCheckIsDefaultComplete, this, state, 206 base::Bind(&DefaultBrowserWorker::OnCheckIsDefaultComplete, this, state,
179 is_following_set_as_default)); 207 is_following_set_as_default));
180 } 208 }
181 209
182 void DefaultWebClientWorker::SetAsDefault() { 210 void DefaultWebClientWorker::SetAsDefault() {
183 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 211 base::ThreadRestrictions::AssertIOAllowed();
184 212
185 // SetAsDefaultImpl will make sure the callback is executed exactly once. 213 // SetAsDefaultImpl will make sure the callback is executed exactly once.
186 SetAsDefaultImpl( 214 SetAsDefaultImpl(
187 base::Bind(&DefaultWebClientWorker::CheckIsDefault, this, true)); 215 base::Bind(&DefaultWebClientWorker::CheckIsDefault, this, true));
188 } 216 }
189 217
190 void DefaultWebClientWorker::ReportSetDefaultResult( 218 void DefaultWebClientWorker::ReportSetDefaultResult(
191 DefaultWebClientState state) { 219 DefaultWebClientState state) {
192 base::LinearHistogram::FactoryGet( 220 base::LinearHistogram::FactoryGet(
193 base::StringPrintf("%s.SetDefaultResult2", worker_name_), 1, 221 base::StringPrintf("%s.SetDefaultResult2", worker_name_), 1,
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 return; 336 return;
309 } 337 }
310 } 338 }
311 #endif // defined(OS_WIN) 339 #endif // defined(OS_WIN)
312 break; 340 break;
313 } 341 }
314 on_finished_callback.Run(); 342 on_finished_callback.Run();
315 } 343 }
316 344
317 } // namespace shell_integration 345 } // namespace shell_integration
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698