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 COMPONENTS_COPRESENCE_RPC_RPC_HANDLER_H_ | 5 #ifndef COMPONENTS_COPRESENCE_RPC_RPC_HANDLER_H_ |
6 #define COMPONENTS_COPRESENCE_RPC_RPC_HANDLER_H_ | 6 #define COMPONENTS_COPRESENCE_RPC_RPC_HANDLER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
16 #include "components/copresence/proto/enums.pb.h" | 16 #include "components/copresence/proto/enums.pb.h" |
| 17 #include "components/copresence/public/copresence_constants.h" |
17 #include "components/copresence/public/copresence_delegate.h" | 18 #include "components/copresence/public/copresence_delegate.h" |
18 #include "components/copresence/timed_map.h" | 19 #include "components/copresence/timed_map.h" |
19 | 20 |
20 namespace copresence { | 21 namespace copresence { |
21 | 22 |
22 struct AudioToken; | 23 struct AudioToken; |
23 class CopresenceDelegate; | 24 class CopresenceDelegate; |
24 class CopresenceStateImpl; | 25 class CopresenceStateImpl; |
25 class DirectiveHandler; | 26 class DirectiveHandler; |
26 class GCMHandler; | 27 class GCMHandler; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 // Report rpc name to send to Apiary. | 65 // Report rpc name to send to Apiary. |
65 static const char kReportRequestRpcName[]; | 66 static const char kReportRequestRpcName[]; |
66 | 67 |
67 // Constructor. |delegate| and |directive_handler| | 68 // Constructor. |delegate| and |directive_handler| |
68 // are owned by the caller and must outlive the RpcHandler. | 69 // are owned by the caller and must outlive the RpcHandler. |
69 // |server_post_callback| should be set only by tests. | 70 // |server_post_callback| should be set only by tests. |
70 RpcHandler(CopresenceDelegate* delegate, | 71 RpcHandler(CopresenceDelegate* delegate, |
71 CopresenceStateImpl* state, | 72 CopresenceStateImpl* state, |
72 DirectiveHandler* directive_handler, | 73 DirectiveHandler* directive_handler, |
73 GCMHandler* gcm_handler, | 74 GCMHandler* gcm_handler, |
| 75 const MessagesCallback& new_messages_callback, |
74 const PostCallback& server_post_callback = PostCallback()); | 76 const PostCallback& server_post_callback = PostCallback()); |
75 | 77 |
76 virtual ~RpcHandler(); | 78 virtual ~RpcHandler(); |
77 | 79 |
78 // Send a ReportRequest from a specific app, and get notified of completion. | 80 // Send a ReportRequest from a specific app, and get notified of completion. |
79 void SendReportRequest(scoped_ptr<ReportRequest> request, | 81 void SendReportRequest(scoped_ptr<ReportRequest> request, |
80 const std::string& app_id, | 82 const std::string& app_id, |
81 const std::string& auth_token, | 83 const std::string& auth_token, |
82 const StatusCallback& callback); | 84 const StatusCallback& callback); |
83 | 85 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 | 131 |
130 // If the request has any unpublish or unsubscribe operations, it removes | 132 // If the request has any unpublish or unsubscribe operations, it removes |
131 // them from our directive handlers. | 133 // them from our directive handlers. |
132 void ProcessRemovedOperations(const ReportRequest& request); | 134 void ProcessRemovedOperations(const ReportRequest& request); |
133 | 135 |
134 // Add all currently playing tokens to the update signals in this report | 136 // Add all currently playing tokens to the update signals in this report |
135 // request. This ensures that the server doesn't keep issueing new tokens to | 137 // request. This ensures that the server doesn't keep issueing new tokens to |
136 // us when we're already playing valid tokens. | 138 // us when we're already playing valid tokens. |
137 void AddPlayingTokens(ReportRequest* request); | 139 void AddPlayingTokens(ReportRequest* request); |
138 | 140 |
139 void DispatchMessages( | |
140 const google::protobuf::RepeatedPtrField<SubscribedMessage>& | |
141 subscribed_messages); | |
142 | |
143 RequestHeader* CreateRequestHeader(const std::string& client_name, | 141 RequestHeader* CreateRequestHeader(const std::string& client_name, |
144 const std::string& device_id) const; | 142 const std::string& device_id) const; |
145 | 143 |
146 // Post a request to the server. The request should be in proto format. | 144 // Post a request to the server. The request should be in proto format. |
147 template <class T> | 145 template <class T> |
148 void SendServerRequest(const std::string& rpc_name, | 146 void SendServerRequest(const std::string& rpc_name, |
149 const std::string& device_id, | 147 const std::string& device_id, |
150 const std::string& app_id, | 148 const std::string& app_id, |
151 const std::string& auth_token, | 149 const std::string& auth_token, |
152 scoped_ptr<T> request, | 150 scoped_ptr<T> request, |
153 const PostCleanupCallback& response_handler); | 151 const PostCleanupCallback& response_handler); |
154 | 152 |
155 // Wrapper for the http post constructor. This is the default way | 153 // Wrapper for the http post constructor. This is the default way |
156 // to contact the server, but it can be overridden for testing. | 154 // to contact the server, but it can be overridden for testing. |
157 void SendHttpPost(net::URLRequestContextGetter* url_context_getter, | 155 void SendHttpPost(net::URLRequestContextGetter* url_context_getter, |
158 const std::string& rpc_name, | 156 const std::string& rpc_name, |
159 const std::string& api_key, | 157 const std::string& api_key, |
160 const std::string& auth_token, | 158 const std::string& auth_token, |
161 scoped_ptr<google::protobuf::MessageLite> request_proto, | 159 scoped_ptr<google::protobuf::MessageLite> request_proto, |
162 const PostCleanupCallback& callback); | 160 const PostCleanupCallback& callback); |
163 | 161 |
164 // These belong to the caller. | 162 // These belong to the caller. |
165 CopresenceDelegate* const delegate_; | 163 CopresenceDelegate* const delegate_; |
166 CopresenceStateImpl* state_; | 164 CopresenceStateImpl* state_; |
167 DirectiveHandler* const directive_handler_; | 165 DirectiveHandler* const directive_handler_; |
168 GCMHandler* const gcm_handler_; | 166 GCMHandler* const gcm_handler_; |
169 | 167 |
| 168 MessagesCallback new_messages_callback_; |
170 PostCallback server_post_callback_; | 169 PostCallback server_post_callback_; |
171 | 170 |
172 ScopedVector<PendingRequest> pending_requests_queue_; | 171 ScopedVector<PendingRequest> pending_requests_queue_; |
173 TimedMap<std::string, bool> invalid_audio_token_cache_; | 172 TimedMap<std::string, bool> invalid_audio_token_cache_; |
174 std::map<std::string, std::string> device_id_by_auth_token_; | 173 std::map<std::string, std::string> device_id_by_auth_token_; |
175 std::set<HttpPost*> pending_posts_; | 174 std::set<HttpPost*> pending_posts_; |
176 std::string gcm_id_; | 175 std::string gcm_id_; |
177 | 176 |
178 DISALLOW_COPY_AND_ASSIGN(RpcHandler); | 177 DISALLOW_COPY_AND_ASSIGN(RpcHandler); |
179 }; | 178 }; |
180 | 179 |
181 } // namespace copresence | 180 } // namespace copresence |
182 | 181 |
183 #endif // COMPONENTS_COPRESENCE_RPC_RPC_HANDLER_H_ | 182 #endif // COMPONENTS_COPRESENCE_RPC_RPC_HANDLER_H_ |
OLD | NEW |