diff options
author | ben <ben@chromium.org> | 2016-02-17 23:53:40 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-18 07:54:41 +0000 |
commit | f451cdbd381c7707f644d41cc1fe30f4cc8a32a2 (patch) | |
tree | 3087a0248e98a094f94447fb4df89730b3f882eb /mojo/shell/public | |
parent | 6c4b4fbb5192fb3624d428172cdf916013bc5a2e (diff) | |
download | chromium_src-f451cdbd381c7707f644d41cc1fe30f4cc8a32a2.zip chromium_src-f451cdbd381c7707f644d41cc1fe30f4cc8a32a2.tar.gz chromium_src-f451cdbd381c7707f644d41cc1fe30f4cc8a32a2.tar.bz2 |
ContentHandler -> ShellClientFactory
TBR=sky@chromium.org
BUG=
Review URL: https://codereview.chromium.org/1705323003
Cr-Commit-Position: refs/heads/master@{#376117}
Diffstat (limited to 'mojo/shell/public')
-rw-r--r-- | mojo/shell/public/cpp/BUILD.gn | 8 | ||||
-rw-r--r-- | mojo/shell/public/cpp/connection.h | 18 | ||||
-rw-r--r-- | mojo/shell/public/cpp/lib/connection_impl.cc | 14 | ||||
-rw-r--r-- | mojo/shell/public/cpp/lib/connection_impl.h | 9 | ||||
-rw-r--r-- | mojo/shell/public/cpp/lib/shell_client_factory.cc (renamed from mojo/shell/public/cpp/lib/content_handler_factory.cc) | 66 | ||||
-rw-r--r-- | mojo/shell/public/cpp/shell_client_factory.h (renamed from mojo/shell/public/cpp/content_handler_factory.h) | 44 | ||||
-rw-r--r-- | mojo/shell/public/interfaces/BUILD.gn | 2 | ||||
-rw-r--r-- | mojo/shell/public/interfaces/content_handler.mojom | 20 | ||||
-rw-r--r-- | mojo/shell/public/interfaces/shell_client_factory.mojom | 13 |
9 files changed, 97 insertions, 97 deletions
diff --git a/mojo/shell/public/cpp/BUILD.gn b/mojo/shell/public/cpp/BUILD.gn index b368a50..3afe21a 100644 --- a/mojo/shell/public/cpp/BUILD.gn +++ b/mojo/shell/public/cpp/BUILD.gn @@ -62,19 +62,21 @@ source_set("init_commandline") { ] } -source_set("content_handler") { +source_set("shell_client_factory") { sources = [ - "content_handler_factory.h", - "lib/content_handler_factory.cc", + "lib/shell_client_factory.cc", + "shell_client_factory.h", ] deps = [ ":cpp", # TODO: this code should not depend on base. "//base", + "//mojo/common:url_type_converters", "//mojo/message_pump", "//mojo/services/network/public/interfaces", "//mojo/shell/public/interfaces:interfaces_cpp_sources", + "//url", ] } diff --git a/mojo/shell/public/cpp/connection.h b/mojo/shell/public/cpp/connection.h index 84f428b..a2f6b77 100644 --- a/mojo/shell/public/cpp/connection.h +++ b/mojo/shell/public/cpp/connection.h @@ -95,15 +95,17 @@ class Connection { // been established. virtual bool GetRemoteApplicationID(uint32_t* remote_id) const = 0; - // Returns the id of the deepest content handler used in connecting to + // Returns the id of the deepest shell client factory used in connecting to // the application. See GetRemoteApplicationID() for details about the return - // value. A |content_handler_id| value of Shell::kInvalidApplicationID - // indicates no content handler was used in connecting to the application. - virtual bool GetRemoteContentHandlerID( - uint32_t* content_handler_id) const = 0; - - // See description in GetRemoteApplicationID()/GetRemoteContentHandlerID(). If - // the ids are available, |callback| is run immediately. + // value. A |shell_client_factory_id| value of Shell::kInvalidApplicationID + // indicates no shell client factory was used in connecting to the + // application. + virtual bool GetRemoteShellClientFactoryID( + uint32_t* shell_client_factory_id) const = 0; + + // See description in GetRemoteApplicationID()/ + // GetRemoteShellClientFactoryID(). If the ids are available, |callback| is + // run immediately. virtual void AddRemoteIDCallback(const Closure& callback) = 0; // Returns true if the Shell allows |interface_name| to be exposed to the diff --git a/mojo/shell/public/cpp/lib/connection_impl.cc b/mojo/shell/public/cpp/lib/connection_impl.cc index 8f41dcb..f301711 100644 --- a/mojo/shell/public/cpp/lib/connection_impl.cc +++ b/mojo/shell/public/cpp/lib/connection_impl.cc @@ -29,7 +29,7 @@ ConnectionImpl::ConnectionImpl( : connection_url_(connection_url), remote_url_(remote_url), remote_id_(remote_id), - content_handler_id_(0u), + shell_client_factory_id_(0u), remote_ids_valid_(false), local_registry_(std::move(local_interfaces), this), remote_interfaces_(std::move(remote_interfaces)), @@ -40,7 +40,7 @@ ConnectionImpl::ConnectionImpl( ConnectionImpl::ConnectionImpl() : remote_id_(shell::mojom::Shell::kInvalidApplicationID), - content_handler_id_(shell::mojom::Shell::kInvalidApplicationID), + shell_client_factory_id_(shell::mojom::Shell::kInvalidApplicationID), remote_ids_valid_(false), local_registry_(shell::mojom::InterfaceProviderRequest(), this), allow_all_interfaces_(true), @@ -78,12 +78,12 @@ bool ConnectionImpl::GetRemoteApplicationID(uint32_t* remote_id) const { return true; } -bool ConnectionImpl::GetRemoteContentHandlerID( - uint32_t* content_handler_id) const { +bool ConnectionImpl::GetRemoteShellClientFactoryID( + uint32_t* shell_client_factory_id) const { if (!remote_ids_valid_) return false; - *content_handler_id = content_handler_id_; + *shell_client_factory_id = shell_client_factory_id_; return true; } @@ -115,12 +115,12 @@ base::WeakPtr<Connection> ConnectionImpl::GetWeakPtr() { // ConnectionImpl, private: void ConnectionImpl::OnGotRemoteIDs(uint32_t target_application_id, - uint32_t content_handler_id) { + uint32_t shell_client_factory_id) { DCHECK(!remote_ids_valid_); remote_ids_valid_ = true; remote_id_ = target_application_id; - content_handler_id_ = content_handler_id; + shell_client_factory_id_ = shell_client_factory_id; std::vector<Closure> callbacks; callbacks.swap(remote_id_callbacks_); for (auto callback : callbacks) diff --git a/mojo/shell/public/cpp/lib/connection_impl.h b/mojo/shell/public/cpp/lib/connection_impl.h index 7d9c55e..1346e257 100644 --- a/mojo/shell/public/cpp/lib/connection_impl.h +++ b/mojo/shell/public/cpp/lib/connection_impl.h @@ -45,7 +45,8 @@ class ConnectionImpl : public Connection { void SetRemoteInterfaceProviderConnectionErrorHandler( const Closure& handler) override; bool GetRemoteApplicationID(uint32_t* remote_id) const override; - bool GetRemoteContentHandlerID(uint32_t* content_handler_id) const override; + bool GetRemoteShellClientFactoryID( + uint32_t* shell_client_factory_id) const override; void AddRemoteIDCallback(const Closure& callback) override; bool AllowsInterface(const std::string& interface_name) const override; shell::mojom::InterfaceProvider* GetRemoteInterfaces() override; @@ -53,15 +54,15 @@ class ConnectionImpl : public Connection { base::WeakPtr<Connection> GetWeakPtr() override; void OnGotRemoteIDs(uint32_t target_application_id, - uint32_t content_handler_id); + uint32_t shell_client_factory_id); const std::string connection_url_; const std::string remote_url_; uint32_t remote_id_; - // The id of the content_handler is only available once the callback from + // The id of the shell_client_factory is only available once the callback from // establishing the connection is made. - uint32_t content_handler_id_; + uint32_t shell_client_factory_id_; bool remote_ids_valid_; std::vector<Closure> remote_id_callbacks_; diff --git a/mojo/shell/public/cpp/lib/content_handler_factory.cc b/mojo/shell/public/cpp/lib/shell_client_factory.cc index 74b788c..14a3e79 100644 --- a/mojo/shell/public/cpp/lib/content_handler_factory.cc +++ b/mojo/shell/public/cpp/lib/shell_client_factory.cc @@ -13,11 +13,13 @@ #include "base/single_thread_task_runner.h" #include "base/thread_task_runner_handle.h" #include "base/threading/platform_thread.h" +#include "mojo/common/url_type_converters.h" #include "mojo/message_pump/message_pump_mojo.h" #include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/shell/public/cpp/connection.h" -#include "mojo/shell/public/cpp/content_handler_factory.h" #include "mojo/shell/public/cpp/interface_factory_impl.h" +#include "mojo/shell/public/cpp/shell_client_factory.h" +#include "url/gurl.h" namespace mojo { @@ -28,15 +30,15 @@ class ApplicationThread : public base::PlatformThread::Delegate { ApplicationThread( scoped_refptr<base::SingleThreadTaskRunner> handler_thread, const base::Callback<void(ApplicationThread*)>& termination_callback, - ContentHandlerFactory::Delegate* handler_delegate, + ShellClientFactory::Delegate* handler_delegate, InterfaceRequest<shell::mojom::ShellClient> request, - URLResponsePtr response, + const GURL& url, const Callback<void()>& destruct_callback) : handler_thread_(handler_thread), termination_callback_(termination_callback), handler_delegate_(handler_delegate), request_(std::move(request)), - response_(std::move(response)), + url_(url), destruct_callback_(destruct_callback) {} ~ApplicationThread() override { @@ -45,30 +47,29 @@ class ApplicationThread : public base::PlatformThread::Delegate { private: void ThreadMain() override { - handler_delegate_->RunApplication(std::move(request_), - std::move(response_)); + handler_delegate_->CreateShellClient(std::move(request_), url_); handler_thread_->PostTask(FROM_HERE, base::Bind(termination_callback_, this)); } scoped_refptr<base::SingleThreadTaskRunner> handler_thread_; base::Callback<void(ApplicationThread*)> termination_callback_; - ContentHandlerFactory::Delegate* handler_delegate_; + ShellClientFactory::Delegate* handler_delegate_; InterfaceRequest<shell::mojom::ShellClient> request_; - URLResponsePtr response_; + GURL url_; Callback<void()> destruct_callback_; DISALLOW_COPY_AND_ASSIGN(ApplicationThread); }; -class ContentHandlerImpl : public shell::mojom::ContentHandler { +class ShellClientFactoryImpl : public shell::mojom::ShellClientFactory { public: - ContentHandlerImpl(ContentHandlerFactory::Delegate* delegate, - InterfaceRequest<shell::mojom::ContentHandler> request) + ShellClientFactoryImpl(mojo::ShellClientFactory::Delegate* delegate, + shell::mojom::ShellClientFactoryRequest request) : delegate_(delegate), binding_(this, std::move(request)), weak_factory_(this) {} - ~ContentHandlerImpl() override { + ~ShellClientFactoryImpl() override { // We're shutting down and doing cleanup. Cleanup may trigger calls back to // OnThreadEnd(). As we're doing the cleanup here we don't want to do it in // OnThreadEnd() as well. InvalidateWeakPtrs() ensures we don't get any @@ -81,16 +82,16 @@ class ContentHandlerImpl : public shell::mojom::ContentHandler { } private: - // Overridden from ContentHandler: - void StartApplication(InterfaceRequest<shell::mojom::ShellClient> request, - URLResponsePtr response, - const Callback<void()>& destruct_callback) override { + // Overridden from shell::mojom::ShellClientFactory: + void CreateShellClient(shell::mojom::ShellClientRequest request, + const String& url, + const Callback<void()>& destruct_callback) override { ApplicationThread* thread = new ApplicationThread(base::ThreadTaskRunnerHandle::Get(), - base::Bind(&ContentHandlerImpl::OnThreadEnd, + base::Bind(&ShellClientFactoryImpl::OnThreadEnd, weak_factory_.GetWeakPtr()), - delegate_, std::move(request), - std::move(response), destruct_callback); + delegate_, std::move(request), url.To<GURL>(), + destruct_callback); base::PlatformThreadHandle handle; bool launched = base::PlatformThread::Create(0, thread, &handle); DCHECK(launched); @@ -105,37 +106,36 @@ class ContentHandlerImpl : public shell::mojom::ContentHandler { delete thread; } - ContentHandlerFactory::Delegate* delegate_; + mojo::ShellClientFactory::Delegate* delegate_; std::map<ApplicationThread*, base::PlatformThreadHandle> active_threads_; - StrongBinding<shell::mojom::ContentHandler> binding_; - base::WeakPtrFactory<ContentHandlerImpl> weak_factory_; + StrongBinding<shell::mojom::ShellClientFactory> binding_; + base::WeakPtrFactory<ShellClientFactoryImpl> weak_factory_; - DISALLOW_COPY_AND_ASSIGN(ContentHandlerImpl); + DISALLOW_COPY_AND_ASSIGN(ShellClientFactoryImpl); }; } // namespace -ContentHandlerFactory::ContentHandlerFactory(Delegate* delegate) +ShellClientFactory::ShellClientFactory(Delegate* delegate) : delegate_(delegate) { } -ContentHandlerFactory::~ContentHandlerFactory() { +ShellClientFactory::~ShellClientFactory() { } -void ContentHandlerFactory::ManagedDelegate::RunApplication( - InterfaceRequest<shell::mojom::ShellClient> request, - URLResponsePtr response) { +void ShellClientFactory::ManagedDelegate::CreateShellClient( + shell::mojom::ShellClientRequest request, + const GURL& url) { base::MessageLoop loop(common::MessagePumpMojo::Create()); - auto application = - this->CreateApplication(std::move(request), std::move(response)); + auto application = this->CreateShellClientManaged(std::move(request), url); if (application) loop.Run(); } -void ContentHandlerFactory::Create( +void ShellClientFactory::Create( Connection* connection, - InterfaceRequest<shell::mojom::ContentHandler> request) { - new ContentHandlerImpl(delegate_, std::move(request)); + shell::mojom::ShellClientFactoryRequest request) { + new ShellClientFactoryImpl(delegate_, std::move(request)); } } // namespace mojo diff --git a/mojo/shell/public/cpp/content_handler_factory.h b/mojo/shell/public/cpp/shell_client_factory.h index 9e3c5ff..5c6e878 100644 --- a/mojo/shell/public/cpp/content_handler_factory.h +++ b/mojo/shell/public/cpp/shell_client_factory.h @@ -2,20 +2,22 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef MOJO_SHELL_PUBLIC_CPP_CONTENT_HANDLER_FACTORY_H_ -#define MOJO_SHELL_PUBLIC_CPP_CONTENT_HANDLER_FACTORY_H_ +#ifndef MOJO_SHELL_PUBLIC_CPP_SHELL_CLIENT_FACTORY_H_ +#define MOJO_SHELL_PUBLIC_CPP_SHELL_CLIENT_FACTORY_H_ #include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "mojo/services/network/public/interfaces/url_loader.mojom.h" #include "mojo/shell/public/cpp/interface_factory.h" -#include "mojo/shell/public/interfaces/content_handler.mojom.h" #include "mojo/shell/public/interfaces/shell.mojom.h" +#include "mojo/shell/public/interfaces/shell_client_factory.mojom.h" + +class GURL; namespace mojo { -class ContentHandlerFactory - : public InterfaceFactory<shell::mojom::ContentHandler> { +class ShellClientFactory + : public InterfaceFactory<shell::mojom::ShellClientFactory> { public: class HandledApplicationHolder { public: @@ -27,9 +29,9 @@ class ContentHandlerFactory virtual ~Delegate() {} // Implement this method to create the Application. This method will be // called on a new thread. Leaving this method will quit the application. - virtual void RunApplication( - InterfaceRequest<shell::mojom::ShellClient> request, - URLResponsePtr response) = 0; + virtual void CreateShellClient( + shell::mojom::ShellClientRequest request, + const GURL& url) = 0; }; class ManagedDelegate : public Delegate { @@ -39,31 +41,31 @@ class ContentHandlerFactory // This method will be called on a new thread. The application will be run // on this new thread, and the returned value will be kept alive until the // application ends. - virtual scoped_ptr<HandledApplicationHolder> CreateApplication( - InterfaceRequest<shell::mojom::ShellClient> request, - URLResponsePtr response) = 0; + virtual scoped_ptr<HandledApplicationHolder> CreateShellClientManaged( + shell::mojom::ShellClientRequest request, + const GURL& url) = 0; private: - void RunApplication(InterfaceRequest<shell::mojom::ShellClient> request, - URLResponsePtr response) override; + void CreateShellClient(shell::mojom::ShellClientRequest request, + const GURL& url) override; }; - explicit ContentHandlerFactory(Delegate* delegate); - ~ContentHandlerFactory() override; + explicit ShellClientFactory(Delegate* delegate); + ~ShellClientFactory() override; private: - // From InterfaceFactory: + // InterfaceFactory<shell::mojom::ShellClientFactory>: void Create(Connection* connection, - InterfaceRequest<shell::mojom::ContentHandler> request) override; + shell::mojom::ShellClientFactoryRequest request) override; Delegate* delegate_; - DISALLOW_COPY_AND_ASSIGN(ContentHandlerFactory); + DISALLOW_COPY_AND_ASSIGN(ShellClientFactory); }; template <class A> class HandledApplicationHolderImpl - : public ContentHandlerFactory::HandledApplicationHolder { + : public ShellClientFactory::HandledApplicationHolder { public: explicit HandledApplicationHolderImpl(A* value) : value_(value) {} @@ -72,11 +74,11 @@ class HandledApplicationHolderImpl }; template <class A> -scoped_ptr<ContentHandlerFactory::HandledApplicationHolder> +scoped_ptr<ShellClientFactory::HandledApplicationHolder> make_handled_factory_holder(A* value) { return make_scoped_ptr(new HandledApplicationHolderImpl<A>(value)); } } // namespace mojo -#endif // MOJO_SHELL_PUBLIC_CPP_CONTENT_HANDLER_FACTORY_H_ +#endif // MOJO_SHELL_PUBLIC_CPP_SHELL_CLIENT_FACTORY_H_ diff --git a/mojo/shell/public/interfaces/BUILD.gn b/mojo/shell/public/interfaces/BUILD.gn index 134a80d..d014121 100644 --- a/mojo/shell/public/interfaces/BUILD.gn +++ b/mojo/shell/public/interfaces/BUILD.gn @@ -8,10 +8,10 @@ import("//mojo/public/tools/bindings/mojom.gni") mojom("interfaces") { sources = [ "application_manager.mojom", - "content_handler.mojom", "interface_provider.mojom", "shell.mojom", "shell_client.mojom", + "shell_client_factory.mojom", ] import_dirs = [ "//mojo/services" ] diff --git a/mojo/shell/public/interfaces/content_handler.mojom b/mojo/shell/public/interfaces/content_handler.mojom deleted file mode 100644 index 0dae8b9..0000000 --- a/mojo/shell/public/interfaces/content_handler.mojom +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -module mojo.shell.mojom; - -import "mojo/shell/public/interfaces/shell_client.mojom"; -import "network/public/interfaces/url_loader.mojom"; - -// Interface implemented by content handlers. To avoid race conditions with -// dropped requests, the implementation should keep a reference to the lifetime -// of the app (by holding on to AppRefCount). Each application started by -// StartApplication should call the callback given by that method on -// destruction. When the owner in the shell notices this, it will destroy the -// interface pointer, which should cause the strongly-bound ContentHandler -// implementation to self destruct and release the app reference. -interface ContentHandler { - // The callback should be called when the application is destructed. - StartApplication(ShellClient& shell_client, mojo.URLResponse response) => (); -}; diff --git a/mojo/shell/public/interfaces/shell_client_factory.mojom b/mojo/shell/public/interfaces/shell_client_factory.mojom new file mode 100644 index 0000000..7179946 --- /dev/null +++ b/mojo/shell/public/interfaces/shell_client_factory.mojom @@ -0,0 +1,13 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +module mojo.shell.mojom; + +import "mojo/shell/public/interfaces/shell_client.mojom"; + +// Implemented by a package containing multiple applications identified by +// unique URLs. +interface ShellClientFactory { + CreateShellClient(ShellClient& shell_client, string url) => (); +}; |