Index: chrome/browser/shell_integration.cc |
diff --git a/chrome/browser/shell_integration.cc b/chrome/browser/shell_integration.cc |
index 2ac4b5896e9b7a6900d43331a66bd853698a581f..9180f6f706942faea5ac3e7eb6d35acd325c4a3b 100644 |
--- a/chrome/browser/shell_integration.cc |
+++ b/chrome/browser/shell_integration.cc |
@@ -29,6 +29,18 @@ |
using content::BrowserThread; |
+#if !defined(OS_WIN) |
+// static |
+bool ShellIntegration::IsSetAsDefaultAsynchronous() { |
+ return false; |
+} |
+ |
+// static |
+void ShellIntegration::SetAsDefaultBrowserAsynchronous() { |
+ NOTREACHED(); |
+} |
+#endif // !defined(OS_WIN) |
+ |
// static |
ShellIntegration::DefaultWebClientSetPermission |
ShellIntegration::CanSetAsDefaultProtocolClient() { |
@@ -135,6 +147,13 @@ bool ShellIntegration::IsElevationNeededForSettingDefaultProtocolClient() { |
return false; |
} |
+void ShellIntegration::DefaultBrowserWorker::InitializeSetAsDefault() {} |
+ |
+bool ShellIntegration::DefaultBrowserWorker::UninitializeSetAsDefault( |
+ bool succeeded) { |
+ return true; |
+} |
+ |
#endif // !defined(OS_WIN) |
bool ShellIntegration::DefaultWebClientObserver::IsOwnedByWorker() { |
@@ -171,6 +190,9 @@ void ShellIntegration::DefaultWebClientWorker::StartSetAsDefault() { |
observer_->SetDefaultWebClientUIState(STATE_PROCESSING); |
interactive_permitted = observer_->IsInteractiveSetDefaultPermitted(); |
} |
+ |
+ InitializeSetAsDefault(); |
+ |
BrowserThread::PostTask( |
BrowserThread::FILE, FROM_HERE, |
base::Bind(&DefaultWebClientWorker::ExecuteSetAsDefault, this, |
@@ -199,7 +221,9 @@ void ShellIntegration::DefaultWebClientWorker::ExecuteCheckIsDefault() { |
void ShellIntegration::DefaultWebClientWorker::CompleteCheckIsDefault( |
DefaultWebClientState state) { |
DCHECK_CURRENTLY_ON(BrowserThread::UI); |
+ |
UpdateUI(state); |
+ |
// The worker has finished everything it needs to do, so free the observer |
// if we own it. |
if (observer_ && observer_->IsOwnedByWorker()) { |
@@ -212,20 +236,23 @@ void ShellIntegration::DefaultWebClientWorker::ExecuteSetAsDefault( |
bool interactive_permitted) { |
DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
- bool result = SetAsDefault(interactive_permitted); |
- BrowserThread::PostTask( |
- BrowserThread::UI, FROM_HERE, |
- base::Bind(&DefaultWebClientWorker::CompleteSetAsDefault, this, result)); |
+ SetAsDefault(interactive_permitted); |
} |
void ShellIntegration::DefaultWebClientWorker::CompleteSetAsDefault( |
bool succeeded) { |
DCHECK_CURRENTLY_ON(BrowserThread::UI); |
- // First tell the observer what the SetAsDefault call has returned. |
- if (observer_) |
- observer_->OnSetAsDefaultConcluded(succeeded); |
- // Set as default completed, check again to make sure it stuck... |
- StartCheckIsDefault(); |
+ |
+ // Only notify observer is |UninitializeSetAsDefault| returns true. This is to |
grt (UTC plus 2)
2015/09/22 18:21:47
is -> if
Patrick Monette
2015/09/23 22:40:44
Comment removed.
|
+ // filter out multiple calls to |CompleteSetAsDefault| due to possible race |
+ // conditions. |
+ if (UninitializeSetAsDefault(succeeded)) { |
+ // First tell the observer what the SetAsDefault call has returned. |
+ if (observer_) |
+ observer_->OnSetAsDefaultConcluded(succeeded); |
+ // Set as default completed, check again to make sure it stuck... |
+ StartCheckIsDefault(); |
+ } |
} |
void ShellIntegration::DefaultWebClientWorker::UpdateUI( |
@@ -264,22 +291,33 @@ ShellIntegration::DefaultBrowserWorker::CheckIsDefault() { |
return ShellIntegration::GetDefaultBrowser(); |
} |
-bool ShellIntegration::DefaultBrowserWorker::SetAsDefault( |
+void ShellIntegration::DefaultBrowserWorker::SetAsDefault( |
bool interactive_permitted) { |
bool result = false; |
switch (ShellIntegration::CanSetAsDefaultBrowser()) { |
case ShellIntegration::SET_DEFAULT_UNATTENDED: |
result = ShellIntegration::SetAsDefaultBrowser(); |
+ BrowserThread::PostTask( |
+ BrowserThread::UI, FROM_HERE, |
+ base::Bind(&DefaultBrowserWorker::CompleteSetAsDefault, this, |
+ result)); |
break; |
case ShellIntegration::SET_DEFAULT_INTERACTIVE: |
- if (interactive_permitted) |
+ if (interactive_permitted) { |
result = ShellIntegration::SetAsDefaultBrowserInteractive(); |
+ BrowserThread::PostTask( |
+ BrowserThread::UI, FROM_HERE, |
+ base::Bind(&DefaultBrowserWorker::CompleteSetAsDefault, this, |
+ result)); |
+ } |
grt (UTC plus 2)
2015/09/22 18:21:47
this should run CompleteSetAsDefault with result=f
Patrick Monette
2015/09/23 22:40:44
CompleteSetAsDefault is not called at the end with
|
+ break; |
+ case ShellIntegration::SET_DEFAULT_ASYNCHRONOUS: |
+ if (interactive_permitted) |
+ ShellIntegration::SetAsDefaultBrowserAsynchronous(); |
break; |
default: |
grt (UTC plus 2)
2015/09/22 18:21:47
while you're here, please change this from "defaul
Patrick Monette
2015/09/23 22:40:44
Done. Moved the cases around so they are in the sa
|
NOTREACHED(); |
} |
- |
- return result; |
} |
/////////////////////////////////////////////////////////////////////////////// |
@@ -300,23 +338,32 @@ ShellIntegration::DefaultProtocolClientWorker::CheckIsDefault() { |
return ShellIntegration::IsDefaultProtocolClient(protocol_); |
} |
-bool ShellIntegration::DefaultProtocolClientWorker::SetAsDefault( |
+void ShellIntegration::DefaultProtocolClientWorker::SetAsDefault( |
bool interactive_permitted) { |
bool result = false; |
switch (ShellIntegration::CanSetAsDefaultProtocolClient()) { |
case ShellIntegration::SET_DEFAULT_NOT_ALLOWED: |
- result = false; |
+ BrowserThread::PostTask( |
+ BrowserThread::UI, FROM_HERE, |
+ base::Bind(&DefaultProtocolClientWorker::CompleteSetAsDefault, this, |
+ false)); |
break; |
case ShellIntegration::SET_DEFAULT_UNATTENDED: |
result = ShellIntegration::SetAsDefaultProtocolClient(protocol_); |
+ BrowserThread::PostTask( |
+ BrowserThread::UI, FROM_HERE, |
+ base::Bind(&DefaultProtocolClientWorker::CompleteSetAsDefault, this, |
+ result)); |
break; |
case ShellIntegration::SET_DEFAULT_INTERACTIVE: |
if (interactive_permitted) { |
- result = ShellIntegration::SetAsDefaultProtocolClientInteractive( |
- protocol_); |
+ result = |
+ ShellIntegration::SetAsDefaultProtocolClientInteractive(protocol_); |
+ BrowserThread::PostTask( |
+ BrowserThread::UI, FROM_HERE, |
+ base::Bind(&DefaultProtocolClientWorker::CompleteSetAsDefault, this, |
+ result)); |
} |
break; |
} |
- |
- return result; |
} |