OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 SERVICES_SHELL_PUBLIC_CPP_LIB_CONNECTION_IMPL_H_ | 5 #ifndef SERVICES_SHELL_PUBLIC_CPP_LIB_CONNECTION_IMPL_H_ |
6 #define SERVICES_SHELL_PUBLIC_CPP_LIB_CONNECTION_IMPL_H_ | 6 #define SERVICES_SHELL_PUBLIC_CPP_LIB_CONNECTION_IMPL_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "mojo/public/cpp/bindings/binding.h" | 14 #include "mojo/public/cpp/bindings/binding.h" |
15 #include "services/shell/public/cpp/capabilities.h" | 15 #include "services/shell/public/cpp/capabilities.h" |
16 #include "services/shell/public/cpp/connection.h" | 16 #include "services/shell/public/cpp/connection.h" |
17 #include "services/shell/public/cpp/identity.h" | 17 #include "services/shell/public/cpp/identity.h" |
18 #include "services/shell/public/interfaces/connector.mojom.h" | 18 #include "services/shell/public/interfaces/connector.mojom.h" |
19 #include "services/shell/public/interfaces/interface_provider.mojom.h" | 19 #include "services/shell/public/interfaces/interface_provider.mojom.h" |
20 | 20 |
21 namespace shell { | 21 namespace shell { |
22 namespace internal { | 22 namespace internal { |
23 | 23 |
24 // A ConnectionImpl represents each half of a connection between two | 24 // A ConnectionImpl represents each half of a connection between two |
25 // applications, allowing customization of which interfaces are published to the | 25 // applications, allowing customization of which interfaces are published to the |
26 // other. | 26 // other. |
27 class ConnectionImpl : public Connection { | 27 class ConnectionImpl : public Connection { |
28 public: | 28 public: |
29 ConnectionImpl(); | 29 ConnectionImpl(); |
30 // |allowed_interfaces| are the set of interfaces that the shell has allowed | 30 ConnectionImpl(const Identity& remote, State initial_state); |
31 // an application to expose to another application. If this set contains only | |
32 // the string value "*" all interfaces may be exposed. | |
33 ConnectionImpl(const Identity& remote, | |
34 const CapabilityRequest& capability_request, | |
35 State initial_state); | |
36 ~ConnectionImpl() override; | 31 ~ConnectionImpl() override; |
37 | 32 |
38 // Sets the local registry & remote provider, transferring ownership to the | 33 // Sets the remote provider, transferring ownership to the ConnectionImpl. |
39 // ConnectionImpl. | |
40 void SetExposedInterfaces( | |
41 std::unique_ptr<InterfaceRegistry> exposed_interfaces); | |
42 void SetRemoteInterfaces( | 34 void SetRemoteInterfaces( |
43 std::unique_ptr<InterfaceProvider> remote_interfaces); | 35 std::unique_ptr<InterfaceProvider> remote_interfaces); |
44 | 36 |
45 // Sets the local registry & remote provider, without transferring ownership. | 37 // Sets the remote provider, without transferring ownership. |
46 void set_exposed_interfaces(InterfaceRegistry* exposed_interfaces) { | |
47 exposed_interfaces_ = exposed_interfaces; | |
48 } | |
49 void set_remote_interfaces(InterfaceProvider* remote_interfaces) { | 38 void set_remote_interfaces(InterfaceProvider* remote_interfaces) { |
50 remote_interfaces_ = remote_interfaces; | 39 remote_interfaces_ = remote_interfaces; |
51 } | 40 } |
52 | 41 |
53 shell::mojom::Connector::ConnectCallback GetConnectCallback(); | 42 shell::mojom::Connector::ConnectCallback GetConnectCallback(); |
54 | 43 |
55 private: | 44 private: |
56 // Connection: | 45 // Connection: |
57 bool HasCapabilityClass(const std::string& class_name) const override; | |
58 const Identity& GetRemoteIdentity() const override; | 46 const Identity& GetRemoteIdentity() const override; |
59 void SetConnectionLostClosure(const base::Closure& handler) override; | 47 void SetConnectionLostClosure(const base::Closure& handler) override; |
60 shell::mojom::ConnectResult GetResult() const override; | 48 shell::mojom::ConnectResult GetResult() const override; |
61 bool IsPending() const override; | 49 bool IsPending() const override; |
62 void AddConnectionCompletedClosure(const base::Closure& callback) override; | 50 void AddConnectionCompletedClosure(const base::Closure& callback) override; |
63 bool AllowsInterface(const std::string& interface_name) const override; | |
64 InterfaceRegistry* GetInterfaceRegistry() override; | |
65 InterfaceProvider* GetRemoteInterfaces() override; | 51 InterfaceProvider* GetRemoteInterfaces() override; |
66 base::WeakPtr<Connection> GetWeakPtr() override; | 52 base::WeakPtr<Connection> GetWeakPtr() override; |
67 | 53 |
68 void OnConnectionCompleted(shell::mojom::ConnectResult result, | 54 void OnConnectionCompleted(shell::mojom::ConnectResult result, |
69 mojo::String target_user_id); | 55 mojo::String target_user_id); |
70 | 56 |
71 Identity remote_; | 57 Identity remote_; |
72 | 58 |
73 State state_; | 59 State state_; |
74 shell::mojom::ConnectResult result_ = shell::mojom::ConnectResult::SUCCEEDED; | 60 shell::mojom::ConnectResult result_ = shell::mojom::ConnectResult::SUCCEEDED; |
75 std::vector<base::Closure> connection_completed_callbacks_; | 61 std::vector<base::Closure> connection_completed_callbacks_; |
76 | 62 |
77 InterfaceRegistry* exposed_interfaces_ = nullptr; | |
78 InterfaceProvider* remote_interfaces_ = nullptr; | 63 InterfaceProvider* remote_interfaces_ = nullptr; |
79 | 64 |
80 std::unique_ptr<InterfaceRegistry> exposed_interfaces_owner_; | |
81 std::unique_ptr<InterfaceProvider> remote_interfaces_owner_; | 65 std::unique_ptr<InterfaceProvider> remote_interfaces_owner_; |
82 | 66 |
83 const CapabilityRequest capability_request_; | |
84 const bool allow_all_interfaces_; | |
85 | |
86 base::WeakPtrFactory<ConnectionImpl> weak_factory_; | 67 base::WeakPtrFactory<ConnectionImpl> weak_factory_; |
87 | 68 |
88 DISALLOW_COPY_AND_ASSIGN(ConnectionImpl); | 69 DISALLOW_COPY_AND_ASSIGN(ConnectionImpl); |
89 }; | 70 }; |
90 | 71 |
91 } // namespace internal | 72 } // namespace internal |
92 } // namespace shell | 73 } // namespace shell |
93 | 74 |
94 #endif // SERVICES_SHELL_PUBLIC_CPP_LIB_CONNECTION_IMPL_H_ | 75 #endif // SERVICES_SHELL_PUBLIC_CPP_LIB_CONNECTION_IMPL_H_ |
OLD | NEW |