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