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.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 | 38 |
39 const struct AppModeInfo* gAppModeInfo = nullptr; | 39 const struct AppModeInfo* gAppModeInfo = nullptr; |
40 | 40 |
41 } // namespace | 41 } // namespace |
42 | 42 |
43 #if !defined(OS_WIN) | 43 #if !defined(OS_WIN) |
44 bool SetAsDefaultBrowserInteractive() { | 44 bool SetAsDefaultBrowserInteractive() { |
45 return false; | 45 return false; |
46 } | 46 } |
47 | 47 |
| 48 void SetAsDefaultBrowserUsingSystemSettings( |
| 49 const base::Closure& on_finished_callback) { |
| 50 // This function should only be called on Windows 10+. |
| 51 NOTREACHED(); |
| 52 on_finished_callback.Run(); |
| 53 } |
| 54 |
48 bool SetAsDefaultProtocolClientInteractive(const std::string& protocol) { | 55 bool SetAsDefaultProtocolClientInteractive(const std::string& protocol) { |
49 return false; | 56 return false; |
50 } | 57 } |
51 #endif // !defined(OS_WIN) | 58 #endif // !defined(OS_WIN) |
52 | 59 |
53 DefaultWebClientSetPermission CanSetAsDefaultProtocolClient() { | 60 DefaultWebClientSetPermission CanSetAsDefaultProtocolClient() { |
54 // Allowed as long as the browser can become the operating system default | 61 // Allowed as long as the browser can become the operating system default |
55 // browser. | 62 // browser. |
56 return CanSetAsDefaultBrowser(); | 63 return CanSetAsDefaultBrowser(); |
57 } | 64 } |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 187 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
181 DefaultWebClientState state = CheckIsDefaultImpl(); | 188 DefaultWebClientState state = CheckIsDefaultImpl(); |
182 BrowserThread::PostTask( | 189 BrowserThread::PostTask( |
183 BrowserThread::UI, FROM_HERE, | 190 BrowserThread::UI, FROM_HERE, |
184 base::Bind(&DefaultBrowserWorker::OnCheckIsDefaultComplete, this, state, | 191 base::Bind(&DefaultBrowserWorker::OnCheckIsDefaultComplete, this, state, |
185 is_following_set_as_default)); | 192 is_following_set_as_default)); |
186 } | 193 } |
187 | 194 |
188 void DefaultWebClientWorker::SetAsDefault() { | 195 void DefaultWebClientWorker::SetAsDefault() { |
189 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 196 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
190 SetAsDefaultImpl(); | 197 |
191 CheckIsDefault(true); | 198 // SetAsDefaultImpl will make sure the callback is executed exactly once. |
| 199 SetAsDefaultImpl( |
| 200 base::Bind(&DefaultWebClientWorker::CheckIsDefault, this, true)); |
192 } | 201 } |
193 | 202 |
194 void DefaultWebClientWorker::ReportSetDefaultResult( | 203 void DefaultWebClientWorker::ReportSetDefaultResult( |
195 DefaultWebClientState state) { | 204 DefaultWebClientState state) { |
196 base::LinearHistogram::FactoryGet( | 205 base::LinearHistogram::FactoryGet( |
197 base::StringPrintf("%s.SetDefaultResult2", worker_name_), 1, | 206 base::StringPrintf("%s.SetDefaultResult2", worker_name_), 1, |
198 DefaultWebClientState::NUM_DEFAULT_STATES, | 207 DefaultWebClientState::NUM_DEFAULT_STATES, |
199 DefaultWebClientState::NUM_DEFAULT_STATES + 1, | 208 DefaultWebClientState::NUM_DEFAULT_STATES + 1, |
200 base::HistogramBase::kUmaTargetedHistogramFlag) | 209 base::HistogramBase::kUmaTargetedHistogramFlag) |
201 ->Add(state); | 210 ->Add(state); |
(...skipping 28 matching lines...) Expand all Loading... |
230 | 239 |
231 /////////////////////////////////////////////////////////////////////////////// | 240 /////////////////////////////////////////////////////////////////////////////// |
232 // DefaultBrowserWorker, private: | 241 // DefaultBrowserWorker, private: |
233 | 242 |
234 DefaultBrowserWorker::~DefaultBrowserWorker() = default; | 243 DefaultBrowserWorker::~DefaultBrowserWorker() = default; |
235 | 244 |
236 DefaultWebClientState DefaultBrowserWorker::CheckIsDefaultImpl() { | 245 DefaultWebClientState DefaultBrowserWorker::CheckIsDefaultImpl() { |
237 return GetDefaultBrowser(); | 246 return GetDefaultBrowser(); |
238 } | 247 } |
239 | 248 |
240 void DefaultBrowserWorker::SetAsDefaultImpl() { | 249 void DefaultBrowserWorker::SetAsDefaultImpl( |
| 250 const base::Closure& on_finished_callback) { |
241 switch (CanSetAsDefaultBrowser()) { | 251 switch (CanSetAsDefaultBrowser()) { |
242 case SET_DEFAULT_NOT_ALLOWED: | 252 case SET_DEFAULT_NOT_ALLOWED: |
243 NOTREACHED(); | 253 NOTREACHED(); |
244 break; | 254 break; |
245 case SET_DEFAULT_UNATTENDED: | 255 case SET_DEFAULT_UNATTENDED: |
246 SetAsDefaultBrowser(); | 256 SetAsDefaultBrowser(); |
247 break; | 257 break; |
248 case SET_DEFAULT_INTERACTIVE: | 258 case SET_DEFAULT_INTERACTIVE: |
249 if (interactive_permitted_) | 259 if (interactive_permitted_) |
250 SetAsDefaultBrowserInteractive(); | 260 SetAsDefaultBrowserInteractive(); |
251 break; | 261 break; |
| 262 case SET_DEFAULT_OPEN_SETTINGS: |
| 263 if (interactive_permitted_) { |
| 264 SetAsDefaultBrowserUsingSystemSettings(on_finished_callback); |
| 265 return; |
| 266 } |
| 267 break; |
252 } | 268 } |
| 269 on_finished_callback.Run(); |
253 } | 270 } |
254 | 271 |
255 /////////////////////////////////////////////////////////////////////////////// | 272 /////////////////////////////////////////////////////////////////////////////// |
256 // DefaultProtocolClientWorker | 273 // DefaultProtocolClientWorker |
257 // | 274 // |
258 | 275 |
259 DefaultProtocolClientWorker::DefaultProtocolClientWorker( | 276 DefaultProtocolClientWorker::DefaultProtocolClientWorker( |
260 const DefaultWebClientWorkerCallback& callback, | 277 const DefaultWebClientWorkerCallback& callback, |
261 const std::string& protocol) | 278 const std::string& protocol) |
262 : DefaultWebClientWorker(callback, "DefaultProtocolClient"), | 279 : DefaultWebClientWorker(callback, "DefaultProtocolClient"), |
263 protocol_(protocol) {} | 280 protocol_(protocol) {} |
264 | 281 |
265 /////////////////////////////////////////////////////////////////////////////// | 282 /////////////////////////////////////////////////////////////////////////////// |
266 // DefaultProtocolClientWorker, protected: | 283 // DefaultProtocolClientWorker, protected: |
267 | 284 |
268 DefaultProtocolClientWorker::~DefaultProtocolClientWorker() = default; | 285 DefaultProtocolClientWorker::~DefaultProtocolClientWorker() = default; |
269 | 286 |
270 /////////////////////////////////////////////////////////////////////////////// | 287 /////////////////////////////////////////////////////////////////////////////// |
271 // DefaultProtocolClientWorker, private: | 288 // DefaultProtocolClientWorker, private: |
272 | 289 |
273 DefaultWebClientState DefaultProtocolClientWorker::CheckIsDefaultImpl() { | 290 DefaultWebClientState DefaultProtocolClientWorker::CheckIsDefaultImpl() { |
274 return IsDefaultProtocolClient(protocol_); | 291 return IsDefaultProtocolClient(protocol_); |
275 } | 292 } |
276 | 293 |
277 void DefaultProtocolClientWorker::SetAsDefaultImpl() { | 294 void DefaultProtocolClientWorker::SetAsDefaultImpl( |
| 295 const base::Closure& on_finished_callback) { |
278 switch (CanSetAsDefaultProtocolClient()) { | 296 switch (CanSetAsDefaultProtocolClient()) { |
279 case SET_DEFAULT_NOT_ALLOWED: | 297 case SET_DEFAULT_NOT_ALLOWED: |
280 // Not allowed, do nothing. | 298 // Not allowed, do nothing. |
281 break; | 299 break; |
282 case SET_DEFAULT_UNATTENDED: | 300 case SET_DEFAULT_UNATTENDED: |
283 SetAsDefaultProtocolClient(protocol_); | 301 SetAsDefaultProtocolClient(protocol_); |
284 break; | 302 break; |
285 case SET_DEFAULT_INTERACTIVE: | 303 case SET_DEFAULT_INTERACTIVE: |
286 if (interactive_permitted_) { | 304 // TODO(pmonette): Implement SET_DEFAULT_OPEN_SETTINGS for Windows 10. |
| 305 case SET_DEFAULT_OPEN_SETTINGS: |
| 306 if (interactive_permitted_) |
287 SetAsDefaultProtocolClientInteractive(protocol_); | 307 SetAsDefaultProtocolClientInteractive(protocol_); |
288 } | |
289 break; | 308 break; |
290 } | 309 } |
| 310 on_finished_callback.Run(); |
291 } | 311 } |
292 | 312 |
293 } // namespace shell_integration | 313 } // namespace shell_integration |
OLD | NEW |