Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 base::CreateSequencedTaskRunnerWithTraits({base::MayBlock()}) |
|
gab
2017/05/26 18:44:05
Why does this need to be called on a sequence whic
Patrick Monette
2017/05/29 18:54:14
I decided to go with sequencing everything
| |
| 140 BrowserThread::FILE, FROM_HERE, | 141 ->PostTask(FROM_HERE, base::Bind(&DefaultWebClientWorker::CheckIsDefault, |
| 141 base::Bind(&DefaultWebClientWorker::CheckIsDefault, this, false)); | 142 this, false)); |
| 142 } | 143 } |
| 143 | 144 |
| 144 void DefaultWebClientWorker::StartSetAsDefault() { | 145 void DefaultWebClientWorker::StartSetAsDefault() { |
| 145 BrowserThread::PostTask( | 146 GetSetDefaultTaskRunner()->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::GetSetDefaultTaskRunner() { | |
| 175 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 176 #if defined(OS_WIN) | |
| 177 if (base::win::GetVersion() >= base::win::VERSION_WIN10) { | |
| 178 // On Windows 10, all the calls to SetAsDefault() must be done on the same | |
| 179 // SequencedTaskRunner (see OpenSystemSettingsHelper). Because the callers | |
| 180 // don't know each others, a global is shared between them. | |
| 181 // | |
| 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. | |
|
gab
2017/05/26 18:44:05
Feels like we might as well just sequence all atte
Patrick Monette
2017/05/29 18:54:14
Sounds good.
| |
| 185 static base::SingleThreadTaskRunner* task_runner = nullptr; | |
|
gab
2017/05/26 18:44:05
Make this a scoped_refptr<> assign the result of b
Patrick Monette
2017/05/29 18:54:14
Done.
| |
| 186 | |
| 187 if (!task_runner) { | |
| 188 scoped_refptr<base::SingleThreadTaskRunner> new_task_runner = | |
| 189 base::CreateSingleThreadTaskRunnerWithTraits({base::MayBlock()}); | |
| 190 | |
| 191 new_task_runner->AddRef(); | |
| 192 task_runner = new_task_runner.get(); | |
| 193 } | |
| 194 | |
| 195 return task_runner; | |
| 196 } | |
| 197 #endif // defined(OS_WIN) | |
|
gab
2017/05/26 18:44:05
#else?
Patrick Monette
2017/05/29 18:54:14
Done.
| |
| 198 return base::CreateSequencedTaskRunnerWithTraits({base::MayBlock()}); | |
| 199 #endif // !defined(OS_WIN) | |
|
gab
2017/05/26 18:44:05
#endif // defined(OS_WIN)
^ don't add
Patrick Monette
2017/05/29 18:54:14
Done.
| |
| 200 } | |
| 201 | |
| 173 void DefaultWebClientWorker::CheckIsDefault(bool is_following_set_as_default) { | 202 void DefaultWebClientWorker::CheckIsDefault(bool is_following_set_as_default) { |
| 174 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 203 base::ThreadRestrictions::AssertIOAllowed(); |
| 204 | |
| 175 DefaultWebClientState state = CheckIsDefaultImpl(); | 205 DefaultWebClientState state = CheckIsDefaultImpl(); |
| 176 BrowserThread::PostTask( | 206 BrowserThread::PostTask( |
| 177 BrowserThread::UI, FROM_HERE, | 207 BrowserThread::UI, FROM_HERE, |
| 178 base::Bind(&DefaultBrowserWorker::OnCheckIsDefaultComplete, this, state, | 208 base::Bind(&DefaultBrowserWorker::OnCheckIsDefaultComplete, this, state, |
| 179 is_following_set_as_default)); | 209 is_following_set_as_default)); |
| 180 } | 210 } |
| 181 | 211 |
| 182 void DefaultWebClientWorker::SetAsDefault() { | 212 void DefaultWebClientWorker::SetAsDefault() { |
| 183 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 213 base::ThreadRestrictions::AssertIOAllowed(); |
| 184 | 214 |
| 185 // SetAsDefaultImpl will make sure the callback is executed exactly once. | 215 // SetAsDefaultImpl will make sure the callback is executed exactly once. |
| 186 SetAsDefaultImpl( | 216 SetAsDefaultImpl( |
| 187 base::Bind(&DefaultWebClientWorker::CheckIsDefault, this, true)); | 217 base::Bind(&DefaultWebClientWorker::CheckIsDefault, this, true)); |
| 188 } | 218 } |
| 189 | 219 |
| 190 void DefaultWebClientWorker::ReportSetDefaultResult( | 220 void DefaultWebClientWorker::ReportSetDefaultResult( |
| 191 DefaultWebClientState state) { | 221 DefaultWebClientState state) { |
| 192 base::LinearHistogram::FactoryGet( | 222 base::LinearHistogram::FactoryGet( |
| 193 base::StringPrintf("%s.SetDefaultResult2", worker_name_), 1, | 223 base::StringPrintf("%s.SetDefaultResult2", worker_name_), 1, |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 308 return; | 338 return; |
| 309 } | 339 } |
| 310 } | 340 } |
| 311 #endif // defined(OS_WIN) | 341 #endif // defined(OS_WIN) |
| 312 break; | 342 break; |
| 313 } | 343 } |
| 314 on_finished_callback.Run(); | 344 on_finished_callback.Run(); |
| 315 } | 345 } |
| 316 | 346 |
| 317 } // namespace shell_integration | 347 } // namespace shell_integration |
| OLD | NEW |