| 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 namespace mojo { | 19 namespace mojo { |
| 20 class ShellClient; | 20 class ShellClient; |
| 21 } | 21 } |
| 22 | 22 |
| 23 namespace content { | 23 namespace content { |
| 24 class BrowserContext; |
| 24 | 25 |
| 25 // MojoShellContext hosts the browser's ApplicationManager, coordinating | 26 // MojoShellContext hosts the browser's ApplicationManager, coordinating |
| 26 // app registration and interconnection. | 27 // app registration and interconnection. |
| 27 class CONTENT_EXPORT MojoShellContext { | 28 class CONTENT_EXPORT MojoShellContext { |
| 28 public: | 29 public: |
| 29 using StaticApplicationMap = | 30 using StaticApplicationMap = |
| 30 std::map<std::string, base::Callback<scoped_ptr<mojo::ShellClient>()>>; | 31 std::map<std::string, base::Callback<scoped_ptr<mojo::ShellClient>()>>; |
| 31 | 32 |
| 32 MojoShellContext(); | 33 MojoShellContext(); |
| 33 ~MojoShellContext(); | 34 ~MojoShellContext(); |
| 34 | 35 |
| 35 // Connects an application at |name| and gets a handle to its exposed | 36 // Connects an application at |name| and gets a handle to its exposed |
| 36 // services. This is only intended for use in browser code that's not part of | 37 // services. This is only intended for use in browser code that's not part of |
| 37 // some Mojo application. May be called from any thread. |requestor_name| is | 38 // some Mojo application. May be called from any thread. |requestor_name| is |
| 38 // given to the target application as the requestor's name upon connection. | 39 // given to the target application as the requestor's name upon connection. |
| 39 static void ConnectToApplication( | 40 static void ConnectToApplication( |
| 40 const std::string& name, | 41 const std::string& name, |
| 41 const std::string& requestor_name, | 42 const std::string& requestor_name, |
| 42 mojo::shell::mojom::InterfaceProviderRequest request, | 43 mojo::shell::mojom::InterfaceProviderRequest request, |
| 43 mojo::shell::mojom::InterfaceProviderPtr exposed_services, | 44 mojo::shell::mojom::InterfaceProviderPtr exposed_services, |
| 44 const mojo::shell::mojom::Connector::ConnectCallback& callback); | 45 const mojo::shell::mojom::Connector::ConnectCallback& callback); |
| 45 | 46 |
| 47 static void ConnectToApplicationWithContext( |
| 48 BrowserContext* context, |
| 49 const std::string& name, |
| 50 const std::string& requestor_name, |
| 51 mojo::shell::mojom::InterfaceProviderRequest request, |
| 52 mojo::shell::mojom::InterfaceProviderPtr exposed_services, |
| 53 const mojo::shell::mojom::Connector::ConnectCallback& callback); |
| 54 |
| 46 static void SetApplicationsForTest(const StaticApplicationMap* apps); | 55 static void SetApplicationsForTest(const StaticApplicationMap* apps); |
| 47 | 56 |
| 48 private: | 57 private: |
| 49 class Proxy; | 58 class Proxy; |
| 50 friend class Proxy; | 59 friend class Proxy; |
| 51 | 60 |
| 52 void ConnectToApplicationOnOwnThread( | 61 void ConnectToApplicationOnOwnThread( |
| 62 uint32_t user_id, |
| 53 const std::string& name, | 63 const std::string& name, |
| 54 const std::string& requestor_name, | 64 const std::string& requestor_name, |
| 55 mojo::shell::mojom::InterfaceProviderRequest request, | 65 mojo::shell::mojom::InterfaceProviderRequest request, |
| 56 mojo::shell::mojom::InterfaceProviderPtr exposed_services, | 66 mojo::shell::mojom::InterfaceProviderPtr exposed_services, |
| 57 const mojo::shell::mojom::Connector::ConnectCallback& callback); | 67 const mojo::shell::mojom::Connector::ConnectCallback& callback); |
| 58 | 68 |
| 59 static base::LazyInstance<scoped_ptr<Proxy>> proxy_; | 69 static base::LazyInstance<scoped_ptr<Proxy>> proxy_; |
| 60 | 70 |
| 61 scoped_ptr<mojo::shell::ApplicationManager> application_manager_; | 71 scoped_ptr<mojo::shell::ApplicationManager> application_manager_; |
| 62 | 72 |
| 63 DISALLOW_COPY_AND_ASSIGN(MojoShellContext); | 73 DISALLOW_COPY_AND_ASSIGN(MojoShellContext); |
| 64 }; | 74 }; |
| 65 | 75 |
| 66 } // namespace content | 76 } // namespace content |
| 67 | 77 |
| 68 #endif // CONTENT_BROWSER_MOJO_MOJO_SHELL_CONTEXT_H_ | 78 #endif // CONTENT_BROWSER_MOJO_MOJO_SHELL_CONTEXT_H_ |
| OLD | NEW |