Chromium Code Reviews| 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 |
| 3 // found in the LICENSE file. | 3 // that can be 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 <google/protobuf/repeated_field.h> | |
| 9 | |
| 8 #include <string> | 10 #include <string> |
| 9 #include <vector> | 11 #include <vector> |
| 10 | 12 |
| 11 #include "base/callback.h" | 13 #include "base/callback.h" |
| 12 #include "base/macros.h" | |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/weak_ptr.h" | |
| 16 #include "components/copresence/rpc/http_post.h" | |
|
Daniel Erat
2014/08/06 16:01:17
fix sorting
Charlie
2014/08/06 19:32:20
Done.
| |
| 17 #include "components/copresence/proto/enums.pb.h" | |
| 14 #include "components/copresence/public/copresence_client_delegate.h" | 18 #include "components/copresence/public/copresence_client_delegate.h" |
| 19 #include "components/copresence/public/whispernet_client.h" | |
| 20 #include "components/copresence/timed_map.h" | |
| 15 | 21 |
| 16 namespace copresence { | 22 namespace copresence { |
| 17 | 23 |
| 24 class DirectiveHandler; | |
| 18 class ReportRequest; | 25 class ReportRequest; |
| 19 class WhispernetClient; | 26 class RequestHeader; |
| 27 class SubscribedMessage; | |
| 20 | 28 |
| 21 // This class currently handles all communication with the copresence server. | 29 // This class currently handles all communication with the copresence server. |
| 22 // NOTE: This class is a stub. | 30 class RpcHandler : public base::SupportsWeakPtr<RpcHandler> { |
| 23 class RpcHandler { | |
| 24 public: | 31 public: |
| 25 // A callback to indicate whether handler initialization succeeded. | 32 // A callback to indicate whether handler initialization succeeded. |
| 26 typedef base::Callback<void(bool)> SuccessCallback; | 33 typedef base::Callback<void(bool)> SuccessCallback; |
| 27 | 34 |
| 28 // Constructor. May call the server to register a device, | 35 // Constructor. May call the server to register a device, |
| 29 // so completion status is indicated by the SuccessCallback. | 36 // so completion status is indicated by the SuccessCallback. |
| 30 RpcHandler(CopresenceClientDelegate* delegate, | 37 explicit RpcHandler(CopresenceClientDelegate* delegate); |
|
Daniel Erat
2014/08/06 16:01:17
document ownership of |delegate|
Charlie
2014/08/06 19:32:20
Done.
| |
| 31 SuccessCallback init_done_callback); | |
| 32 | 38 |
| 33 virtual ~RpcHandler(); | 39 virtual ~RpcHandler(); |
| 34 | 40 |
| 41 // Clients must call this and wait for init_done_callback | |
|
Daniel Erat
2014/08/06 16:01:17
nit: |init_done_callback| (since that's the common
Charlie
2014/08/06 19:32:20
Done.
| |
| 42 // to be called before invoking any other methods. | |
| 43 void Initialize(const SuccessCallback& init_done_callback); | |
| 44 | |
| 35 // Send a report request | 45 // Send a report request |
| 36 void SendReportRequest(scoped_ptr<copresence::ReportRequest> request); | 46 void SendReportRequest(scoped_ptr<ReportRequest> request); |
| 37 void SendReportRequest(scoped_ptr<copresence::ReportRequest> request, | 47 void SendReportRequest(scoped_ptr<ReportRequest> request, |
| 38 const std::string& app_id, | 48 const std::string& app_id, |
| 39 const StatusCallback& callback); | 49 const StatusCallback& callback); |
| 40 | 50 |
| 41 // Report a set of tokens to the server for a given medium. | 51 // Report a set of tokens to the server for a given medium. |
| 42 void ReportTokens(copresence::TokenMedium medium, | 52 void ReportTokens(TokenMedium medium, const std::vector<std::string>& tokens); |
| 43 const std::vector<std::string>& tokens); | |
| 44 | 53 |
| 45 // Create the directive handler and connect it to the whispernet client. | 54 // Create the directive handler and connect it to |
| 46 void ConnectToWhispernet(WhispernetClient* whispernet_client); | 55 // the whispernet client specified by the delegate. |
| 56 void ConnectToWhispernet(); | |
| 47 | 57 |
| 48 // Disconnect the directive handler from the whispernet client. | 58 // Disconnect the directive handler from the whispernet client. |
| 49 void DisconnectFromWhispernet(); | 59 void DisconnectFromWhispernet(); |
| 50 | 60 |
| 51 private: | 61 private: |
| 62 typedef base::Callback<void(net::URLRequestContextGetter*, | |
|
Daniel Erat
2014/08/06 16:01:17
document what these different fields contain (the
Charlie
2014/08/06 19:32:20
Done.
| |
| 63 const std::string&, | |
| 64 scoped_ptr<google::protobuf::MessageLite>, | |
| 65 const HttpPost::ResponseCallback&)> PostCallback; | |
| 66 | |
| 67 friend class RpcHandlerTest; | |
| 68 | |
| 69 void RegisterResponseHandler(const SuccessCallback& init_done_callback, | |
| 70 int http_status_code, | |
| 71 const std::string& response_data); | |
| 72 void ReportResponseHandler(const StatusCallback& status_callback, | |
| 73 int http_status_code, | |
| 74 const std::string& response_data); | |
| 75 | |
| 76 void DispatchMessages( | |
| 77 const google::protobuf::RepeatedPtrField<SubscribedMessage>& | |
| 78 subscribed_messages); | |
| 79 | |
| 80 RequestHeader* CreateRequestHeader(const std::string& client_name) const; | |
| 81 | |
| 82 template <class T> | |
| 83 void SendServerRequest(const std::string& rpc_name, | |
| 84 const std::string& app_id, | |
| 85 scoped_ptr<T> request, | |
| 86 const HttpPost::ResponseCallback& response_handler); | |
| 87 | |
| 88 // This method receives the request to encode a token and forwards it to | |
| 89 // whispernet, setting the samples return callback to samples_callback. | |
| 90 void AudioDirectiveListToWhispernetConnector( | |
| 91 const std::string& token, | |
| 92 const WhispernetClient::SamplesCallback& samples_callback); | |
| 93 | |
| 94 CopresenceClientDelegate* delegate_; | |
|
Daniel Erat
2014/08/06 16:01:17
document ownership
Charlie
2014/08/06 19:32:20
Done.
| |
| 95 TimedMap<std::string, bool> invalid_audio_token_cache_; | |
| 96 PostCallback server_post_callback_; | |
| 97 | |
| 98 std::string device_id_; | |
| 99 scoped_ptr<DirectiveHandler> directive_handler_; | |
| 100 | |
| 52 DISALLOW_COPY_AND_ASSIGN(RpcHandler); | 101 DISALLOW_COPY_AND_ASSIGN(RpcHandler); |
| 53 }; | 102 }; |
| 54 | 103 |
| 55 } // namespace copresence | 104 } // namespace copresence |
| 56 | 105 |
| 57 #endif // COMPONENTS_COPRESENCE_RPC_RPC_HANDLER_H_ | 106 #endif // COMPONENTS_COPRESENCE_RPC_RPC_HANDLER_H_ |
| OLD | NEW |