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

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: Added a comment and fix typo 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
« no previous file with comments | « chrome/browser/shell_integration.h ('k') | chrome/browser/shell_integration_linux.cc » ('j') | 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) 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 13 matching lines...) Expand all
37 #endif 38 #endif
38 39
39 using content::BrowserThread; 40 using content::BrowserThread;
40 41
41 namespace shell_integration { 42 namespace shell_integration {
42 43
43 namespace { 44 namespace {
44 45
45 const struct AppModeInfo* gAppModeInfo = nullptr; 46 const struct AppModeInfo* gAppModeInfo = nullptr;
46 47
48 scoped_refptr<base::SequencedTaskRunner>
49 CreateTaskRunnerForDefaultWebClientWorker() {
50 #if defined(OS_WIN)
51 if (base::win::GetVersion() >= base::win::VERSION_WIN10)
52 // TODO(pmonette): Windows 10's implementation uses a base::Timer which
53 // currently still requires a SingleThreadTaskRunner. Change this to a
54 // SequencedTaskRunner when crbug.com/552633 is fixed.
55 return base::CreateSingleThreadTaskRunnerWithTraits({base::MayBlock()});
56 #endif // defined(OS_WIN)
57 return base::CreateSequencedTaskRunnerWithTraits({base::MayBlock()});
58 }
59
47 } // namespace 60 } // namespace
48 61
49 bool CanSetAsDefaultBrowser() { 62 bool CanSetAsDefaultBrowser() {
50 return GetDefaultWebClientSetPermission() != SET_DEFAULT_NOT_ALLOWED; 63 return GetDefaultWebClientSetPermission() != SET_DEFAULT_NOT_ALLOWED;
51 } 64 }
52 65
53 #if !defined(OS_WIN) 66 #if !defined(OS_WIN)
54 bool IsElevationNeededForSettingDefaultProtocolClient() { 67 bool IsElevationNeededForSettingDefaultProtocolClient() {
55 return false; 68 return false;
56 } 69 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 return l10n_util::GetStringUTF16(IDS_APP_SHORTCUTS_SUBDIR_NAME_CANARY); 142 return l10n_util::GetStringUTF16(IDS_APP_SHORTCUTS_SUBDIR_NAME_CANARY);
130 return l10n_util::GetStringUTF16(IDS_APP_SHORTCUTS_SUBDIR_NAME); 143 return l10n_util::GetStringUTF16(IDS_APP_SHORTCUTS_SUBDIR_NAME);
131 } 144 }
132 #endif // !defined(OS_WIN) 145 #endif // !defined(OS_WIN)
133 146
134 /////////////////////////////////////////////////////////////////////////////// 147 ///////////////////////////////////////////////////////////////////////////////
135 // DefaultWebClientWorker 148 // DefaultWebClientWorker
136 // 149 //
137 150
138 void DefaultWebClientWorker::StartCheckIsDefault() { 151 void DefaultWebClientWorker::StartCheckIsDefault() {
139 BrowserThread::PostTask( 152 GetTaskRunner()->PostTask(
140 BrowserThread::FILE, FROM_HERE, 153 FROM_HERE,
141 base::Bind(&DefaultWebClientWorker::CheckIsDefault, this, false)); 154 base::Bind(&DefaultWebClientWorker::CheckIsDefault, this, false));
142 } 155 }
143 156
144 void DefaultWebClientWorker::StartSetAsDefault() { 157 void DefaultWebClientWorker::StartSetAsDefault() {
145 BrowserThread::PostTask( 158 GetTaskRunner()->PostTask(
146 BrowserThread::FILE, FROM_HERE, 159 FROM_HERE, base::Bind(&DefaultWebClientWorker::SetAsDefault, this));
147 base::Bind(&DefaultWebClientWorker::SetAsDefault, this));
148 } 160 }
149 161
150 /////////////////////////////////////////////////////////////////////////////// 162 ///////////////////////////////////////////////////////////////////////////////
151 // DefaultWebClientWorker, protected: 163 // DefaultWebClientWorker, protected:
152 164
153 DefaultWebClientWorker::DefaultWebClientWorker( 165 DefaultWebClientWorker::DefaultWebClientWorker(
154 const DefaultWebClientWorkerCallback& callback, 166 const DefaultWebClientWorkerCallback& callback,
155 const char* worker_name) 167 const char* worker_name)
156 : callback_(callback), worker_name_(worker_name) {} 168 : callback_(callback), worker_name_(worker_name) {}
157 169
158 DefaultWebClientWorker::~DefaultWebClientWorker() = default; 170 DefaultWebClientWorker::~DefaultWebClientWorker() = default;
159 171
160 void DefaultWebClientWorker::OnCheckIsDefaultComplete( 172 void DefaultWebClientWorker::OnCheckIsDefaultComplete(
161 DefaultWebClientState state, 173 DefaultWebClientState state,
162 bool is_following_set_as_default) { 174 bool is_following_set_as_default) {
163 DCHECK_CURRENTLY_ON(BrowserThread::UI); 175 DCHECK_CURRENTLY_ON(BrowserThread::UI);
164 UpdateUI(state); 176 UpdateUI(state);
165 177
166 if (is_following_set_as_default) 178 if (is_following_set_as_default)
167 ReportSetDefaultResult(state); 179 ReportSetDefaultResult(state);
168 } 180 }
169 181
170 /////////////////////////////////////////////////////////////////////////////// 182 ///////////////////////////////////////////////////////////////////////////////
171 // DefaultWebClientWorker, private: 183 // DefaultWebClientWorker, private:
172 184
185 // static
186 scoped_refptr<base::SequencedTaskRunner>
187 DefaultWebClientWorker::GetTaskRunner() {
188 DCHECK_CURRENTLY_ON(BrowserThread::UI);
189
190 // TODO(pmonette): The better way to make sure all instances of
191 // DefaultWebClient share a SequencedTaskRunner is to make the worker a
192 // singleton.
193 static scoped_refptr<base::SequencedTaskRunner>* task_runner = nullptr;
194
195 if (!task_runner) {
196 task_runner = new scoped_refptr<base::SequencedTaskRunner>(
197 CreateTaskRunnerForDefaultWebClientWorker());
198 }
199
200 return *task_runner;
201 }
202
173 void DefaultWebClientWorker::CheckIsDefault(bool is_following_set_as_default) { 203 void DefaultWebClientWorker::CheckIsDefault(bool is_following_set_as_default) {
174 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 204 base::ThreadRestrictions::AssertIOAllowed();
205
175 DefaultWebClientState state = CheckIsDefaultImpl(); 206 DefaultWebClientState state = CheckIsDefaultImpl();
176 BrowserThread::PostTask( 207 BrowserThread::PostTask(
177 BrowserThread::UI, FROM_HERE, 208 BrowserThread::UI, FROM_HERE,
178 base::Bind(&DefaultBrowserWorker::OnCheckIsDefaultComplete, this, state, 209 base::Bind(&DefaultBrowserWorker::OnCheckIsDefaultComplete, this, state,
179 is_following_set_as_default)); 210 is_following_set_as_default));
180 } 211 }
181 212
182 void DefaultWebClientWorker::SetAsDefault() { 213 void DefaultWebClientWorker::SetAsDefault() {
183 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 214 base::ThreadRestrictions::AssertIOAllowed();
184 215
185 // SetAsDefaultImpl will make sure the callback is executed exactly once. 216 // SetAsDefaultImpl will make sure the callback is executed exactly once.
186 SetAsDefaultImpl( 217 SetAsDefaultImpl(
187 base::Bind(&DefaultWebClientWorker::CheckIsDefault, this, true)); 218 base::Bind(&DefaultWebClientWorker::CheckIsDefault, this, true));
188 } 219 }
189 220
190 void DefaultWebClientWorker::ReportSetDefaultResult( 221 void DefaultWebClientWorker::ReportSetDefaultResult(
191 DefaultWebClientState state) { 222 DefaultWebClientState state) {
192 base::LinearHistogram::FactoryGet( 223 base::LinearHistogram::FactoryGet(
193 base::StringPrintf("%s.SetDefaultResult2", worker_name_), 1, 224 base::StringPrintf("%s.SetDefaultResult2", worker_name_), 1,
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 return; 339 return;
309 } 340 }
310 } 341 }
311 #endif // defined(OS_WIN) 342 #endif // defined(OS_WIN)
312 break; 343 break;
313 } 344 }
314 on_finished_callback.Run(); 345 on_finished_callback.Run();
315 } 346 }
316 347
317 } // namespace shell_integration 348 } // namespace shell_integration
OLDNEW
« no previous file with comments | « chrome/browser/shell_integration.h ('k') | chrome/browser/shell_integration_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698