| 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 <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 private: | 59 private: |
| 60 // An HttpPost::ResponseCallback prepended with an HttpPost object | 60 // An HttpPost::ResponseCallback prepended with an HttpPost object |
| 61 // that needs to be deleted. | 61 // that needs to be deleted. |
| 62 typedef base::Callback<void(HttpPost*, int, const std::string&)> | 62 typedef base::Callback<void(HttpPost*, int, const std::string&)> |
| 63 PostCleanupCallback; | 63 PostCleanupCallback; |
| 64 | 64 |
| 65 // Callback to allow tests to stub out HTTP POST behavior. | 65 // Callback to allow tests to stub out HTTP POST behavior. |
| 66 // Arguments: | 66 // Arguments: |
| 67 // URLRequestContextGetter: Context for the HTTP POST request. | 67 // URLRequestContextGetter: Context for the HTTP POST request. |
| 68 // string: Name of the rpc to invoke. URL format: server.google.com/rpc_name | 68 // string: Name of the rpc to invoke. URL format: server.google.com/rpc_name |
| 69 // string: The id of the app making the request. |
| 69 // MessageLite: Contents of POST request to be sent. This needs to be | 70 // MessageLite: Contents of POST request to be sent. This needs to be |
| 70 // a (scoped) pointer to ease handling of the abstract MessageLite class. | 71 // a (scoped) pointer to ease handling of the abstract MessageLite class. |
| 71 // ResponseCallback: Receives the response to the request. | 72 // ResponseCallback: Receives the response to the request. |
| 72 typedef base::Callback<void(net::URLRequestContextGetter*, | 73 typedef base::Callback<void(net::URLRequestContextGetter*, |
| 73 const std::string&, | 74 const std::string&, |
| 75 const std::string&, |
| 74 scoped_ptr<google::protobuf::MessageLite>, | 76 scoped_ptr<google::protobuf::MessageLite>, |
| 75 const PostCleanupCallback&)> PostCallback; | 77 const PostCleanupCallback&)> PostCallback; |
| 76 | 78 |
| 77 friend class RpcHandlerTest; | 79 friend class RpcHandlerTest; |
| 78 | 80 |
| 79 void RegisterResponseHandler(const SuccessCallback& init_done_callback, | 81 void RegisterResponseHandler(const SuccessCallback& init_done_callback, |
| 80 HttpPost* completed_post, | 82 HttpPost* completed_post, |
| 81 int http_status_code, | 83 int http_status_code, |
| 82 const std::string& response_data); | 84 const std::string& response_data); |
| 83 void ReportResponseHandler(const StatusCallback& status_callback, | 85 void ReportResponseHandler(const StatusCallback& status_callback, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 103 template <class T> | 105 template <class T> |
| 104 void SendServerRequest(const std::string& rpc_name, | 106 void SendServerRequest(const std::string& rpc_name, |
| 105 const std::string& app_id, | 107 const std::string& app_id, |
| 106 scoped_ptr<T> request, | 108 scoped_ptr<T> request, |
| 107 const PostCleanupCallback& response_handler); | 109 const PostCleanupCallback& response_handler); |
| 108 | 110 |
| 109 // Wrapper for the http post constructor. This is the default way | 111 // Wrapper for the http post constructor. This is the default way |
| 110 // to contact the server, but it can be overridden for testing. | 112 // to contact the server, but it can be overridden for testing. |
| 111 void SendHttpPost(net::URLRequestContextGetter* url_context_getter, | 113 void SendHttpPost(net::URLRequestContextGetter* url_context_getter, |
| 112 const std::string& rpc_name, | 114 const std::string& rpc_name, |
| 115 const std::string& app_id, |
| 113 scoped_ptr<google::protobuf::MessageLite> request_proto, | 116 scoped_ptr<google::protobuf::MessageLite> request_proto, |
| 114 const PostCleanupCallback& callback); | 117 const PostCleanupCallback& callback); |
| 115 | 118 |
| 116 // This method receives the request to encode a token and forwards it to | 119 // This method receives the request to encode a token and forwards it to |
| 117 // whispernet, setting the samples return callback to samples_callback. | 120 // whispernet, setting the samples return callback to samples_callback. |
| 118 void AudioDirectiveListToWhispernetConnector( | 121 void AudioDirectiveListToWhispernetConnector( |
| 119 const std::string& token, | 122 const std::string& token, |
| 120 bool audible, | 123 bool audible, |
| 121 const WhispernetClient::SamplesCallback& samples_callback); | 124 const WhispernetClient::SamplesCallback& samples_callback); |
| 122 | 125 |
| 123 CopresenceDelegate* delegate_; // Belongs to the caller. | 126 CopresenceDelegate* delegate_; // Belongs to the caller. |
| 124 TimedMap<std::string, bool> invalid_audio_token_cache_; | 127 TimedMap<std::string, bool> invalid_audio_token_cache_; |
| 125 PostCallback server_post_callback_; | 128 PostCallback server_post_callback_; |
| 126 | 129 |
| 127 std::string device_id_; | 130 std::string device_id_; |
| 128 scoped_ptr<DirectiveHandler> directive_handler_; | 131 scoped_ptr<DirectiveHandler> directive_handler_; |
| 129 std::set<HttpPost*> pending_posts_; | 132 std::set<HttpPost*> pending_posts_; |
| 130 | 133 |
| 131 DISALLOW_COPY_AND_ASSIGN(RpcHandler); | 134 DISALLOW_COPY_AND_ASSIGN(RpcHandler); |
| 132 }; | 135 }; |
| 133 | 136 |
| 134 } // namespace copresence | 137 } // namespace copresence |
| 135 | 138 |
| 136 #endif // COMPONENTS_COPRESENCE_RPC_RPC_HANDLER_H_ | 139 #endif // COMPONENTS_COPRESENCE_RPC_RPC_HANDLER_H_ |
| OLD | NEW |