Commit 8db6a8be authored by pmonette's avatar pmonette Committed by Commit bot

Fixes the interactive default browser UX for policy setting

This was caused by relying on the default implementation of
IsInteractiveSetDefaultPermitted(). This CL also replace this
function with an explicit member variable.

BUG=583317

Review URL: https://codereview.chromium.org/1657933003

Cr-Commit-Position: refs/heads/master@{#374831}
parent e735266d
...@@ -1196,8 +1196,17 @@ void BrowserProcessImpl::CreateGCMDriver() { ...@@ -1196,8 +1196,17 @@ void BrowserProcessImpl::CreateGCMDriver() {
void BrowserProcessImpl::ApplyDefaultBrowserPolicy() { void BrowserProcessImpl::ApplyDefaultBrowserPolicy() {
if (local_state()->GetBoolean(prefs::kDefaultBrowserSettingEnabled)) { if (local_state()->GetBoolean(prefs::kDefaultBrowserSettingEnabled)) {
// The worker pointer is reference counted. While it is running, the
// message loops of the FILE and UI thread will hold references to it
// and it will be automatically freed once all its tasks have finished.
scoped_refptr<shell_integration::DefaultWebClientWorker> scoped_refptr<shell_integration::DefaultWebClientWorker>
set_browser_worker = new shell_integration::DefaultBrowserWorker(NULL); set_browser_worker = new shell_integration::DefaultBrowserWorker(
nullptr,
/*delete_observer=*/false);
// The user interaction must always be disabled when applying the default
// browser policy since it is done at each browser startup and the result
// of the interaction cannot be forced.
set_browser_worker->set_interactive_permitted(false);
set_browser_worker->StartSetAsDefault(); set_browser_worker->StartSetAsDefault();
} }
} }
......
...@@ -261,20 +261,11 @@ void ProtocolHandlerRegistry::DefaultClientObserver::SetDefaultWebClientUIState( ...@@ -261,20 +261,11 @@ void ProtocolHandlerRegistry::DefaultClientObserver::SetDefaultWebClientUIState(
} }
} }
bool ProtocolHandlerRegistry::DefaultClientObserver::
IsInteractiveSetDefaultPermitted() {
return true;
}
void ProtocolHandlerRegistry::DefaultClientObserver::SetWorker( void ProtocolHandlerRegistry::DefaultClientObserver::SetWorker(
shell_integration::DefaultProtocolClientWorker* worker) { shell_integration::DefaultProtocolClientWorker* worker) {
worker_ = worker; worker_ = worker;
} }
bool ProtocolHandlerRegistry::DefaultClientObserver::IsOwnedByWorker() {
return true;
}
// Delegate -------------------------------------------------------------------- // Delegate --------------------------------------------------------------------
ProtocolHandlerRegistry::Delegate::~Delegate() {} ProtocolHandlerRegistry::Delegate::~Delegate() {}
...@@ -303,7 +294,8 @@ shell_integration::DefaultProtocolClientWorker* ...@@ -303,7 +294,8 @@ shell_integration::DefaultProtocolClientWorker*
ProtocolHandlerRegistry::Delegate::CreateShellWorker( ProtocolHandlerRegistry::Delegate::CreateShellWorker(
shell_integration::DefaultWebClientObserver* observer, shell_integration::DefaultWebClientObserver* observer,
const std::string& protocol) { const std::string& protocol) {
return new shell_integration::DefaultProtocolClientWorker(observer, protocol); return new shell_integration::DefaultProtocolClientWorker(
observer, protocol, /*delete_observer=*/true);
} }
ProtocolHandlerRegistry::DefaultClientObserver* ProtocolHandlerRegistry::DefaultClientObserver*
...@@ -315,7 +307,7 @@ ProtocolHandlerRegistry::Delegate::CreateShellObserver( ...@@ -315,7 +307,7 @@ ProtocolHandlerRegistry::Delegate::CreateShellObserver(
void ProtocolHandlerRegistry::Delegate::RegisterWithOSAsDefaultClient( void ProtocolHandlerRegistry::Delegate::RegisterWithOSAsDefaultClient(
const std::string& protocol, ProtocolHandlerRegistry* registry) { const std::string& protocol, ProtocolHandlerRegistry* registry) {
DefaultClientObserver* observer = CreateShellObserver(registry); DefaultClientObserver* observer = CreateShellObserver(registry);
// The worker pointer is reference counted. While it is running the // The worker pointer is reference counted. While it is running, the
// message loops of the FILE and UI thread will hold references to it // message loops of the FILE and UI thread will hold references to it
// and it will be automatically freed once all its tasks have finished. // and it will be automatically freed once all its tasks have finished.
scoped_refptr<shell_integration::DefaultProtocolClientWorker> worker; scoped_refptr<shell_integration::DefaultProtocolClientWorker> worker;
......
...@@ -53,8 +53,6 @@ class ProtocolHandlerRegistry : public KeyedService { ...@@ -53,8 +53,6 @@ class ProtocolHandlerRegistry : public KeyedService {
void SetDefaultWebClientUIState( void SetDefaultWebClientUIState(
shell_integration::DefaultWebClientUIState state) override; shell_integration::DefaultWebClientUIState state) override;
bool IsInteractiveSetDefaultPermitted() override;
// Give the observer a handle to the worker, so we can find out the protocol // Give the observer a handle to the worker, so we can find out the protocol
// when we're called and also tell the worker if we get deleted. // when we're called and also tell the worker if we get deleted.
void SetWorker(shell_integration::DefaultProtocolClientWorker* worker); void SetWorker(shell_integration::DefaultProtocolClientWorker* worker);
...@@ -63,8 +61,6 @@ class ProtocolHandlerRegistry : public KeyedService { ...@@ -63,8 +61,6 @@ class ProtocolHandlerRegistry : public KeyedService {
shell_integration::DefaultProtocolClientWorker* worker_; shell_integration::DefaultProtocolClientWorker* worker_;
private: private:
bool IsOwnedByWorker() override;
// This is a raw pointer, not reference counted, intentionally. In general // This is a raw pointer, not reference counted, intentionally. In general
// subclasses of DefaultWebClientObserver are not able to be refcounted // subclasses of DefaultWebClientObserver are not able to be refcounted
// e.g. the browser options page // e.g. the browser options page
......
...@@ -224,7 +224,10 @@ class FakeProtocolClientWorker ...@@ -224,7 +224,10 @@ class FakeProtocolClientWorker
shell_integration::DefaultWebClientObserver* observer, shell_integration::DefaultWebClientObserver* observer,
const std::string& protocol, const std::string& protocol,
bool force_failure) bool force_failure)
: shell_integration::DefaultProtocolClientWorker(observer, protocol), : shell_integration::DefaultProtocolClientWorker(
observer,
protocol,
/*delete_observer*/ true),
force_failure_(force_failure) {} force_failure_(force_failure) {}
private: private:
...@@ -242,7 +245,7 @@ class FakeProtocolClientWorker ...@@ -242,7 +245,7 @@ class FakeProtocolClientWorker
state)); state));
} }
void SetAsDefault(bool interactive_permitted) override { void SetAsDefault() override {
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE, BrowserThread::UI, FROM_HERE,
base::Bind(&FakeProtocolClientWorker::OnSetAsDefaultAttemptComplete, base::Bind(&FakeProtocolClientWorker::OnSetAsDefaultAttemptComplete,
......
...@@ -38,14 +38,16 @@ static bool g_accept_requests = true; ...@@ -38,14 +38,16 @@ static bool g_accept_requests = true;
namespace { namespace {
// Functions enabling unit testing. Using a NULL delegate will use the default // Functions enabling unit testing. Using a NULL delegate will use the default
// behavior; if a delegate is provided it will be used instead. // behavior; if a delegate is provided it will be used instead. Also, Ownership
// of |observer| is passed to the new worker.
shell_integration::DefaultProtocolClientWorker* CreateShellWorker( shell_integration::DefaultProtocolClientWorker* CreateShellWorker(
shell_integration::DefaultWebClientObserver* observer, shell_integration::DefaultWebClientObserver* observer,
const std::string& protocol, const std::string& protocol,
ExternalProtocolHandler::Delegate* delegate) { ExternalProtocolHandler::Delegate* delegate) {
if (!delegate) if (!delegate)
return new shell_integration::DefaultProtocolClientWorker(observer, return new shell_integration::DefaultProtocolClientWorker(
protocol); observer, protocol,
/*delete_observer=*/true);
return delegate->CreateShellWorker(observer, protocol); return delegate->CreateShellWorker(observer, protocol);
} }
...@@ -146,8 +148,6 @@ class ExternalDefaultProtocolObserver ...@@ -146,8 +148,6 @@ class ExternalDefaultProtocolObserver
escaped_url_, render_process_host_id_, tab_contents_id_, delegate_); escaped_url_, render_process_host_id_, tab_contents_id_, delegate_);
} }
bool IsOwnedByWorker() override { return true; }
private: private:
ExternalProtocolHandler::Delegate* delegate_; ExternalProtocolHandler::Delegate* delegate_;
const GURL escaped_url_; const GURL escaped_url_;
......
...@@ -17,7 +17,10 @@ class FakeExternalProtocolHandlerWorker ...@@ -17,7 +17,10 @@ class FakeExternalProtocolHandlerWorker
shell_integration::DefaultWebClientObserver* observer, shell_integration::DefaultWebClientObserver* observer,
const std::string& protocol, const std::string& protocol,
shell_integration::DefaultWebClientState os_state) shell_integration::DefaultWebClientState os_state)
: shell_integration::DefaultProtocolClientWorker(observer, protocol), : shell_integration::DefaultProtocolClientWorker(
observer,
protocol,
/*delete_observer=*/true),
os_state_(os_state) {} os_state_(os_state) {}
private: private:
...@@ -30,7 +33,7 @@ class FakeExternalProtocolHandlerWorker ...@@ -30,7 +33,7 @@ class FakeExternalProtocolHandlerWorker
this, os_state_)); this, os_state_));
} }
void SetAsDefault(bool interactive_permitted) override { void SetAsDefault() override {
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE, BrowserThread::UI, FROM_HERE,
base::Bind( base::Bind(
......
...@@ -146,25 +146,14 @@ base::string16 GetAppShortcutsSubdirName() { ...@@ -146,25 +146,14 @@ base::string16 GetAppShortcutsSubdirName() {
} }
#endif // !defined(OS_WIN) #endif // !defined(OS_WIN)
///////////////////////////////////////////////////////////////////////////////
// DefaultWebClientObserver
//
bool DefaultWebClientObserver::IsOwnedByWorker() {
return false;
}
bool DefaultWebClientObserver::IsInteractiveSetDefaultPermitted() {
return false;
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// DefaultWebClientWorker // DefaultWebClientWorker
// //
DefaultWebClientWorker::DefaultWebClientWorker( DefaultWebClientWorker::DefaultWebClientWorker(
DefaultWebClientObserver* observer) DefaultWebClientObserver* observer,
: observer_(observer) {} bool delete_observer)
: observer_(observer), delete_observer_(delete_observer) {}
void DefaultWebClientWorker::StartCheckIsDefault() { void DefaultWebClientWorker::StartCheckIsDefault() {
if (observer_) if (observer_)
...@@ -187,20 +176,17 @@ void DefaultWebClientWorker::StartSetAsDefault() { ...@@ -187,20 +176,17 @@ void DefaultWebClientWorker::StartSetAsDefault() {
} }
set_as_default_in_progress_ = true; set_as_default_in_progress_ = true;
bool interactive_permitted = true; if (observer_)
if (observer_) {
observer_->SetDefaultWebClientUIState(STATE_PROCESSING); observer_->SetDefaultWebClientUIState(STATE_PROCESSING);
interactive_permitted = observer_->IsInteractiveSetDefaultPermitted();
}
set_as_default_initialized_ = InitializeSetAsDefault(); set_as_default_initialized_ = InitializeSetAsDefault();
// Remember the start time. // Remember the start time.
start_time_ = base::TimeTicks::Now(); start_time_ = base::TimeTicks::Now();
BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, BrowserThread::PostTask(
base::Bind(&DefaultWebClientWorker::SetAsDefault, BrowserThread::FILE, FROM_HERE,
this, interactive_permitted)); base::Bind(&DefaultWebClientWorker::SetAsDefault, this));
} }
void DefaultWebClientWorker::ObserverDestroyed() { void DefaultWebClientWorker::ObserverDestroyed() {
...@@ -238,7 +224,7 @@ void DefaultWebClientWorker::OnCheckIsDefaultComplete( ...@@ -238,7 +224,7 @@ void DefaultWebClientWorker::OnCheckIsDefaultComplete(
// The worker has finished everything it needs to do, so free the observer // The worker has finished everything it needs to do, so free the observer
// if we own it. // if we own it.
if (observer_ && observer_->IsOwnedByWorker()) { if (observer_ && delete_observer_) {
delete observer_; delete observer_;
observer_ = nullptr; observer_ = nullptr;
} }
...@@ -363,8 +349,9 @@ const char* DefaultWebClientWorker::AttemptResultToString( ...@@ -363,8 +349,9 @@ const char* DefaultWebClientWorker::AttemptResultToString(
// DefaultBrowserWorker // DefaultBrowserWorker
// //
DefaultBrowserWorker::DefaultBrowserWorker(DefaultWebClientObserver* observer) DefaultBrowserWorker::DefaultBrowserWorker(DefaultWebClientObserver* observer,
: DefaultWebClientWorker(observer) {} bool delete_observer)
: DefaultWebClientWorker(observer, delete_observer) {}
DefaultBrowserWorker::~DefaultBrowserWorker() {} DefaultBrowserWorker::~DefaultBrowserWorker() {}
...@@ -378,7 +365,7 @@ void DefaultBrowserWorker::CheckIsDefault() { ...@@ -378,7 +365,7 @@ void DefaultBrowserWorker::CheckIsDefault() {
base::Bind(&DefaultBrowserWorker::OnCheckIsDefaultComplete, this, state)); base::Bind(&DefaultBrowserWorker::OnCheckIsDefaultComplete, this, state));
} }
void DefaultBrowserWorker::SetAsDefault(bool interactive_permitted) { void DefaultBrowserWorker::SetAsDefault() {
AttemptResult result = AttemptResult::FAILURE; AttemptResult result = AttemptResult::FAILURE;
switch (CanSetAsDefaultBrowser()) { switch (CanSetAsDefaultBrowser()) {
case SET_DEFAULT_NOT_ALLOWED: case SET_DEFAULT_NOT_ALLOWED:
...@@ -389,12 +376,12 @@ void DefaultBrowserWorker::SetAsDefault(bool interactive_permitted) { ...@@ -389,12 +376,12 @@ void DefaultBrowserWorker::SetAsDefault(bool interactive_permitted) {
result = AttemptResult::SUCCESS; result = AttemptResult::SUCCESS;
break; break;
case SET_DEFAULT_INTERACTIVE: case SET_DEFAULT_INTERACTIVE:
if (interactive_permitted && SetAsDefaultBrowserInteractive()) if (interactive_permitted_ && SetAsDefaultBrowserInteractive())
result = AttemptResult::SUCCESS; result = AttemptResult::SUCCESS;
break; break;
case SET_DEFAULT_ASYNCHRONOUS: case SET_DEFAULT_ASYNCHRONOUS:
#if defined(OS_WIN) #if defined(OS_WIN)
if (!interactive_permitted) if (!interactive_permitted_)
break; break;
if (GetDefaultBrowser() == IS_DEFAULT) { if (GetDefaultBrowser() == IS_DEFAULT) {
// Don't start the asynchronous operation since it could result in // Don't start the asynchronous operation since it could result in
...@@ -430,8 +417,9 @@ const char* DefaultBrowserWorker::GetHistogramPrefix() { ...@@ -430,8 +417,9 @@ const char* DefaultBrowserWorker::GetHistogramPrefix() {
DefaultProtocolClientWorker::DefaultProtocolClientWorker( DefaultProtocolClientWorker::DefaultProtocolClientWorker(
DefaultWebClientObserver* observer, DefaultWebClientObserver* observer,
const std::string& protocol) const std::string& protocol,
: DefaultWebClientWorker(observer), protocol_(protocol) {} bool delete_observer)
: DefaultWebClientWorker(observer, delete_observer), protocol_(protocol) {}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// DefaultProtocolClientWorker, private: // DefaultProtocolClientWorker, private:
...@@ -446,7 +434,7 @@ void DefaultProtocolClientWorker::CheckIsDefault() { ...@@ -446,7 +434,7 @@ void DefaultProtocolClientWorker::CheckIsDefault() {
state)); state));
} }
void DefaultProtocolClientWorker::SetAsDefault(bool interactive_permitted) { void DefaultProtocolClientWorker::SetAsDefault() {
AttemptResult result = AttemptResult::FAILURE; AttemptResult result = AttemptResult::FAILURE;
switch (CanSetAsDefaultProtocolClient()) { switch (CanSetAsDefaultProtocolClient()) {
case SET_DEFAULT_NOT_ALLOWED: case SET_DEFAULT_NOT_ALLOWED:
...@@ -457,7 +445,7 @@ void DefaultProtocolClientWorker::SetAsDefault(bool interactive_permitted) { ...@@ -457,7 +445,7 @@ void DefaultProtocolClientWorker::SetAsDefault(bool interactive_permitted) {
result = AttemptResult::SUCCESS; result = AttemptResult::SUCCESS;
break; break;
case SET_DEFAULT_INTERACTIVE: case SET_DEFAULT_INTERACTIVE:
if (interactive_permitted && if (interactive_permitted_ &&
SetAsDefaultProtocolClientInteractive(protocol_)) { SetAsDefaultProtocolClientInteractive(protocol_)) {
result = AttemptResult::SUCCESS; result = AttemptResult::SUCCESS;
} }
......
...@@ -197,12 +197,6 @@ class DefaultWebClientObserver { ...@@ -197,12 +197,6 @@ class DefaultWebClientObserver {
// Called to notify the UI of the immediate result of invoking // Called to notify the UI of the immediate result of invoking
// SetAsDefault. // SetAsDefault.
virtual void OnSetAsDefaultConcluded(bool succeeded) {} virtual void OnSetAsDefaultConcluded(bool succeeded) {}
// Observer classes that return true to OwnedByWorker are automatically
// freed by the worker when they are no longer needed. False by default.
virtual bool IsOwnedByWorker();
// An observer can permit or decline set-as-default operation if it
// requires triggering user interaction. By default not allowed.
virtual bool IsInteractiveSetDefaultPermitted();
}; };
// Helper objects that handle checking if Chrome is the default browser // Helper objects that handle checking if Chrome is the default browser
...@@ -210,10 +204,25 @@ class DefaultWebClientObserver { ...@@ -210,10 +204,25 @@ class DefaultWebClientObserver {
// it as the default. These operations are performed asynchronously on the // it as the default. These operations are performed asynchronously on the
// file thread since registry access (on Windows) or the preference database // file thread since registry access (on Windows) or the preference database
// (on Linux) are involved and this can be slow. // (on Linux) are involved and this can be slow.
// By default, the worker will present the user with an interactive flow if
// required by the platform. This can be suppressed via
// set_interactive_permitted(), in which case an attempt to set Chrome as
// the default handler will silently fail on such platforms.
class DefaultWebClientWorker class DefaultWebClientWorker
: public base::RefCountedThreadSafe<DefaultWebClientWorker> { : public base::RefCountedThreadSafe<DefaultWebClientWorker> {
public: public:
explicit DefaultWebClientWorker(DefaultWebClientObserver* observer); // Constructor. The worker will post updates to |observer|. If
// |delete_observer| is true, the worker owns the observer and it will be
// freed in the destructor.
DefaultWebClientWorker(DefaultWebClientObserver* observer,
bool delete_observer);
// Controls whether the worker can use user interaction to set the default
// web client. If false, the set-as-default operation will fail on OS where
// it is required.
void set_interactive_permitted(bool interactive_permitted) {
interactive_permitted_ = interactive_permitted;
}
// Checks to see if Chrome is the default web client application. The result // Checks to see if Chrome is the default web client application. The result
// will be passed back to the observer via the SetDefaultWebClientUIState // will be passed back to the observer via the SetDefaultWebClientUIState
...@@ -277,6 +286,10 @@ class DefaultWebClientWorker ...@@ -277,6 +286,10 @@ class DefaultWebClientWorker
return set_as_default_initialized_; return set_as_default_initialized_;
} }
// When false, the operation to set as default will fail for interactive
// flows.
bool interactive_permitted_ = true;
// Flag that indicates if the set-as-default operation is in progess to // Flag that indicates if the set-as-default operation is in progess to
// prevent multiple notifications to the observer. // prevent multiple notifications to the observer.
bool set_as_default_in_progress_ = false; bool set_as_default_in_progress_ = false;
...@@ -288,10 +301,9 @@ class DefaultWebClientWorker ...@@ -288,10 +301,9 @@ class DefaultWebClientWorker
virtual void CheckIsDefault() = 0; virtual void CheckIsDefault() = 0;
// Sets Chrome as the default web client. Always called on the FILE thread. // Sets Chrome as the default web client. Always called on the FILE thread.
// |interactive_permitted| will make SetAsDefault() fail if it requires // Subclasses are responsible for calling OnSetAsDefaultAttemptComplete() on
// interaction with the user. Subclasses are responsible for calling // the UI thread.
// OnSetAsDefaultAttemptComplete() on the UI thread. virtual void SetAsDefault() = 0;
virtual void SetAsDefault(bool interactive_permitted) = 0;
// Returns the prefix used for metrics to differentiate UMA metrics for // Returns the prefix used for metrics to differentiate UMA metrics for
// setting the default browser and setting the default protocol client. // setting the default browser and setting the default protocol client.
...@@ -321,6 +333,9 @@ class DefaultWebClientWorker ...@@ -321,6 +333,9 @@ class DefaultWebClientWorker
DefaultWebClientObserver* observer_; DefaultWebClientObserver* observer_;
// Indicates if the the observer will be automatically freed by the worker.
bool delete_observer_;
// Flag that indicates the return value of InitializeSetAsDefault(). If // Flag that indicates the return value of InitializeSetAsDefault(). If
// true, FinalizeSetAsDefault() will be called to clear what was // true, FinalizeSetAsDefault() will be called to clear what was
// initialized. // initialized.
...@@ -339,7 +354,11 @@ class DefaultWebClientWorker ...@@ -339,7 +354,11 @@ class DefaultWebClientWorker
// Worker for checking and setting the default browser. // Worker for checking and setting the default browser.
class DefaultBrowserWorker : public DefaultWebClientWorker { class DefaultBrowserWorker : public DefaultWebClientWorker {
public: public:
explicit DefaultBrowserWorker(DefaultWebClientObserver* observer); // Constructor. The worker will post updates to |observer|. If
// |delete_observer| is true, the worker owns the observer and it will be
// freed in the destructor.
DefaultBrowserWorker(DefaultWebClientObserver* observer,
bool delete_observer);
private: private:
~DefaultBrowserWorker() override; ~DefaultBrowserWorker() override;
...@@ -348,7 +367,7 @@ class DefaultBrowserWorker : public DefaultWebClientWorker { ...@@ -348,7 +367,7 @@ class DefaultBrowserWorker : public DefaultWebClientWorker {
void CheckIsDefault() override; void CheckIsDefault() override;
// Set Chrome as the default browser. // Set Chrome as the default browser.
void SetAsDefault(bool interactive_permitted) override; void SetAsDefault() override;
// Returns the histogram prefix for DefaultBrowserWorker. // Returns the histogram prefix for DefaultBrowserWorker.
const char* GetHistogramPrefix() override; const char* GetHistogramPrefix() override;
...@@ -379,8 +398,12 @@ class DefaultBrowserWorker : public DefaultWebClientWorker { ...@@ -379,8 +398,12 @@ class DefaultBrowserWorker : public DefaultWebClientWorker {
// multiple protocols you should use multiple worker objects. // multiple protocols you should use multiple worker objects.
class DefaultProtocolClientWorker : public DefaultWebClientWorker { class DefaultProtocolClientWorker : public DefaultWebClientWorker {
public: public:
// Constructor. The worker will post updates to |observer|. If
// |delete_observer| is true, the worker owns the observer and it will be
// freed in the destructor.
DefaultProtocolClientWorker(DefaultWebClientObserver* observer, DefaultProtocolClientWorker(DefaultWebClientObserver* observer,
const std::string& protocol); const std::string& protocol,
bool delete_observer);
const std::string& protocol() const { return protocol_; } const std::string& protocol() const { return protocol_; }
...@@ -392,7 +415,7 @@ class DefaultProtocolClientWorker : public DefaultWebClientWorker { ...@@ -392,7 +415,7 @@ class DefaultProtocolClientWorker : public DefaultWebClientWorker {
void CheckIsDefault() override; void CheckIsDefault() override;
// Set Chrome as the default handler for this protocol. // Set Chrome as the default handler for this protocol.
void SetAsDefault(bool interactive_permitted) override; void SetAsDefault() override;
// Returns the histogram prefix for DefaultProtocolClientWorker. // Returns the histogram prefix for DefaultProtocolClientWorker.
const char* GetHistogramPrefix() override; const char* GetHistogramPrefix() override;
......
...@@ -110,8 +110,6 @@ class OpenURLFromTabBasedOnBrowserDefault ...@@ -110,8 +110,6 @@ class OpenURLFromTabBasedOnBrowserDefault
} }
} }
bool IsOwnedByWorker() override { return true; }
private: private:
scoped_ptr<content::WebContents> source_; scoped_ptr<content::WebContents> source_;
const content::OpenURLParams params_; const content::OpenURLParams params_;
...@@ -158,7 +156,8 @@ ChromeAppDelegate::NewWindowContentsDelegate::OpenURLFromTab( ...@@ -158,7 +156,8 @@ ChromeAppDelegate::NewWindowContentsDelegate::OpenURLFromTab(
check_if_default_browser_worker = check_if_default_browser_worker =
new shell_integration::DefaultBrowserWorker( new shell_integration::DefaultBrowserWorker(
new OpenURLFromTabBasedOnBrowserDefault(std::move(owned_source), new OpenURLFromTabBasedOnBrowserDefault(std::move(owned_source),
params)); params),
/*delete_observer=*/true);
// Object lifetime notes: The OpenURLFromTabBasedOnBrowserDefault is owned // Object lifetime notes: The OpenURLFromTabBasedOnBrowserDefault is owned
// by check_if_default_browser_worker. StartCheckIsDefault() takes lifetime // by check_if_default_browser_worker. StartCheckIsDefault() takes lifetime
// ownership of check_if_default_browser_worker and will clean up after // ownership of check_if_default_browser_worker and will clean up after
......
...@@ -176,8 +176,12 @@ bool DefaultBrowserInfoBarDelegate::Accept() { ...@@ -176,8 +176,12 @@ bool DefaultBrowserInfoBarDelegate::Accept() {
UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction", UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction",
InfoBarUserInteraction::START_SET_AS_DEFAULT, InfoBarUserInteraction::START_SET_AS_DEFAULT,
NUM_INFO_BAR_USER_INTERACTION_TYPES); NUM_INFO_BAR_USER_INTERACTION_TYPES);
// The worker pointer is reference counted. While it is running, the
// message loops of the FILE and UI thread will hold references to it
// and it will be automatically freed once all its tasks have finished.
scoped_refptr<shell_integration::DefaultBrowserWorker>( scoped_refptr<shell_integration::DefaultBrowserWorker>(
new shell_integration::DefaultBrowserWorker(nullptr)) new shell_integration::DefaultBrowserWorker(nullptr,
/*delete_observer=*/false))
->StartSetAsDefault(); ->StartSetAsDefault();
return true; return true;
} }
...@@ -208,7 +212,6 @@ class CheckDefaultBrowserObserver ...@@ -208,7 +212,6 @@ class CheckDefaultBrowserObserver
private: private:
void SetDefaultWebClientUIState( void SetDefaultWebClientUIState(
shell_integration::DefaultWebClientUIState state) override; shell_integration::DefaultWebClientUIState state) override;
bool IsOwnedByWorker() override;
void ResetCheckDefaultBrowserPref(); void ResetCheckDefaultBrowserPref();
void ShowPrompt(); void ShowPrompt();
...@@ -242,11 +245,6 @@ void CheckDefaultBrowserObserver::SetDefaultWebClientUIState( ...@@ -242,11 +245,6 @@ void CheckDefaultBrowserObserver::SetDefaultWebClientUIState(
} }
} }
bool CheckDefaultBrowserObserver::IsOwnedByWorker() {
// Instruct the DefaultBrowserWorker to delete this instance when it is done.
return true;
}
void CheckDefaultBrowserObserver::ResetCheckDefaultBrowserPref() { void CheckDefaultBrowserObserver::ResetCheckDefaultBrowserPref() {
Profile* profile = Profile* profile =
g_browser_process->profile_manager()->GetProfileByPath(profile_path_); g_browser_process->profile_manager()->GetProfileByPath(profile_path_);
...@@ -317,7 +315,8 @@ void ShowDefaultBrowserPrompt(Profile* profile) { ...@@ -317,7 +315,8 @@ void ShowDefaultBrowserPrompt(Profile* profile) {
scoped_refptr<shell_integration::DefaultBrowserWorker>( scoped_refptr<shell_integration::DefaultBrowserWorker>(
new shell_integration::DefaultBrowserWorker( new shell_integration::DefaultBrowserWorker(
new CheckDefaultBrowserObserver(profile->GetPath(), show_prompt))) new CheckDefaultBrowserObserver(profile->GetPath(), show_prompt),
/*delete_observer=*/true))
->StartCheckIsDefault(); ->StartCheckIsDefault();
} }
......
...@@ -186,7 +186,11 @@ BrowserOptionsHandler::BrowserOptionsHandler() ...@@ -186,7 +186,11 @@ BrowserOptionsHandler::BrowserOptionsHandler()
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
signin_observer_(this), signin_observer_(this),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
default_browser_worker_ = new shell_integration::DefaultBrowserWorker(this); // The worker pointer is reference counted. While it is running, the
// message loops of the FILE and UI thread will hold references to it
// and it will be automatically freed once all its tasks have finished.
default_browser_worker_ = new shell_integration::DefaultBrowserWorker(
this, /*delete_observer=*/false);
#if defined(ENABLE_SERVICE_DISCOVERY) #if defined(ENABLE_SERVICE_DISCOVERY)
cloud_print_mdns_ui_enabled_ = true; cloud_print_mdns_ui_enabled_ = true;
...@@ -1144,10 +1148,6 @@ void BrowserOptionsHandler::SetDefaultWebClientUIState( ...@@ -1144,10 +1148,6 @@ void BrowserOptionsHandler::SetDefaultWebClientUIState(
SetDefaultBrowserUIString(status_string_id); SetDefaultBrowserUIString(status_string_id);
} }
bool BrowserOptionsHandler::IsInteractiveSetDefaultPermitted() {
return true; // This is UI so we can allow it.
}
void BrowserOptionsHandler::SetDefaultBrowserUIString(int status_string_id) { void BrowserOptionsHandler::SetDefaultBrowserUIString(int status_string_id) {
base::StringValue status_string( base::StringValue status_string(
l10n_util::GetStringFUTF16(status_string_id, l10n_util::GetStringFUTF16(status_string_id,
......
...@@ -94,7 +94,6 @@ class BrowserOptionsHandler ...@@ -94,7 +94,6 @@ class BrowserOptionsHandler
// shell_integration::DefaultWebClientObserver implementation. // shell_integration::DefaultWebClientObserver implementation.
void SetDefaultWebClientUIState( void SetDefaultWebClientUIState(
shell_integration::DefaultWebClientUIState state) override; shell_integration::DefaultWebClientUIState state) override;
bool IsInteractiveSetDefaultPermitted() override;
// TemplateURLServiceObserver implementation. // TemplateURLServiceObserver implementation.
void OnTemplateURLServiceChanged() override; void OnTemplateURLServiceChanged() override;
......
...@@ -109,7 +109,6 @@ class SetAsDefaultBrowserHandler ...@@ -109,7 +109,6 @@ class SetAsDefaultBrowserHandler
void SetDefaultWebClientUIState( void SetDefaultWebClientUIState(
shell_integration::DefaultWebClientUIState state) override; shell_integration::DefaultWebClientUIState state) override;
void OnSetAsDefaultConcluded(bool close_chrome) override; void OnSetAsDefaultConcluded(bool close_chrome) override;
bool IsInteractiveSetDefaultPermitted() override;
private: private:
// Handler for the 'Next' (or 'make Chrome the Metro browser') button. // Handler for the 'Next' (or 'make Chrome the Metro browser') button.
...@@ -118,6 +117,9 @@ class SetAsDefaultBrowserHandler ...@@ -118,6 +117,9 @@ class SetAsDefaultBrowserHandler
// Close this web ui. // Close this web ui.
void ConcludeInteraction(MakeChromeDefaultResult interaction_result); void ConcludeInteraction(MakeChromeDefaultResult interaction_result);
// The worker pointer is reference counted. While it is running, the
// message loops of the FILE and UI thread will hold references to it
// and it will be automatically freed once all its tasks have finished.
scoped_refptr<shell_integration::DefaultBrowserWorker> scoped_refptr<shell_integration::DefaultBrowserWorker>
default_browser_worker_; default_browser_worker_;
bool set_default_returned_; bool set_default_returned_;
...@@ -129,8 +131,9 @@ class SetAsDefaultBrowserHandler ...@@ -129,8 +131,9 @@ class SetAsDefaultBrowserHandler
SetAsDefaultBrowserHandler::SetAsDefaultBrowserHandler( SetAsDefaultBrowserHandler::SetAsDefaultBrowserHandler(
const base::WeakPtr<ResponseDelegate>& response_delegate) const base::WeakPtr<ResponseDelegate>& response_delegate)
: default_browser_worker_( : default_browser_worker_(new shell_integration::DefaultBrowserWorker(
new shell_integration::DefaultBrowserWorker(this)), this,
/*delete_observer=*/false)),
set_default_returned_(false), set_default_returned_(false),
set_default_result_(false), set_default_result_(false),
response_delegate_(response_delegate) {} response_delegate_(response_delegate) {}
...@@ -171,10 +174,6 @@ void SetAsDefaultBrowserHandler::OnSetAsDefaultConcluded(bool call_result) { ...@@ -171,10 +174,6 @@ void SetAsDefaultBrowserHandler::OnSetAsDefaultConcluded(bool call_result) {
set_default_result_ = call_result; set_default_result_ = call_result;
} }
bool SetAsDefaultBrowserHandler::IsInteractiveSetDefaultPermitted() {
return true;
}
void SetAsDefaultBrowserHandler::HandleLaunchSetDefaultBrowserFlow( void SetAsDefaultBrowserHandler::HandleLaunchSetDefaultBrowserFlow(
const base::ListValue* args) { const base::ListValue* args) {
set_default_returned_ = false; set_default_returned_ = false;
......
...@@ -13,8 +13,9 @@ ...@@ -13,8 +13,9 @@
namespace settings { namespace settings {
DefaultBrowserHandler::DefaultBrowserHandler(content::WebUI* webui) DefaultBrowserHandler::DefaultBrowserHandler(content::WebUI* webui)
: default_browser_worker_( : default_browser_worker_(new shell_integration::DefaultBrowserWorker(
new shell_integration::DefaultBrowserWorker(this)) { this,
/*delete_observer=*/false)) {
default_browser_policy_.Init( default_browser_policy_.Init(
prefs::kDefaultBrowserSettingEnabled, g_browser_process->local_state(), prefs::kDefaultBrowserSettingEnabled, g_browser_process->local_state(),
base::Bind(&DefaultBrowserHandler::RequestDefaultBrowserState, base::Bind(&DefaultBrowserHandler::RequestDefaultBrowserState,
...@@ -60,10 +61,6 @@ void DefaultBrowserHandler::SetDefaultWebClientUIState( ...@@ -60,10 +61,6 @@ void DefaultBrowserHandler::SetDefaultWebClientUIState(
is_default, can_be_default); is_default, can_be_default);
} }
bool DefaultBrowserHandler::IsInteractiveSetDefaultPermitted() {
return true;
}
void DefaultBrowserHandler::OnSetAsDefaultConcluded(bool succeeded) { void DefaultBrowserHandler::OnSetAsDefaultConcluded(bool succeeded) {
base::FundamentalValue success(succeeded); base::FundamentalValue success(succeeded);
web_ui()->CallJavascriptFunction("Settings.setAsDefaultConcluded", success); web_ui()->CallJavascriptFunction("Settings.setAsDefaultConcluded", success);
......
...@@ -37,7 +37,6 @@ class DefaultBrowserHandler ...@@ -37,7 +37,6 @@ class DefaultBrowserHandler
// shell_integration::DefaultWebClientObserver implementation. // shell_integration::DefaultWebClientObserver implementation.
void SetDefaultWebClientUIState( void SetDefaultWebClientUIState(
shell_integration::DefaultWebClientUIState state) override; shell_integration::DefaultWebClientUIState state) override;
bool IsInteractiveSetDefaultPermitted() override;
void OnSetAsDefaultConcluded(bool succeeded) override; void OnSetAsDefaultConcluded(bool succeeded) override;
private: private:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment