Chromium Code Reviews| Index: components/copresence/public/copresence_client.h |
| diff --git a/components/copresence/public/copresence_client.h b/components/copresence/public/copresence_client.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f52573988e24e645853873c2dc68d14ebb22e07b |
| --- /dev/null |
| +++ b/components/copresence/public/copresence_client.h |
| @@ -0,0 +1,90 @@ |
| +// 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. |
| + |
| +#ifndef COMPONENTS_COPRESENCE_PUBLIC_COPRESENCE_CLIENT_H_ |
| +#define COMPONENTS_COPRESENCE_PUBLIC_COPRESENCE_CLIENT_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/proto/rpcs.pb.h" |
| +#include "components/copresence/public/copresence_client_delegate.h" |
| + |
| +namespace net { |
| +class URLContextGetter; |
| +} |
| + |
| +namespace copresence { |
| + |
| +class CopresenceClientDelegate; |
| +class RpcHandler; |
| +class WhispernetClient; |
| + |
| +struct PendingRequest { |
| + PendingRequest(const copresence::ReportRequest& report, |
| + const std::string app_id, |
| + const StatusCallback& callback); |
| + ~PendingRequest(); |
| + |
| + copresence::ReportRequest report; |
| + std::string app_id; |
| + StatusCallback callback; |
| +}; |
| + |
| +// The CopresenceClient class is the central interface for Copresence |
| +// functionality. This class handles all the initialization and delegation of |
| +// copresence tasks. Any user of copresence only needs to interact with this |
| +// client. |
| +class CopresenceClient : public base::SupportsWeakPtr<CopresenceClient> { |
| + public: |
| + // We do not take ownership of the delegate but we do take ownership of the |
| + // whispernet_client. This is because the whispernet_client is tied to this |
| + // copresence client (and various objects that it owns) while no such |
| + // restriction exists for the delegate. Theoretically a client could use the |
| + // same delegate for multiple CopresenceClients, not the case a |
| + // WhispernetClient. |
|
jochen (gone - plz use gerrit)
2014/07/31 14:27:06
sorry, I still didn't fully understand it. I thoug
jochen (gone - plz use gerrit)
2014/07/31 14:46:41
i'm not really sure how to make this API a lot nic
rkc
2014/07/31 15:44:13
So I thought a bit more about this and realized th
|
| + CopresenceClient(CopresenceClientDelegate* delegate, |
| + scoped_ptr<WhispernetClient> whispernet_client); |
| + virtual ~CopresenceClient(); |
| + |
| + WhispernetClient* whispernet_client(); |
| + |
| + // This method will execute a report request. Each report request can have |
| + // multiple (un)publishes, (un)subscribes. This will ensure that once the |
| + // client is initialized, it sends all request to the server and handles |
| + // the response. If an error is encountered, the status callback is used |
| + // to relay it to the requester. |
| + void ExecuteReportRequest(copresence::ReportRequest request, |
| + const std::string& app_id, |
| + const StatusCallback& callback); |
| + |
| + // Called before the API (and thus the Client) is destructed. |
| + void Shutdown(); |
| + |
| + private: |
| + void CompleteInitialization(); |
| + void InitStepComplete(const std::string& step, bool success); |
| + |
| + bool init_failed_; |
| + std::vector<PendingRequest> pending_requests_queue_; |
| + |
| + // TODO(rkc): This code is almost identical to what we use in feedback to |
| + // perform multiple blocking tasks and then run a post process method. Look |
| + // into refactoring it all out to a common construct, like maybe a |
| + // PostMultipleTasksAndReply? |
| + size_t pending_init_operations_; |
| + |
| + scoped_ptr<WhispernetClient> whispernet_client_; |
| + scoped_ptr<RpcHandler> rpc_handler_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(CopresenceClient); |
| +}; |
| + |
| +} // namespace copresence |
| + |
| +#endif // COMPONENTS_COPRESENCE_PUBLIC_COPRESENCE_CLIENT_H_ |