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