| 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> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "components/copresence/proto/enums.pb.h" | 14 #include "components/copresence/proto/enums.pb.h" |
| 15 #include "components/copresence/public/copresence_client_delegate.h" | 15 #include "components/copresence/public/copresence_manager_delegate.h" |
| 16 #include "components/copresence/public/whispernet_client.h" | 16 #include "components/copresence/public/whispernet_client.h" |
| 17 #include "components/copresence/rpc/http_post.h" | 17 #include "components/copresence/rpc/http_post.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 class DirectiveHandler; | 22 class DirectiveHandler; |
| 23 class ReportRequest; | 23 class ReportRequest; |
| 24 class RequestHeader; | 24 class RequestHeader; |
| 25 class SubscribedMessage; | 25 class SubscribedMessage; |
| 26 | 26 |
| 27 // This class currently handles all communication with the copresence server. | 27 // This class currently handles all communication with the copresence server. |
| 28 class RpcHandler { | 28 class RpcHandler { |
| 29 public: | 29 public: |
| 30 // A callback to indicate whether handler initialization succeeded. | 30 // A callback to indicate whether handler initialization succeeded. |
| 31 typedef base::Callback<void(bool)> SuccessCallback; | 31 typedef base::Callback<void(bool)> SuccessCallback; |
| 32 | 32 |
| 33 // Report rpc name to send to Apiary. | 33 // Report rpc name to send to Apiary. |
| 34 static const char kReportRequestRpcName[]; | 34 static const char kReportRequestRpcName[]; |
| 35 | 35 |
| 36 // Constructor. |delegate| is owned by the caller, | 36 // Constructor. |delegate| is owned by the caller, |
| 37 // and must be valid as long as the RpcHandler exists. | 37 // and must be valid as long as the RpcHandler exists. |
| 38 explicit RpcHandler(CopresenceClientDelegate* delegate); | 38 explicit RpcHandler(CopresenceManagerDelegate* delegate); |
| 39 | 39 |
| 40 virtual ~RpcHandler(); | 40 virtual ~RpcHandler(); |
| 41 | 41 |
| 42 // Clients must call this and wait for |init_done_callback| | 42 // Clients must call this and wait for |init_done_callback| |
| 43 // to be called before invoking any other methods. | 43 // to be called before invoking any other methods. |
| 44 void Initialize(const SuccessCallback& init_done_callback); | 44 void Initialize(const SuccessCallback& init_done_callback); |
| 45 | 45 |
| 46 // Send a report request | 46 // Send a report request. |
| 47 void SendReportRequest(scoped_ptr<ReportRequest> request); | 47 void SendReportRequest(scoped_ptr<ReportRequest> request); |
| 48 void SendReportRequest(scoped_ptr<ReportRequest> request, | 48 void SendReportRequest(scoped_ptr<ReportRequest> request, |
| 49 const std::string& app_id, | 49 const std::string& app_id, |
| 50 const StatusCallback& callback); | 50 const StatusCallback& callback); |
| 51 | 51 |
| 52 // Report a set of tokens to the server for a given medium. | 52 // Report a set of tokens to the server for a given medium. |
| 53 void ReportTokens(const std::vector<AudioToken>& tokens); | 53 void ReportTokens(const std::vector<AudioToken>& tokens); |
| 54 | 54 |
| 55 // Create the directive handler and connect it to | 55 // Create the directive handler and connect it to |
| 56 // the whispernet client specified by the delegate. | 56 // the whispernet client specified by the delegate. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 scoped_ptr<google::protobuf::MessageLite> request_proto, | 113 scoped_ptr<google::protobuf::MessageLite> request_proto, |
| 114 const PostCleanupCallback& callback); | 114 const PostCleanupCallback& callback); |
| 115 | 115 |
| 116 // This method receives the request to encode a token and forwards it to | 116 // This method receives the request to encode a token and forwards it to |
| 117 // whispernet, setting the samples return callback to samples_callback. | 117 // whispernet, setting the samples return callback to samples_callback. |
| 118 void AudioDirectiveListToWhispernetConnector( | 118 void AudioDirectiveListToWhispernetConnector( |
| 119 const std::string& token, | 119 const std::string& token, |
| 120 bool audible, | 120 bool audible, |
| 121 const WhispernetClient::SamplesCallback& samples_callback); | 121 const WhispernetClient::SamplesCallback& samples_callback); |
| 122 | 122 |
| 123 CopresenceClientDelegate* delegate_; // Belongs to the caller. | 123 CopresenceManagerDelegate* delegate_; // Belongs to the caller. |
| 124 TimedMap<std::string, bool> invalid_audio_token_cache_; | 124 TimedMap<std::string, bool> invalid_audio_token_cache_; |
| 125 PostCallback server_post_callback_; | 125 PostCallback server_post_callback_; |
| 126 | 126 |
| 127 std::string device_id_; | 127 std::string device_id_; |
| 128 scoped_ptr<DirectiveHandler> directive_handler_; | 128 scoped_ptr<DirectiveHandler> directive_handler_; |
| 129 std::set<HttpPost*> pending_posts_; | 129 std::set<HttpPost*> pending_posts_; |
| 130 | 130 |
| 131 DISALLOW_COPY_AND_ASSIGN(RpcHandler); | 131 DISALLOW_COPY_AND_ASSIGN(RpcHandler); |
| 132 }; | 132 }; |
| 133 | 133 |
| 134 } // namespace copresence | 134 } // namespace copresence |
| 135 | 135 |
| 136 #endif // COMPONENTS_COPRESENCE_RPC_RPC_HANDLER_H_ | 136 #endif // COMPONENTS_COPRESENCE_RPC_RPC_HANDLER_H_ |
| OLD | NEW |