| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_BROWSER_MOJO_MOJO_SHELL_CONTEXT_H_ | 5 #ifndef CONTENT_BROWSER_MOJO_MOJO_SHELL_CONTEXT_H_ |
| 6 #define CONTENT_BROWSER_MOJO_MOJO_SHELL_CONTEXT_H_ | 6 #define CONTENT_BROWSER_MOJO_MOJO_SHELL_CONTEXT_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
| 16 #include "mojo/shell/application_manager.h" | 16 #include "mojo/shell/application_manager.h" |
| 17 #include "mojo/shell/public/interfaces/shell.mojom.h" | 17 #include "mojo/shell/public/interfaces/shell.mojom.h" |
| 18 | 18 |
| 19 class GURL; | |
| 20 | |
| 21 namespace mojo { | 19 namespace mojo { |
| 22 class ShellClient; | 20 class ShellClient; |
| 23 } | 21 } |
| 24 | 22 |
| 25 namespace content { | 23 namespace content { |
| 26 | 24 |
| 27 // MojoShellContext hosts the browser's ApplicationManager, coordinating | 25 // MojoShellContext hosts the browser's ApplicationManager, coordinating |
| 28 // app registration and interconnection. | 26 // app registration and interconnection. |
| 29 class CONTENT_EXPORT MojoShellContext { | 27 class CONTENT_EXPORT MojoShellContext { |
| 30 public: | 28 public: |
| 31 using StaticApplicationMap = | 29 using StaticApplicationMap = |
| 32 std::map<GURL, base::Callback<scoped_ptr<mojo::ShellClient>()>>; | 30 std::map<std::string, base::Callback<scoped_ptr<mojo::ShellClient>()>>; |
| 33 | 31 |
| 34 MojoShellContext(); | 32 MojoShellContext(); |
| 35 ~MojoShellContext(); | 33 ~MojoShellContext(); |
| 36 | 34 |
| 37 // Connects an application at |url| and gets a handle to its exposed services. | 35 // Connects an application at |name| and gets a handle to its exposed |
| 38 // This is only intended for use in browser code that's not part of some Mojo | 36 // services. This is only intended for use in browser code that's not part of |
| 39 // application. May be called from any thread. |requestor_url| is given to | 37 // some Mojo application. May be called from any thread. |requestor_name| is |
| 40 // the target application as the requestor's URL upon connection. | 38 // given to the target application as the requestor's name upon connection. |
| 41 static void ConnectToApplication( | 39 static void ConnectToApplication( |
| 42 const GURL& url, | 40 const std::string& name, |
| 43 const GURL& requestor_url, | 41 const std::string& requestor_name, |
| 44 mojo::shell::mojom::InterfaceProviderRequest request, | 42 mojo::shell::mojom::InterfaceProviderRequest request, |
| 45 mojo::shell::mojom::InterfaceProviderPtr exposed_services, | 43 mojo::shell::mojom::InterfaceProviderPtr exposed_services, |
| 46 const mojo::shell::mojom::Connector::ConnectCallback& callback); | 44 const mojo::shell::mojom::Connector::ConnectCallback& callback); |
| 47 | 45 |
| 48 static void SetApplicationsForTest(const StaticApplicationMap* apps); | 46 static void SetApplicationsForTest(const StaticApplicationMap* apps); |
| 49 | 47 |
| 50 private: | 48 private: |
| 51 class Proxy; | 49 class Proxy; |
| 52 friend class Proxy; | 50 friend class Proxy; |
| 53 | 51 |
| 54 void ConnectToApplicationOnOwnThread( | 52 void ConnectToApplicationOnOwnThread( |
| 55 const GURL& url, | 53 const std::string& name, |
| 56 const GURL& requestor_url, | 54 const std::string& requestor_name, |
| 57 mojo::shell::mojom::InterfaceProviderRequest request, | 55 mojo::shell::mojom::InterfaceProviderRequest request, |
| 58 mojo::shell::mojom::InterfaceProviderPtr exposed_services, | 56 mojo::shell::mojom::InterfaceProviderPtr exposed_services, |
| 59 const mojo::shell::mojom::Connector::ConnectCallback& callback); | 57 const mojo::shell::mojom::Connector::ConnectCallback& callback); |
| 60 | 58 |
| 61 static base::LazyInstance<scoped_ptr<Proxy>> proxy_; | 59 static base::LazyInstance<scoped_ptr<Proxy>> proxy_; |
| 62 | 60 |
| 63 scoped_ptr<mojo::shell::ApplicationManager> application_manager_; | 61 scoped_ptr<mojo::shell::ApplicationManager> application_manager_; |
| 64 | 62 |
| 65 DISALLOW_COPY_AND_ASSIGN(MojoShellContext); | 63 DISALLOW_COPY_AND_ASSIGN(MojoShellContext); |
| 66 }; | 64 }; |
| 67 | 65 |
| 68 } // namespace content | 66 } // namespace content |
| 69 | 67 |
| 70 #endif // CONTENT_BROWSER_MOJO_MOJO_SHELL_CONTEXT_H_ | 68 #endif // CONTENT_BROWSER_MOJO_MOJO_SHELL_CONTEXT_H_ |
| OLD | NEW |