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

Unified Diff: chrome/browser/shell_integration.cc

Issue 1349163008: Setting chrome as the default browser is now fixed on Windows 10 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Responding to comments Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/shell_integration.cc
diff --git a/chrome/browser/shell_integration.cc b/chrome/browser/shell_integration.cc
index 2ac4b5896e9b7a6900d43331a66bd853698a581f..e0d489a1569bb5a9f519b8350c985c43bde702e5 100644
--- a/chrome/browser/shell_integration.cc
+++ b/chrome/browser/shell_integration.cc
@@ -11,6 +11,7 @@
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_restrictions.h"
+#include "base/timer/timer.h"
#include "chrome/browser/policy/policy_path_parser.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
@@ -34,7 +35,11 @@ ShellIntegration::DefaultWebClientSetPermission
ShellIntegration::CanSetAsDefaultProtocolClient() {
// Allowed as long as the browser can become the operating system default
// browser.
- return CanSetAsDefaultBrowser();
+ DefaultWebClientSetPermission permission = CanSetAsDefaultBrowser();
+
+ // Set as default asynchronous is only supported for default web browser.
+ return (permission == SET_DEFAULT_ASYNCHRONOUS) ? SET_DEFAULT_INTERACTIVE
+ : permission;
}
static const struct ShellIntegration::AppModeInfo* gAppModeInfo = NULL;
@@ -124,6 +129,18 @@ bool ShellIntegration::SetAsDefaultBrowserInteractive() {
return false;
}
+#if !defined(OS_WIN)
+// static
+bool ShellIntegration::IsSetAsDefaultAsynchronous() {
+ return false;
+}
+
+// static
+void ShellIntegration::SetAsDefaultBrowserAsynchronous() {
+ NOTREACHED();
+}
+#endif // !defined(OS_WIN)
+
// static
bool ShellIntegration::SetAsDefaultProtocolClientInteractive(
const std::string& protocol) {
@@ -152,29 +169,35 @@ bool ShellIntegration::DefaultWebClientObserver::
ShellIntegration::DefaultWebClientWorker::DefaultWebClientWorker(
DefaultWebClientObserver* observer)
- : observer_(observer) {
-}
+ : observer_(observer) {}
void ShellIntegration::DefaultWebClientWorker::StartCheckIsDefault() {
if (observer_) {
observer_->SetDefaultWebClientUIState(STATE_PROCESSING);
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
- base::Bind(
- &DefaultWebClientWorker::ExecuteCheckIsDefault, this));
+ base::Bind(&DefaultWebClientWorker::CheckIsDefault, this));
}
}
void ShellIntegration::DefaultWebClientWorker::StartSetAsDefault() {
+ // Cancel the already running process if another start is requested.
+ if (set_as_default_in_progress_)
+ OnSetAsDefaultAttemptComplete(false);
+
+ set_as_default_in_progress_ = true;
bool interactive_permitted = false;
if (observer_) {
observer_->SetDefaultWebClientUIState(STATE_PROCESSING);
interactive_permitted = observer_->IsInteractiveSetDefaultPermitted();
+
+ InitializeSetAsDefault();
}
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- base::Bind(&DefaultWebClientWorker::ExecuteSetAsDefault, this,
- interactive_permitted));
+
+ if (set_as_default_in_progress_)
+ BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
+ base::Bind(&DefaultWebClientWorker::SetAsDefault,
+ this, interactive_permitted));
}
void ShellIntegration::DefaultWebClientWorker::ObserverDestroyed() {
@@ -182,21 +205,20 @@ void ShellIntegration::DefaultWebClientWorker::ObserverDestroyed() {
// our worker thread returns after the view is dead.
DCHECK_CURRENTLY_ON(BrowserThread::UI);
observer_ = NULL;
+ // If an attempt to set the default browser is already in progress, its result
+ // won't be posted to any observers. Manually invoke
+ // OnSetAsDefaultAttemptComplete() to ensure we free the default browser
+ // callback and timer.
+ if (set_as_default_in_progress_)
+ OnSetAsDefaultAttemptComplete(false);
}
///////////////////////////////////////////////////////////////////////////////
// DefaultWebClientWorker, private:
-void ShellIntegration::DefaultWebClientWorker::ExecuteCheckIsDefault() {
- DCHECK_CURRENTLY_ON(BrowserThread::FILE);
- DefaultWebClientState state = CheckIsDefault();
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(
- &DefaultWebClientWorker::CompleteCheckIsDefault, this, state));
-}
+ShellIntegration::DefaultWebClientWorker::~DefaultWebClientWorker() {}
-void ShellIntegration::DefaultWebClientWorker::CompleteCheckIsDefault(
+void ShellIntegration::DefaultWebClientWorker::OnCheckIsDefaultComplete(
DefaultWebClientState state) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
UpdateUI(state);
@@ -208,26 +230,36 @@ void ShellIntegration::DefaultWebClientWorker::CompleteCheckIsDefault(
}
}
-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));
-}
-
-void ShellIntegration::DefaultWebClientWorker::CompleteSetAsDefault(
+void ShellIntegration::DefaultWebClientWorker::OnSetAsDefaultAttemptComplete(
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();
+ // Hold on to a reference because if this was called via the default browser
+ // callback in StartupBrowserCreator, clearing the callback in
+ // FinalizeSetAsDefault would otherwise remove the last reference and delete
+ // us in the middle of this function.
+ scoped_refptr<DefaultWebClientWorker> scoped_ref(this);
+
+ if (set_as_default_in_progress_) {
+ set_as_default_in_progress_ = false;
+
+ FinalizeSetAsDefault(succeeded);
+ if (observer_)
+ observer_->OnSetAsDefaultConcluded(succeeded);
+
+ // Start the default browser check which will notify the observer as to
+ // whether Chrome is really the default browser. This is needed because
+ // detecting that the process was successful is not 100% sure.
+ // For example, on Windows 10+, the user might have unchecked the "Always
+ // use this app" checkbox which can't be detected.
+ StartCheckIsDefault();
+ }
}
+void ShellIntegration::DefaultWebClientWorker::InitializeSetAsDefault() {}
+
+void ShellIntegration::DefaultWebClientWorker::FinalizeSetAsDefault(
+ bool succeeded) {}
+
void ShellIntegration::DefaultWebClientWorker::UpdateUI(
DefaultWebClientState state) {
if (observer_) {
@@ -256,18 +288,28 @@ ShellIntegration::DefaultBrowserWorker::DefaultBrowserWorker(
: DefaultWebClientWorker(observer) {
}
+ShellIntegration::DefaultBrowserWorker::~DefaultBrowserWorker() {
+ if (set_as_default_in_progress_)
+ OnSetAsDefaultAttemptComplete(false);
+}
+
///////////////////////////////////////////////////////////////////////////////
// DefaultBrowserWorker, private:
-ShellIntegration::DefaultWebClientState
-ShellIntegration::DefaultBrowserWorker::CheckIsDefault() {
- return ShellIntegration::GetDefaultBrowser();
+void ShellIntegration::DefaultBrowserWorker::CheckIsDefault() {
+ DefaultWebClientState state = ShellIntegration::GetDefaultBrowser();
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&DefaultBrowserWorker::OnCheckIsDefaultComplete, this, state));
}
-bool ShellIntegration::DefaultBrowserWorker::SetAsDefault(
+void ShellIntegration::DefaultBrowserWorker::SetAsDefault(
bool interactive_permitted) {
bool result = false;
switch (ShellIntegration::CanSetAsDefaultBrowser()) {
+ case ShellIntegration::SET_DEFAULT_NOT_ALLOWED:
+ NOTREACHED();
+ break;
case ShellIntegration::SET_DEFAULT_UNATTENDED:
result = ShellIntegration::SetAsDefaultBrowser();
break;
@@ -275,11 +317,18 @@ bool ShellIntegration::DefaultBrowserWorker::SetAsDefault(
if (interactive_permitted)
result = ShellIntegration::SetAsDefaultBrowserInteractive();
break;
- default:
- NOTREACHED();
+ case ShellIntegration::SET_DEFAULT_ASYNCHRONOUS:
+ if (!interactive_permitted)
+ break;
+ // This function will cause OnSetAsDefaultAttemptComplete() to be called
+ // asynchronously via a filter established in InitializeSetAsDefault().
+ ShellIntegration::SetAsDefaultBrowserAsynchronous();
+ return;
}
-
- return result;
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&DefaultBrowserWorker::OnSetAsDefaultAttemptComplete, this,
+ result));
}
///////////////////////////////////////////////////////////////////////////////
@@ -295,28 +344,39 @@ ShellIntegration::DefaultProtocolClientWorker::DefaultProtocolClientWorker(
///////////////////////////////////////////////////////////////////////////////
// DefaultProtocolClientWorker, private:
-ShellIntegration::DefaultWebClientState
-ShellIntegration::DefaultProtocolClientWorker::CheckIsDefault() {
- return ShellIntegration::IsDefaultProtocolClient(protocol_);
+ShellIntegration::DefaultProtocolClientWorker::~DefaultProtocolClientWorker() {}
+
+void ShellIntegration::DefaultProtocolClientWorker::CheckIsDefault() {
+ DefaultWebClientState state =
+ ShellIntegration::IsDefaultProtocolClient(protocol_);
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&DefaultProtocolClientWorker::OnCheckIsDefaultComplete, this,
+ state));
}
-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;
+ // Not allowed, do nothing.
break;
case ShellIntegration::SET_DEFAULT_UNATTENDED:
result = ShellIntegration::SetAsDefaultProtocolClient(protocol_);
break;
case ShellIntegration::SET_DEFAULT_INTERACTIVE:
if (interactive_permitted) {
- result = ShellIntegration::SetAsDefaultProtocolClientInteractive(
- protocol_);
+ result =
+ ShellIntegration::SetAsDefaultProtocolClientInteractive(protocol_);
}
break;
+ case ShellIntegration::SET_DEFAULT_ASYNCHRONOUS:
+ NOTREACHED();
+ break;
}
-
- return result;
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&DefaultProtocolClientWorker::OnSetAsDefaultAttemptComplete,
+ this, result));
}

Powered by Google App Engine
This is Rietveld 408576698