Simplify ContentHandlerFactory a bit. On the road to nuking the class itself. Now you don't even need to instantiate it anymore. R=vardhan@google.com Review URL: https://codereview.chromium.org/1993053002 .
diff --git a/examples/forwarding_content_handler/forwarding_content_handler.cc b/examples/forwarding_content_handler/forwarding_content_handler.cc index 91e9d35..cfc284a 100644 --- a/examples/forwarding_content_handler/forwarding_content_handler.cc +++ b/examples/forwarding_content_handler/forwarding_content_handler.cc
@@ -54,14 +54,14 @@ class ForwardingContentHandler : public ApplicationDelegate, public ContentHandlerFactory::ManagedDelegate { public: - ForwardingContentHandler() : content_handler_factory_(this) {} + ForwardingContentHandler() {} private: // Overridden from ApplicationDelegate: bool ConfigureIncomingConnection( ServiceProviderImpl* service_provider_impl) override { service_provider_impl->AddService<ContentHandler>( - content_handler_factory_.GetInterfaceRequestHandler()); + ContentHandlerFactory::GetInterfaceRequestHandler(this)); return true; } @@ -80,8 +80,6 @@ new ForwardingApplicationImpl(application_request.Pass(), target_url)); } - ContentHandlerFactory content_handler_factory_; - DISALLOW_COPY_AND_ASSIGN(ForwardingContentHandler); };
diff --git a/examples/recursive_content_handler/recursive_content_handler.cc b/examples/recursive_content_handler/recursive_content_handler.cc index 62f9357..77613d7 100644 --- a/examples/recursive_content_handler/recursive_content_handler.cc +++ b/examples/recursive_content_handler/recursive_content_handler.cc
@@ -18,14 +18,14 @@ class RecursiveContentHandler : public ApplicationDelegate, public ContentHandlerFactory::ManagedDelegate { public: - RecursiveContentHandler() : content_handler_factory_(this) {} + RecursiveContentHandler() {} private: // Overridden from ApplicationDelegate: bool ConfigureIncomingConnection( ServiceProviderImpl* service_provider_impl) override { service_provider_impl->AddService<ContentHandler>( - content_handler_factory_.GetInterfaceRequestHandler()); + ContentHandlerFactory::GetInterfaceRequestHandler(this)); return true; } @@ -38,8 +38,6 @@ new RecursiveContentHandler(), application_request.Pass())); } - ContentHandlerFactory content_handler_factory_; - DISALLOW_COPY_AND_ASSIGN(RecursiveContentHandler); };
diff --git a/mojo/application/content_handler_factory.cc b/mojo/application/content_handler_factory.cc index 8b10448..e27996a 100644 --- a/mojo/application/content_handler_factory.cc +++ b/mojo/application/content_handler_factory.cc
@@ -4,7 +4,7 @@ #include "mojo/application/content_handler_factory.h" -#include <set> +#include <map> #include "base/bind.h" #include "base/callback.h" @@ -111,22 +111,12 @@ } // namespace -ContentHandlerFactory::ContentHandlerFactory(Delegate* delegate) - : delegate_(delegate) {} - -ContentHandlerFactory::~ContentHandlerFactory() {} - -void ContentHandlerFactory::Create( - const ConnectionContext& connection_context, - InterfaceRequest<ContentHandler> content_handler_request) { - new ContentHandlerImpl(delegate_, content_handler_request.Pass()); -} - +// static ServiceProviderImpl::InterfaceRequestHandler<ContentHandler> -ContentHandlerFactory::GetInterfaceRequestHandler() { - return [this](const ConnectionContext& connection_context, - InterfaceRequest<ContentHandler> content_handler_request) { - Create(connection_context, content_handler_request.Pass()); +ContentHandlerFactory::GetInterfaceRequestHandler(Delegate* delegate) { + return [delegate](const ConnectionContext& connection_context, + InterfaceRequest<ContentHandler> content_handler_request) { + new ContentHandlerImpl(delegate, content_handler_request.Pass()); }; }
diff --git a/mojo/application/content_handler_factory.h b/mojo/application/content_handler_factory.h index 86293df..b1ebccc 100644 --- a/mojo/application/content_handler_factory.h +++ b/mojo/application/content_handler_factory.h
@@ -15,7 +15,8 @@ struct ConnectionContext; -// TODO(vtl): Should this even be a class, now that InterfaceFactory is no more? +// TODO(vtl): Nuke this class. Now it's only a "namespace" for stuff, most of +// which is overcomplicated. class ContentHandlerFactory { public: class HandledApplicationHolder { @@ -49,21 +50,9 @@ URLResponsePtr response) override; }; - explicit ContentHandlerFactory(Delegate* delegate); - ~ContentHandlerFactory(); - - // Creates a content handler for the given connection (context and request). - void Create(const ConnectionContext& connection_context, - InterfaceRequest<ContentHandler> content_handler_request); - // For use with |ServiceProviderImpl::AddService<ContentHandler>()|. - ServiceProviderImpl::InterfaceRequestHandler<ContentHandler> - GetInterfaceRequestHandler(); - - private: - Delegate* delegate_; - - DISALLOW_COPY_AND_ASSIGN(ContentHandlerFactory); + static ServiceProviderImpl::InterfaceRequestHandler<ContentHandler> + GetInterfaceRequestHandler(Delegate* delegate); }; template <class A>
diff --git a/services/dart/content_handler_main.cc b/services/dart/content_handler_main.cc index 957e690..aafa2b6 100644 --- a/services/dart/content_handler_main.cc +++ b/services/dart/content_handler_main.cc
@@ -135,8 +135,6 @@ DartContentHandlerApp() : content_handler_(this, false), strict_content_handler_(this, true), - content_handler_factory_(&content_handler_), - strict_content_handler_factory_(&strict_content_handler_), service_connector_(nullptr), default_strict_(false), run_on_message_loop_(false) {} @@ -242,10 +240,12 @@ service_provider_impl->connection_context().connection_url); if (default_strict_ || strict) { service_provider_impl->AddService<mojo::ContentHandler>( - strict_content_handler_factory_.GetInterfaceRequestHandler()); + mojo::ContentHandlerFactory::GetInterfaceRequestHandler( + &strict_content_handler_)); } else { service_provider_impl->AddService<mojo::ContentHandler>( - content_handler_factory_.GetInterfaceRequestHandler()); + mojo::ContentHandlerFactory::GetInterfaceRequestHandler( + &content_handler_)); } return true; } @@ -253,8 +253,6 @@ mojo::TracingImpl tracing_; DartContentHandler content_handler_; DartContentHandler strict_content_handler_; - mojo::ContentHandlerFactory content_handler_factory_; - mojo::ContentHandlerFactory strict_content_handler_factory_; mojo::URLResponseDiskCachePtr url_response_disk_cache_; ContentHandlerAppServiceConnector* service_connector_; DartTracingImpl dart_tracing_;
diff --git a/services/java_handler/java_handler.cc b/services/java_handler/java_handler.cc index 1387c1a..b7949de 100644 --- a/services/java_handler/java_handler.cc +++ b/services/java_handler/java_handler.cc
@@ -53,7 +53,7 @@ namespace services { namespace android { -JavaHandler::JavaHandler() : content_handler_factory_(this) {} +JavaHandler::JavaHandler() {} JavaHandler::~JavaHandler() {} @@ -121,7 +121,7 @@ bool JavaHandler::ConfigureIncomingConnection( mojo::ServiceProviderImpl* service_provider_impl) { service_provider_impl->AddService<mojo::ContentHandler>( - content_handler_factory_.GetInterfaceRequestHandler()); + mojo::ContentHandlerFactory::GetInterfaceRequestHandler(this)); return true; }
diff --git a/services/java_handler/java_handler.h b/services/java_handler/java_handler.h index 6f8c0ea..6412ca0 100644 --- a/services/java_handler/java_handler.h +++ b/services/java_handler/java_handler.h
@@ -41,7 +41,6 @@ const base::Closure& callback); mojo::TracingImpl tracing_; - mojo::ContentHandlerFactory content_handler_factory_; mojo::URLResponseDiskCachePtr url_response_disk_cache_; scoped_refptr<base::SingleThreadTaskRunner> handler_task_runner_; MOJO_DISALLOW_COPY_AND_ASSIGN(JavaHandler);
diff --git a/services/js/content_handler_main.cc b/services/js/content_handler_main.cc index 5f30561..9ed4f84 100644 --- a/services/js/content_handler_main.cc +++ b/services/js/content_handler_main.cc
@@ -17,7 +17,7 @@ class JsContentHandler : public mojo::ApplicationDelegate, public mojo::ContentHandlerFactory::ManagedDelegate { public: - JsContentHandler() : content_handler_factory_(this) {} + JsContentHandler() {} private: // Overridden from mojo::ApplicationDelegate: @@ -33,7 +33,7 @@ bool ConfigureIncomingConnection( mojo::ServiceProviderImpl* service_provider_impl) override { service_provider_impl->AddService<mojo::ContentHandler>( - content_handler_factory_.GetInterfaceRequestHandler()); + mojo::ContentHandlerFactory::GetInterfaceRequestHandler(this)); return true; } @@ -46,8 +46,6 @@ new JSApp(application_request.Pass(), response.Pass())); } - mojo::ContentHandlerFactory content_handler_factory_; - DISALLOW_COPY_AND_ASSIGN(JsContentHandler); };
diff --git a/services/nacl/nonsfi/content_handler_main_nexe.cc b/services/nacl/nonsfi/content_handler_main_nexe.cc index 0ccada1..158816a 100644 --- a/services/nacl/nonsfi/content_handler_main_nexe.cc +++ b/services/nacl/nonsfi/content_handler_main_nexe.cc
@@ -20,7 +20,7 @@ class NaClContentHandler : public mojo::ApplicationDelegate, public mojo::ContentHandlerFactory::Delegate { public: - NaClContentHandler() : content_handler_factory_(this) {} + NaClContentHandler() {} private: // Overridden from ApplicationDelegate: @@ -30,7 +30,7 @@ bool ConfigureIncomingConnection( mojo::ServiceProviderImpl* service_provider_impl) override { service_provider_impl->AddService<mojo::ContentHandler>( - content_handler_factory_.GetInterfaceRequestHandler()); + mojo::ContentHandlerFactory::GetInterfaceRequestHandler(this)); return true; } @@ -57,8 +57,6 @@ MojoLaunchNexeNonsfi(fd, handle, false /* enable_translation_irt */); } - mojo::ContentHandlerFactory content_handler_factory_; - DISALLOW_COPY_AND_ASSIGN(NaClContentHandler); };
diff --git a/services/nacl/nonsfi/content_handler_main_pexe.cc b/services/nacl/nonsfi/content_handler_main_pexe.cc index f0ecc3b..e92d3d6 100644 --- a/services/nacl/nonsfi/content_handler_main_pexe.cc +++ b/services/nacl/nonsfi/content_handler_main_pexe.cc
@@ -31,7 +31,7 @@ class PexeContentHandler : public mojo::ApplicationDelegate, public mojo::ContentHandlerFactory::Delegate { public: - PexeContentHandler() : content_handler_factory_(this) {} + PexeContentHandler() {} private: // Overridden from ApplicationDelegate: @@ -53,7 +53,7 @@ bool ConfigureIncomingConnection( mojo::ServiceProviderImpl* service_provider_impl) override { service_provider_impl->AddService<mojo::ContentHandler>( - content_handler_factory_.GetInterfaceRequestHandler()); + mojo::ContentHandlerFactory::GetInterfaceRequestHandler(this)); return true; } @@ -152,7 +152,6 @@ private: mojo::SynchronousInterfacePtr<mojo::files::Directory> nexe_cache_directory_; mojo::files::FilesPtr files_; - mojo::ContentHandlerFactory content_handler_factory_; mojo::SynchronousInterfacePtr<mojo::nacl::PexeCompilerInit> compiler_init_; mojo::SynchronousInterfacePtr<mojo::nacl::PexeLinkerInit> linker_init_;
diff --git a/services/nacl/sfi/content_handler_main.cc b/services/nacl/sfi/content_handler_main.cc index 3e0a51b..3894e3a 100644 --- a/services/nacl/sfi/content_handler_main.cc +++ b/services/nacl/sfi/content_handler_main.cc
@@ -74,7 +74,7 @@ class NaClContentHandler : public mojo::ApplicationDelegate, public mojo::ContentHandlerFactory::Delegate { public: - NaClContentHandler() : content_handler_factory_(this) {} + NaClContentHandler() {} private: // Overridden from ApplicationDelegate: @@ -106,7 +106,7 @@ bool ConfigureIncomingConnection( mojo::ServiceProviderImpl* service_provider_impl) override { service_provider_impl->AddService<mojo::ContentHandler>( - content_handler_factory_.GetInterfaceRequestHandler()); + mojo::ContentHandlerFactory::GetInterfaceRequestHandler(this)); return true; } @@ -139,7 +139,6 @@ NOTREACHED(); } - mojo::ContentHandlerFactory content_handler_factory_; GURL url_; base::ScopedFILE irt_fp_;
diff --git a/services/python/content_handler/content_handler_main.cc b/services/python/content_handler/content_handler_main.cc index 04c9045..383f4b3 100644 --- a/services/python/content_handler/content_handler_main.cc +++ b/services/python/content_handler/content_handler_main.cc
@@ -204,10 +204,7 @@ class PythonContentHandlerApp : public ApplicationDelegate { public: PythonContentHandlerApp() - : content_handler_(false), - debug_content_handler_(true), - content_handler_factory_(&content_handler_), - debug_content_handler_factory_(&debug_content_handler_) {} + : content_handler_(false), debug_content_handler_(true) {} private: // Overridden from ApplicationDelegate: @@ -215,10 +212,11 @@ mojo::ServiceProviderImpl* service_provider_impl) override { if (IsDebug(service_provider_impl->connection_context().connection_url)) { service_provider_impl->AddService<mojo::ContentHandler>( - debug_content_handler_factory_.GetInterfaceRequestHandler()); + ContentHandlerFactory::GetInterfaceRequestHandler( + &debug_content_handler_)); } else { service_provider_impl->AddService<mojo::ContentHandler>( - content_handler_factory_.GetInterfaceRequestHandler()); + ContentHandlerFactory::GetInterfaceRequestHandler(&content_handler_)); } return true; } @@ -236,8 +234,6 @@ PythonContentHandler content_handler_; PythonContentHandler debug_content_handler_; - ContentHandlerFactory content_handler_factory_; - ContentHandlerFactory debug_content_handler_factory_; DISALLOW_COPY_AND_ASSIGN(PythonContentHandlerApp); };
diff --git a/shell/android/android_handler.cc b/shell/android/android_handler.cc index 5bb40600..cf709f0 100644 --- a/shell/android/android_handler.cc +++ b/shell/android/android_handler.cc
@@ -83,11 +83,9 @@ } // namespace -AndroidHandler::AndroidHandler() : content_handler_factory_(this) { -} +AndroidHandler::AndroidHandler() {} -AndroidHandler::~AndroidHandler() { -} +AndroidHandler::~AndroidHandler() {} void AndroidHandler::RunApplication( mojo::InterfaceRequest<mojo::Application> application_request, @@ -133,7 +131,7 @@ bool AndroidHandler::ConfigureIncomingConnection( mojo::ServiceProviderImpl* service_provider_impl) { service_provider_impl->AddService<mojo::ContentHandler>( - content_handler_factory_.GetInterfaceRequestHandler()); + mojo::ContentHandlerFactory::GetInterfaceRequestHandler(this)); return true; }
diff --git a/shell/android/android_handler.h b/shell/android/android_handler.h index d9a96fe..e31c014 100644 --- a/shell/android/android_handler.h +++ b/shell/android/android_handler.h
@@ -41,7 +41,6 @@ mojo::URLResponsePtr response, const base::Closure& callback); - mojo::ContentHandlerFactory content_handler_factory_; mojo::URLResponseDiskCachePtr url_response_disk_cache_; scoped_refptr<base::SingleThreadTaskRunner> handler_task_runner_;