| 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_delegate.h" | 17 #include "components/copresence/public/copresence_delegate.h" |
| 18 #include "components/copresence/timed_map.h" | 18 #include "components/copresence/timed_map.h" |
| 19 | 19 |
| 20 namespace copresence { | 20 namespace copresence { |
| 21 | 21 |
| 22 struct AudioToken; | 22 struct AudioToken; |
| 23 class CopresenceDelegate; | 23 class CopresenceDelegate; |
| 24 class DirectiveHandler; | 24 class DirectiveHandler; |
| 25 class GCMHandler; | |
| 26 class HttpPost; | 25 class HttpPost; |
| 27 class ReportRequest; | 26 class ReportRequest; |
| 28 class RequestHeader; | 27 class RequestHeader; |
| 29 class SubscribedMessage; | 28 class SubscribedMessage; |
| 30 | 29 |
| 31 // This class currently handles all communication with the copresence server. | 30 // This class currently handles all communication with the copresence server. |
| 32 class RpcHandler { | 31 class RpcHandler { |
| 33 public: | 32 public: |
| 34 // A callback to indicate whether handler initialization succeeded. | 33 // A callback to indicate whether handler initialization succeeded. |
| 35 typedef base::Callback<void(bool)> SuccessCallback; | 34 typedef base::Callback<void(bool)> SuccessCallback; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 59 const PostCleanupCallback&)> PostCallback; | 58 const PostCleanupCallback&)> PostCallback; |
| 60 | 59 |
| 61 // Report rpc name to send to Apiary. | 60 // Report rpc name to send to Apiary. |
| 62 static const char kReportRequestRpcName[]; | 61 static const char kReportRequestRpcName[]; |
| 63 | 62 |
| 64 // Constructor. |delegate| and |directive_handler| | 63 // Constructor. |delegate| and |directive_handler| |
| 65 // are owned by the caller and must outlive the RpcHandler. | 64 // are owned by the caller and must outlive the RpcHandler. |
| 66 // |server_post_callback| should be set only by tests. | 65 // |server_post_callback| should be set only by tests. |
| 67 RpcHandler(CopresenceDelegate* delegate, | 66 RpcHandler(CopresenceDelegate* delegate, |
| 68 DirectiveHandler* directive_handler, | 67 DirectiveHandler* directive_handler, |
| 69 GCMHandler* gcm_handler, | |
| 70 const PostCallback& server_post_callback = PostCallback()); | 68 const PostCallback& server_post_callback = PostCallback()); |
| 71 | 69 |
| 72 virtual ~RpcHandler(); | 70 virtual ~RpcHandler(); |
| 73 | 71 |
| 74 // Send a ReportRequest from a specific app, and get notified of completion. | 72 // Send a ReportRequest from a specific app, and get notified of completion. |
| 75 void SendReportRequest(scoped_ptr<ReportRequest> request, | 73 void SendReportRequest(scoped_ptr<ReportRequest> request, |
| 76 const std::string& app_id, | 74 const std::string& app_id, |
| 77 const std::string& auth_token, | 75 const std::string& auth_token, |
| 78 const StatusCallback& callback); | 76 const StatusCallback& callback); |
| 79 | 77 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 102 // which is tied to the auth token (or lack thereof) used to call Report. | 100 // which is tied to the auth token (or lack thereof) used to call Report. |
| 103 void RegisterForToken(const std::string& auth_token); | 101 void RegisterForToken(const std::string& auth_token); |
| 104 | 102 |
| 105 // Device registration has completed. Send the requests that it was blocking. | 103 // Device registration has completed. Send the requests that it was blocking. |
| 106 void ProcessQueuedRequests(const std::string& auth_token); | 104 void ProcessQueuedRequests(const std::string& auth_token); |
| 107 | 105 |
| 108 // Send a ReportRequest from Chrome itself, i.e. no app id. | 106 // Send a ReportRequest from Chrome itself, i.e. no app id. |
| 109 void SendReportRequest(scoped_ptr<ReportRequest> request, | 107 void SendReportRequest(scoped_ptr<ReportRequest> request, |
| 110 const std::string& auth_token); | 108 const std::string& auth_token); |
| 111 | 109 |
| 112 // Store a GCM ID and send it to the server if needed. | |
| 113 void RegisterGcmId(const std::string& gcm_id); | |
| 114 | |
| 115 // Server call response handlers. | 110 // Server call response handlers. |
| 116 void RegisterResponseHandler(const std::string& auth_token, | 111 void RegisterResponseHandler(const std::string& auth_token, |
| 117 bool gcm_pending, | |
| 118 HttpPost* completed_post, | 112 HttpPost* completed_post, |
| 119 int http_status_code, | 113 int http_status_code, |
| 120 const std::string& response_data); | 114 const std::string& response_data); |
| 121 void ReportResponseHandler(const StatusCallback& status_callback, | 115 void ReportResponseHandler(const StatusCallback& status_callback, |
| 122 HttpPost* completed_post, | 116 HttpPost* completed_post, |
| 123 int http_status_code, | 117 int http_status_code, |
| 124 const std::string& response_data); | 118 const std::string& response_data); |
| 125 | 119 |
| 126 // If the request has any unpublish or unsubscribe operations, it removes | 120 // If the request has any unpublish or unsubscribe operations, it removes |
| 127 // them from our directive handlers. | 121 // them from our directive handlers. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 151 // Wrapper for the http post constructor. This is the default way | 145 // Wrapper for the http post constructor. This is the default way |
| 152 // to contact the server, but it can be overridden for testing. | 146 // to contact the server, but it can be overridden for testing. |
| 153 void SendHttpPost(net::URLRequestContextGetter* url_context_getter, | 147 void SendHttpPost(net::URLRequestContextGetter* url_context_getter, |
| 154 const std::string& rpc_name, | 148 const std::string& rpc_name, |
| 155 const std::string& api_key, | 149 const std::string& api_key, |
| 156 const std::string& auth_token, | 150 const std::string& auth_token, |
| 157 scoped_ptr<google::protobuf::MessageLite> request_proto, | 151 scoped_ptr<google::protobuf::MessageLite> request_proto, |
| 158 const PostCleanupCallback& callback); | 152 const PostCleanupCallback& callback); |
| 159 | 153 |
| 160 // These belong to the caller. | 154 // These belong to the caller. |
| 161 CopresenceDelegate* const delegate_; | 155 CopresenceDelegate* delegate_; |
| 162 DirectiveHandler* const directive_handler_; | 156 DirectiveHandler* directive_handler_; |
| 163 GCMHandler* const gcm_handler_; | |
| 164 | 157 |
| 165 PostCallback server_post_callback_; | 158 PostCallback server_post_callback_; |
| 166 | 159 |
| 167 ScopedVector<PendingRequest> pending_requests_queue_; | 160 ScopedVector<PendingRequest> pending_requests_queue_; |
| 168 TimedMap<std::string, bool> invalid_audio_token_cache_; | 161 TimedMap<std::string, bool> invalid_audio_token_cache_; |
| 169 std::map<std::string, std::string> device_id_by_auth_token_; | 162 std::map<std::string, std::string> device_id_by_auth_token_; |
| 170 std::set<HttpPost*> pending_posts_; | 163 std::set<HttpPost*> pending_posts_; |
| 171 std::string gcm_id_; | |
| 172 | 164 |
| 173 DISALLOW_COPY_AND_ASSIGN(RpcHandler); | 165 DISALLOW_COPY_AND_ASSIGN(RpcHandler); |
| 174 }; | 166 }; |
| 175 | 167 |
| 176 } // namespace copresence | 168 } // namespace copresence |
| 177 | 169 |
| 178 #endif // COMPONENTS_COPRESENCE_RPC_RPC_HANDLER_H_ | 170 #endif // COMPONENTS_COPRESENCE_RPC_RPC_HANDLER_H_ |
| OLD | NEW |