Commit 6d1171cb authored by Patrick Monette's avatar Patrick Monette Committed by Commit Bot

Simplify ProtocolHandlerRegistry::Delegate

This CL changes RegisterWithOSAsDefaultClient() and
CheckDefaultClientWithOS() to directly receive the callback
instead of calling GetDefaultWebClientCallback() on the
registry.

Bug: 1021600
Change-Id: Ic71173e91121f0f3576b38532e030227f3f23797
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1894698
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Reviewed-by: default avatarMartin Šrámek <msramek@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713514}
parent 4a7a0352
...@@ -505,10 +505,11 @@ class FakeProtocolHandlerRegistryDelegate ...@@ -505,10 +505,11 @@ class FakeProtocolHandlerRegistryDelegate
void RegisterWithOSAsDefaultClient( void RegisterWithOSAsDefaultClient(
const std::string& protocol, const std::string& protocol,
ProtocolHandlerRegistry* registry) override {} shell_integration::DefaultWebClientWorkerCallback callback) override {}
void CheckDefaultClientWithOS(const std::string& protocol, void CheckDefaultClientWithOS(
ProtocolHandlerRegistry* registry) override {} const std::string& protocol,
shell_integration::DefaultWebClientWorkerCallback callback) override {}
private: private:
std::set<std::string> registered_protocols_; std::set<std::string> registered_protocols_;
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#include "chrome/browser/browsing_data/counters/site_settings_counter.h" #include "chrome/browser/browsing_data/counters/site_settings_counter.h"
#include <memory> #include <memory>
#include <string>
#include <utility>
#include "base/bind.h" #include "base/bind.h"
#include "base/containers/flat_set.h" #include "base/containers/flat_set.h"
...@@ -54,18 +56,17 @@ class TestProtocolHandlerRegistryDelegate ...@@ -54,18 +56,17 @@ class TestProtocolHandlerRegistryDelegate
} }
void RegisterWithOSAsDefaultClient( void RegisterWithOSAsDefaultClient(
const std::string& protocol, const std::string& protocol,
ProtocolHandlerRegistry* registry) override { shell_integration::DefaultWebClientWorkerCallback callback) override {
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(registry->GetDefaultWebClientCallback(protocol), base::BindOnce(std::move(callback), shell_integration::NOT_DEFAULT));
shell_integration::NOT_DEFAULT));
} }
void CheckDefaultClientWithOS(const std::string& protocol, void CheckDefaultClientWithOS(
ProtocolHandlerRegistry* registry) override { const std::string& protocol,
shell_integration::DefaultWebClientWorkerCallback callback) override {
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(registry->GetDefaultWebClientCallback(protocol), base::BindOnce(std::move(callback), shell_integration::NOT_DEFAULT));
shell_integration::NOT_DEFAULT));
} }
private: private:
......
...@@ -95,23 +95,24 @@ bool ProtocolHandlerRegistry::Delegate::IsExternalHandlerRegistered( ...@@ -95,23 +95,24 @@ bool ProtocolHandlerRegistry::Delegate::IsExternalHandlerRegistered(
} }
void ProtocolHandlerRegistry::Delegate::RegisterWithOSAsDefaultClient( void ProtocolHandlerRegistry::Delegate::RegisterWithOSAsDefaultClient(
const std::string& protocol, ProtocolHandlerRegistry* registry) { const std::string& protocol,
shell_integration::DefaultWebClientWorkerCallback callback) {
// The worker pointer is reference counted. While it is running, the // The worker pointer is reference counted. While it is running, the
// sequence it runs on will hold references it will be automatically freed // sequence it runs on will hold references it will be automatically freed
// once all its tasks have finished. // once all its tasks have finished.
base::MakeRefCounted<shell_integration::DefaultProtocolClientWorker>( base::MakeRefCounted<shell_integration::DefaultProtocolClientWorker>(
registry->GetDefaultWebClientCallback(protocol), protocol) std::move(callback), protocol)
->StartSetAsDefault(); ->StartSetAsDefault();
} }
void ProtocolHandlerRegistry::Delegate::CheckDefaultClientWithOS( void ProtocolHandlerRegistry::Delegate::CheckDefaultClientWithOS(
const std::string& protocol, const std::string& protocol,
ProtocolHandlerRegistry* registry) { shell_integration::DefaultWebClientWorkerCallback callback) {
// The worker pointer is reference counted. While it is running, the // The worker pointer is reference counted. While it is running, the
// sequence it runs on will hold references it will be automatically freed // sequence it runs on will hold references it will be automatically freed
// once all its tasks have finished. // once all its tasks have finished.
base::MakeRefCounted<shell_integration::DefaultProtocolClientWorker>( base::MakeRefCounted<shell_integration::DefaultProtocolClientWorker>(
registry->GetDefaultWebClientCallback(protocol), protocol) std::move(callback), protocol)
->StartCheckIsDefault(); ->StartCheckIsDefault();
} }
...@@ -259,7 +260,9 @@ void ProtocolHandlerRegistry::InitProtocolSettings() { ...@@ -259,7 +260,9 @@ void ProtocolHandlerRegistry::InitProtocolSettings() {
if (ShouldRemoveHandlersNotInOS()) { if (ShouldRemoveHandlersNotInOS()) {
for (ProtocolHandlerMap::const_iterator p = default_handlers_.begin(); for (ProtocolHandlerMap::const_iterator p = default_handlers_.begin();
p != default_handlers_.end(); ++p) { p != default_handlers_.end(); ++p) {
delegate_->CheckDefaultClientWithOS(p->second.protocol(), this); const std::string& protocol = p->second.protocol();
delegate_->CheckDefaultClientWithOS(
protocol, GetDefaultWebClientCallback(protocol));
} }
} }
} }
...@@ -591,14 +594,17 @@ ProtocolHandlerRegistry::GetHandlerList( ...@@ -591,14 +594,17 @@ ProtocolHandlerRegistry::GetHandlerList(
void ProtocolHandlerRegistry::SetDefault(const ProtocolHandler& handler) { void ProtocolHandlerRegistry::SetDefault(const ProtocolHandler& handler) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
ProtocolHandlerMap::const_iterator p = default_handlers_.find(
handler.protocol()); const std::string& protocol = handler.protocol();
ProtocolHandlerMap::const_iterator p = default_handlers_.find(protocol);
// If we're not loading, and we are setting a default for a new protocol, // If we're not loading, and we are setting a default for a new protocol,
// register with the OS. // register with the OS.
if (!is_loading_ && p == default_handlers_.end()) if (!is_loading_ && p == default_handlers_.end())
delegate_->RegisterWithOSAsDefaultClient(handler.protocol(), this); delegate_->RegisterWithOSAsDefaultClient(
default_handlers_.erase(handler.protocol()); protocol, GetDefaultWebClientCallback(protocol));
default_handlers_.insert(std::make_pair(handler.protocol(), handler)); default_handlers_.erase(protocol);
default_handlers_.insert(std::make_pair(protocol, handler));
PromoteHandler(handler); PromoteHandler(handler);
} }
......
...@@ -52,9 +52,10 @@ class ProtocolHandlerRegistry : public KeyedService { ...@@ -52,9 +52,10 @@ class ProtocolHandlerRegistry : public KeyedService {
virtual bool IsExternalHandlerRegistered(const std::string& protocol); virtual bool IsExternalHandlerRegistered(const std::string& protocol);
virtual void RegisterWithOSAsDefaultClient( virtual void RegisterWithOSAsDefaultClient(
const std::string& protocol, const std::string& protocol,
ProtocolHandlerRegistry* registry); shell_integration::DefaultWebClientWorkerCallback callback);
virtual void CheckDefaultClientWithOS(const std::string& protocol, virtual void CheckDefaultClientWithOS(
ProtocolHandlerRegistry* registry); const std::string& protocol,
shell_integration::DefaultWebClientWorkerCallback callback);
}; };
class Observer : public base::CheckedObserver { class Observer : public base::CheckedObserver {
...@@ -194,11 +195,6 @@ class ProtocolHandlerRegistry : public KeyedService { ...@@ -194,11 +195,6 @@ class ProtocolHandlerRegistry : public KeyedService {
// load command was issued, otherwise the command will be ignored. // load command was issued, otherwise the command will be ignored.
void AddPredefinedHandler(const ProtocolHandler& handler); void AddPredefinedHandler(const ProtocolHandler& handler);
// Gets the callback for DefaultProtocolClientWorker. Allows the Delegate to
// create the worker on behalf of ProtocolHandlerRegistry.
shell_integration::DefaultWebClientWorkerCallback GetDefaultWebClientCallback(
const std::string& protocol);
private: private:
friend class base::DeleteHelper<ProtocolHandlerRegistry>; friend class base::DeleteHelper<ProtocolHandlerRegistry>;
friend struct content::BrowserThread::DeleteOnThread< friend struct content::BrowserThread::DeleteOnThread<
...@@ -294,6 +290,10 @@ class ProtocolHandlerRegistry : public KeyedService { ...@@ -294,6 +290,10 @@ class ProtocolHandlerRegistry : public KeyedService {
const std::string& protocol, const std::string& protocol,
shell_integration::DefaultWebClientState state); shell_integration::DefaultWebClientState state);
// Gets the callback for DefaultProtocolClientWorker.
shell_integration::DefaultWebClientWorkerCallback GetDefaultWebClientCallback(
const std::string& protocol);
// Map from protocols (strings) to protocol handlers. // Map from protocols (strings) to protocol handlers.
ProtocolHandlerMultiMap protocol_handlers_; ProtocolHandlerMultiMap protocol_handlers_;
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <memory> #include <memory>
#include <set> #include <set>
#include <utility>
#include "base/bind.h" #include "base/bind.h"
#include "base/run_loop.h" #include "base/run_loop.h"
...@@ -66,14 +67,14 @@ class FakeDelegate : public ProtocolHandlerRegistry::Delegate { ...@@ -66,14 +67,14 @@ class FakeDelegate : public ProtocolHandlerRegistry::Delegate {
void RegisterWithOSAsDefaultClient( void RegisterWithOSAsDefaultClient(
const std::string& protocol, const std::string& protocol,
ProtocolHandlerRegistry* registry) override { shell_integration::DefaultWebClientWorkerCallback callback) override {
// Do as-if the registration has to run on another sequence and post back // Do as-if the registration has to run on another sequence and post back
// the result with a task to the current thread. // the result with a task to the current thread.
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(registry->GetDefaultWebClientCallback(protocol), base::BindOnce(callback, force_os_failure_
force_os_failure_ ? shell_integration::NOT_DEFAULT ? shell_integration::NOT_DEFAULT
: shell_integration::IS_DEFAULT)); : shell_integration::IS_DEFAULT));
if (!force_os_failure_) if (!force_os_failure_)
os_registered_protocols_.insert(protocol); os_registered_protocols_.insert(protocol);
......
...@@ -863,7 +863,7 @@ class FakeDelegate : public ProtocolHandlerRegistry::Delegate { ...@@ -863,7 +863,7 @@ class FakeDelegate : public ProtocolHandlerRegistry::Delegate {
void RegisterWithOSAsDefaultClient( void RegisterWithOSAsDefaultClient(
const std::string& protocol, const std::string& protocol,
ProtocolHandlerRegistry* registry) override { shell_integration::DefaultWebClientWorkerCallback callback) override {
VLOG(1) << "Register With OS"; VLOG(1) << "Register With OS";
} }
}; };
......
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