Index: components/copresence/rpc/rpc_handler.h |
diff --git a/components/copresence/rpc/rpc_handler.h b/components/copresence/rpc/rpc_handler.h |
index dee7220ac78045659d7e0c62868a344df22026d7..50d3d2d23f402f407b8d3b35f0cb0643b172b677 100644 |
--- a/components/copresence/rpc/rpc_handler.h |
+++ b/components/copresence/rpc/rpc_handler.h |
@@ -1,54 +1,103 @@ |
// Copyright 2014 The Chromium Authors. All rights reserved. |
-// Use of this source code is governed by a BSD-style license that can be |
-// found in the LICENSE file. |
+// Use of this source code is governed by a BSD-style license |
+// that can be found in the LICENSE file. |
#ifndef COMPONENTS_COPRESENCE_RPC_RPC_HANDLER_H_ |
#define COMPONENTS_COPRESENCE_RPC_RPC_HANDLER_H_ |
+#include <google/protobuf/repeated_field.h> |
+ |
#include <string> |
#include <vector> |
#include "base/callback.h" |
-#include "base/macros.h" |
#include "base/memory/scoped_ptr.h" |
+#include "base/memory/weak_ptr.h" |
+#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.
|
+#include "components/copresence/proto/enums.pb.h" |
#include "components/copresence/public/copresence_client_delegate.h" |
+#include "components/copresence/public/whispernet_client.h" |
+#include "components/copresence/timed_map.h" |
namespace copresence { |
+class DirectiveHandler; |
class ReportRequest; |
-class WhispernetClient; |
+class RequestHeader; |
+class SubscribedMessage; |
// This class currently handles all communication with the copresence server. |
-// NOTE: This class is a stub. |
-class RpcHandler { |
+class RpcHandler : public base::SupportsWeakPtr<RpcHandler> { |
public: |
// A callback to indicate whether handler initialization succeeded. |
typedef base::Callback<void(bool)> SuccessCallback; |
// Constructor. May call the server to register a device, |
// so completion status is indicated by the SuccessCallback. |
- RpcHandler(CopresenceClientDelegate* delegate, |
- SuccessCallback init_done_callback); |
+ explicit RpcHandler(CopresenceClientDelegate* delegate); |
Daniel Erat
2014/08/06 16:01:17
document ownership of |delegate|
Charlie
2014/08/06 19:32:20
Done.
|
virtual ~RpcHandler(); |
+ // 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.
|
+ // to be called before invoking any other methods. |
+ void Initialize(const SuccessCallback& init_done_callback); |
+ |
// Send a report request |
- void SendReportRequest(scoped_ptr<copresence::ReportRequest> request); |
- void SendReportRequest(scoped_ptr<copresence::ReportRequest> request, |
+ void SendReportRequest(scoped_ptr<ReportRequest> request); |
+ void SendReportRequest(scoped_ptr<ReportRequest> request, |
const std::string& app_id, |
const StatusCallback& callback); |
// Report a set of tokens to the server for a given medium. |
- void ReportTokens(copresence::TokenMedium medium, |
- const std::vector<std::string>& tokens); |
+ void ReportTokens(TokenMedium medium, const std::vector<std::string>& tokens); |
- // Create the directive handler and connect it to the whispernet client. |
- void ConnectToWhispernet(WhispernetClient* whispernet_client); |
+ // Create the directive handler and connect it to |
+ // the whispernet client specified by the delegate. |
+ void ConnectToWhispernet(); |
// Disconnect the directive handler from the whispernet client. |
void DisconnectFromWhispernet(); |
private: |
+ 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.
|
+ const std::string&, |
+ scoped_ptr<google::protobuf::MessageLite>, |
+ const HttpPost::ResponseCallback&)> PostCallback; |
+ |
+ friend class RpcHandlerTest; |
+ |
+ void RegisterResponseHandler(const SuccessCallback& init_done_callback, |
+ int http_status_code, |
+ const std::string& response_data); |
+ void ReportResponseHandler(const StatusCallback& status_callback, |
+ int http_status_code, |
+ const std::string& response_data); |
+ |
+ void DispatchMessages( |
+ const google::protobuf::RepeatedPtrField<SubscribedMessage>& |
+ subscribed_messages); |
+ |
+ RequestHeader* CreateRequestHeader(const std::string& client_name) const; |
+ |
+ template <class T> |
+ void SendServerRequest(const std::string& rpc_name, |
+ const std::string& app_id, |
+ scoped_ptr<T> request, |
+ const HttpPost::ResponseCallback& response_handler); |
+ |
+ // This method receives the request to encode a token and forwards it to |
+ // whispernet, setting the samples return callback to samples_callback. |
+ void AudioDirectiveListToWhispernetConnector( |
+ const std::string& token, |
+ const WhispernetClient::SamplesCallback& samples_callback); |
+ |
+ CopresenceClientDelegate* delegate_; |
Daniel Erat
2014/08/06 16:01:17
document ownership
Charlie
2014/08/06 19:32:20
Done.
|
+ TimedMap<std::string, bool> invalid_audio_token_cache_; |
+ PostCallback server_post_callback_; |
+ |
+ std::string device_id_; |
+ scoped_ptr<DirectiveHandler> directive_handler_; |
+ |
DISALLOW_COPY_AND_ASSIGN(RpcHandler); |
}; |