| 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_PUBLIC_BROWSER_MOJO_APP_CONNECTION_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_MOJO_APP_CONNECTION_H_ |
| 6 #define CONTENT_PUBLIC_BROWSER_MOJO_APP_CONNECTION_H_ | 6 #define CONTENT_PUBLIC_BROWSER_MOJO_APP_CONNECTION_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "content/common/content_export.h" | 11 #include "content/common/content_export.h" |
| 12 #include "mojo/public/cpp/bindings/interface_ptr.h" | 12 #include "mojo/public/cpp/bindings/interface_ptr.h" |
| 13 #include "mojo/public/cpp/bindings/interface_request.h" | 13 #include "mojo/public/cpp/bindings/interface_request.h" |
| 14 #include "mojo/public/cpp/system/message_pipe.h" | 14 #include "mojo/public/cpp/system/message_pipe.h" |
| 15 | 15 |
| 16 namespace content { | 16 namespace content { |
| 17 | 17 |
| 18 class BrowserContext; |
| 19 |
| 18 // A virtual app URL identifying the browser itself. This should be used for | 20 // A virtual app URL identifying the browser itself. This should be used for |
| 19 // a connection's |requestor_url| when connecting from browser code to apps that | 21 // a connection's |requestor_url| when connecting from browser code to apps that |
| 20 // don't require a more specific request context. | 22 // don't require a more specific request context. |
| 21 CONTENT_EXPORT extern const char kBrowserMojoAppUrl[]; | 23 CONTENT_EXPORT extern const char kBrowserMojoAppUrl[]; |
| 22 | 24 |
| 23 // This provides a way for arbitrary browser code to connect to Mojo apps. These | 25 // This provides a way for arbitrary browser code to connect to Mojo apps. These |
| 24 // objects are not thread-safe but may be constructed and used on any single | 26 // objects are not thread-safe but may be constructed and used on any single |
| 25 // thread. | 27 // thread. |
| 26 class CONTENT_EXPORT MojoAppConnection { | 28 class CONTENT_EXPORT MojoAppConnection { |
| 27 public: | 29 public: |
| 28 virtual ~MojoAppConnection() {} | 30 virtual ~MojoAppConnection() {} |
| 29 | 31 |
| 30 // Creates a new connection to the application at |name| using | 32 // Creates a new connection to the application at |name| using |
| 31 // |requestor_name| to identify the requestor upon connection. This may be | 33 // |requestor_name| to identify the requestor upon connection. This may be |
| 32 // called from any thread. | 34 // called from any thread. |
| 33 static scoped_ptr<MojoAppConnection> Create( | 35 static scoped_ptr<MojoAppConnection> Create( |
| 36 BrowserContext* context, |
| 34 const std::string& name, | 37 const std::string& name, |
| 35 const std::string& requestor_name); | 38 const std::string& requestor_name); |
| 36 | 39 |
| 37 // Connects to a service within the application. | 40 // Connects to a service within the application. |
| 38 template <typename Interface> | 41 template <typename Interface> |
| 39 void GetInterface(mojo::InterfacePtr<Interface>* proxy) { | 42 void GetInterface(mojo::InterfacePtr<Interface>* proxy) { |
| 40 GetInterface(Interface::Name_, mojo::GetProxy(proxy).PassMessagePipe()); | 43 GetInterface(Interface::Name_, mojo::GetProxy(proxy).PassMessagePipe()); |
| 41 } | 44 } |
| 42 | 45 |
| 43 virtual void GetInterface(const std::string& interface_name, | 46 virtual void GetInterface(const std::string& interface_name, |
| 44 mojo::ScopedMessagePipeHandle handle) = 0; | 47 mojo::ScopedMessagePipeHandle handle) = 0; |
| 45 }; | 48 }; |
| 46 | 49 |
| 47 } // namespace content | 50 } // namespace content |
| 48 | 51 |
| 49 #endif // CONTENT_PUBLIC_BROWSER_MOJO_APP_CONNECTION_H_ | 52 #endif // CONTENT_PUBLIC_BROWSER_MOJO_APP_CONNECTION_H_ |
| OLD | NEW |