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 EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_CHANNEL_API_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_CHANNEL_API_H_ |
6 #define EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_CHANNEL_API_H_ | 6 #define EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_CHANNEL_API_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 21 matching lines...) Expand all Loading... | |
32 | 32 |
33 namespace core_api { | 33 namespace core_api { |
34 namespace cast_channel { | 34 namespace cast_channel { |
35 class Logger; | 35 class Logger; |
36 } // namespace cast_channel | 36 } // namespace cast_channel |
37 } // namespace core_api | 37 } // namespace core_api |
38 | 38 |
39 namespace cast_channel = core_api::cast_channel; | 39 namespace cast_channel = core_api::cast_channel; |
40 | 40 |
41 class CastChannelAPI : public BrowserContextKeyedAPI, | 41 class CastChannelAPI : public BrowserContextKeyedAPI, |
42 public cast_channel::CastSocket::Delegate { | 42 public cast_channel::CastSocketImpl::Delegate { |
43 public: | 43 public: |
44 explicit CastChannelAPI(content::BrowserContext* context); | 44 explicit CastChannelAPI(content::BrowserContext* context); |
45 | 45 |
46 static CastChannelAPI* Get(content::BrowserContext* context); | 46 static CastChannelAPI* Get(content::BrowserContext* context); |
47 | 47 |
48 // BrowserContextKeyedAPI implementation. | 48 // BrowserContextKeyedAPI implementation. |
49 static BrowserContextKeyedAPIFactory<CastChannelAPI>* GetFactoryInstance(); | 49 static BrowserContextKeyedAPIFactory<CastChannelAPI>* GetFactoryInstance(); |
50 | 50 |
51 // Returns a new CastSocket that connects to |ip_endpoint| with authentication | 51 // Returns a new CastSocketImpl that connects to |ip_endpoint| with |
52 // authentication | |
52 // |channel_auth| and is to be owned by |extension_id|. | 53 // |channel_auth| and is to be owned by |extension_id|. |
53 scoped_ptr<cast_channel::CastSocket> CreateCastSocket( | 54 scoped_ptr<cast_channel::CastSocketImpl> CreateCastSocketImpl( |
Wez
2014/09/20 00:41:30
Ick... OK, this ends up being really ugly since th
Kevin M
2014/09/22 19:56:51
I would prefer to do it in a followup CL. I'll add
| |
54 const std::string& extension_id, | 55 const std::string& extension_id, |
55 const net::IPEndPoint& ip_endpoint, | 56 const net::IPEndPoint& ip_endpoint, |
56 cast_channel::ChannelAuthType channel_auth, | 57 cast_channel::ChannelAuthType channel_auth, |
57 const base::TimeDelta& timeout); | 58 const base::TimeDelta& timeout); |
58 | 59 |
59 // Returns a pointer to the Logger member variable. | 60 // Returns a pointer to the Logger member variable. |
60 // TODO(imcheng): Consider whether it is possible for this class to own the | 61 // TODO(imcheng): Consider whether it is possible for this class to own the |
61 // CastSockets and make this class the sole owner of Logger. Alternatively, | 62 // CastSocketImpls and make this class the sole owner of Logger. |
63 // Alternatively, | |
62 // consider making Logger not ref-counted by passing a weak | 64 // consider making Logger not ref-counted by passing a weak |
63 // reference of Logger to the CastSockets instead. | 65 // reference of Logger to the CastSocketImpls instead. |
64 scoped_refptr<cast_channel::Logger> GetLogger(); | 66 scoped_refptr<cast_channel::Logger> GetLogger(); |
65 | 67 |
66 // Sets the CastSocket instance to be returned by CreateCastSocket for | 68 // Sets the CastSocketImpl instance to be returned by CreateCastSocketImpl for |
67 // testing. | 69 // testing. |
68 void SetSocketForTest(scoped_ptr<cast_channel::CastSocket> socket_for_test); | 70 void SetSocketForTest( |
71 scoped_ptr<cast_channel::CastSocketImpl> socket_for_test); | |
69 | 72 |
70 private: | 73 private: |
71 friend class BrowserContextKeyedAPIFactory<CastChannelAPI>; | 74 friend class BrowserContextKeyedAPIFactory<CastChannelAPI>; |
72 friend class ::CastChannelAPITest; | 75 friend class ::CastChannelAPITest; |
73 | 76 |
74 virtual ~CastChannelAPI(); | 77 virtual ~CastChannelAPI(); |
75 | 78 |
76 // CastSocket::Delegate. Called on IO thread. | 79 // CastSocketImpl::Delegate. Called on IO thread. |
77 virtual void OnError(const cast_channel::CastSocket* socket, | 80 virtual void OnError(const cast_channel::CastSocketImpl* socket, |
78 cast_channel::ChannelError error_state, | 81 cast_channel::ChannelError error_state, |
79 const cast_channel::LastErrors& last_errors) OVERRIDE; | 82 const cast_channel::LastErrors& last_errors) OVERRIDE; |
80 virtual void OnMessage(const cast_channel::CastSocket* socket, | 83 virtual void OnMessage(const cast_channel::CastSocketImpl* socket, |
81 const cast_channel::MessageInfo& message) OVERRIDE; | 84 const cast_channel::MessageInfo& message) OVERRIDE; |
82 | 85 |
83 // BrowserContextKeyedAPI implementation. | 86 // BrowserContextKeyedAPI implementation. |
84 static const char* service_name() { return "CastChannelAPI"; } | 87 static const char* service_name() { return "CastChannelAPI"; } |
85 | 88 |
86 content::BrowserContext* const browser_context_; | 89 content::BrowserContext* const browser_context_; |
87 scoped_refptr<cast_channel::Logger> logger_; | 90 scoped_refptr<cast_channel::Logger> logger_; |
88 scoped_ptr<cast_channel::CastSocket> socket_for_test_; | 91 scoped_ptr<cast_channel::CastSocketImpl> socket_for_test_; |
89 | 92 |
90 DISALLOW_COPY_AND_ASSIGN(CastChannelAPI); | 93 DISALLOW_COPY_AND_ASSIGN(CastChannelAPI); |
91 }; | 94 }; |
92 | 95 |
93 class CastChannelAsyncApiFunction : public AsyncApiFunction { | 96 class CastChannelAsyncApiFunction : public AsyncApiFunction { |
94 public: | 97 public: |
95 CastChannelAsyncApiFunction(); | 98 CastChannelAsyncApiFunction(); |
96 | 99 |
97 protected: | 100 protected: |
98 virtual ~CastChannelAsyncApiFunction(); | 101 virtual ~CastChannelAsyncApiFunction(); |
99 | 102 |
100 // AsyncApiFunction: | 103 // AsyncApiFunction: |
101 virtual bool PrePrepare() OVERRIDE; | 104 virtual bool PrePrepare() OVERRIDE; |
102 virtual bool Respond() OVERRIDE; | 105 virtual bool Respond() OVERRIDE; |
103 | 106 |
104 // Returns the socket corresponding to |channel_id| if one exists. Otherwise, | 107 // Returns the socket corresponding to |channel_id| if one exists. Otherwise, |
105 // sets the function result with CHANNEL_ERROR_INVALID_CHANNEL_ID, completes | 108 // sets the function result with CHANNEL_ERROR_INVALID_CHANNEL_ID, completes |
106 // the function, and returns null. | 109 // the function, and returns null. |
107 cast_channel::CastSocket* GetSocketOrCompleteWithError(int channel_id); | 110 cast_channel::CastSocketImpl* GetSocketOrCompleteWithError(int channel_id); |
108 | 111 |
109 // Adds |socket| to |manager_| and returns the new channel_id. |manager_| | 112 // Adds |socket| to |manager_| and returns the new channel_id. |manager_| |
110 // assumes ownership of |socket|. | 113 // assumes ownership of |socket|. |
111 int AddSocket(cast_channel::CastSocket* socket); | 114 int AddSocket(cast_channel::CastSocketImpl* socket); |
112 | 115 |
113 // Removes the CastSocket corresponding to |channel_id| from the resource | 116 // Removes the CastSocketImpl corresponding to |channel_id| from the resource |
114 // manager. | 117 // manager. |
115 void RemoveSocket(int channel_id); | 118 void RemoveSocket(int channel_id); |
116 | 119 |
117 // Sets the function result to a ChannelInfo obtained from the state of | 120 // Sets the function result to a ChannelInfo obtained from the state of |
118 // |socket|. | 121 // |socket|. |
119 void SetResultFromSocket(const cast_channel::CastSocket& socket); | 122 void SetResultFromSocket(const cast_channel::CastSocketImpl& socket); |
120 | 123 |
121 // Sets the function result to a ChannelInfo populated with |channel_id| and | 124 // Sets the function result to a ChannelInfo populated with |channel_id| and |
122 // |error|. | 125 // |error|. |
123 void SetResultFromError(int channel_id, cast_channel::ChannelError error); | 126 void SetResultFromError(int channel_id, cast_channel::ChannelError error); |
124 | 127 |
125 // Returns the socket corresponding to |channel_id| if one exists, or null | 128 // Returns the socket corresponding to |channel_id| if one exists, or null |
126 // otherwise. | 129 // otherwise. |
127 cast_channel::CastSocket* GetSocket(int channel_id); | 130 cast_channel::CastSocketImpl* GetSocket(int channel_id); |
128 | 131 |
129 private: | 132 private: |
130 // Sets the function result from |channel_info|. | 133 // Sets the function result from |channel_info|. |
131 void SetResultFromChannelInfo(const cast_channel::ChannelInfo& channel_info); | 134 void SetResultFromChannelInfo(const cast_channel::ChannelInfo& channel_info); |
132 | 135 |
133 // The API resource manager for CastSockets. | 136 // The API resource manager for CastSocketImpls. |
134 ApiResourceManager<cast_channel::CastSocket>* manager_; | 137 ApiResourceManager<cast_channel::CastSocketImpl>* manager_; |
135 | 138 |
136 // The result of the function. | 139 // The result of the function. |
137 cast_channel::ChannelError error_; | 140 cast_channel::ChannelError error_; |
138 }; | 141 }; |
139 | 142 |
140 class CastChannelOpenFunction : public CastChannelAsyncApiFunction { | 143 class CastChannelOpenFunction : public CastChannelAsyncApiFunction { |
141 public: | 144 public: |
142 CastChannelOpenFunction(); | 145 CastChannelOpenFunction(); |
143 | 146 |
144 protected: | 147 protected: |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 void OnClose(int result); | 241 void OnClose(int result); |
239 | 242 |
240 CastChannelAPI* api_; | 243 CastChannelAPI* api_; |
241 | 244 |
242 DISALLOW_COPY_AND_ASSIGN(CastChannelGetLogsFunction); | 245 DISALLOW_COPY_AND_ASSIGN(CastChannelGetLogsFunction); |
243 }; | 246 }; |
244 | 247 |
245 } // namespace extensions | 248 } // namespace extensions |
246 | 249 |
247 #endif // EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_CHANNEL_API_H_ | 250 #endif // EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_CHANNEL_API_H_ |
OLD | NEW |