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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_COPRESENCE_PUBLIC_COPRESENCE_CLIENT_H_
6 #define COMPONENTS_COPRESENCE_PUBLIC_COPRESENCE_CLIENT_H_
11 #include "base/callback.h"
12 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "components/copresence/proto/rpcs.pb.h"
16 #include "components/copresence/public/copresence_client_delegate.h"
19 class URLContextGetter;
22 namespace copresence {
24 class CopresenceClientDelegate;
27 struct PendingRequest {
28 PendingRequest(const copresence::ReportRequest& report,
29 const std::string app_id,
30 const StatusCallback& callback);
33 copresence::ReportRequest report;
35 StatusCallback callback;
38 // The CopresenceClient class is the central interface for Copresence
39 // functionality. This class handles all the initialization and delegation
40 // of copresence tasks. Any user of copresence only needs to interact
42 class CopresenceClient : public base::SupportsWeakPtr<CopresenceClient> {
44 // The delegate must outlive us.
45 explicit CopresenceClient(CopresenceClientDelegate* delegate);
46 virtual ~CopresenceClient();
48 // This method will execute a report request. Each report request can have
49 // multiple (un)publishes, (un)subscribes. This will ensure that once the
50 // client is initialized, it sends all request to the server and handles
51 // the response. If an error is encountered, the status callback is used
52 // to relay it to the requester.
53 void ExecuteReportRequest(copresence::ReportRequest request,
54 const std::string& app_id,
55 const StatusCallback& callback);
58 void CompleteInitialization();
59 void InitStepComplete(const std::string& step, bool success);
61 CopresenceClientDelegate* delegate_;
63 std::vector<PendingRequest> pending_requests_queue_;
65 // TODO(rkc): This code is almost identical to what we use in feedback to
66 // perform multiple blocking tasks and then run a post process method. Look
67 // into refactoring it all out to a common construct, like maybe a
68 // PostMultipleTasksAndReply?
69 size_t pending_init_operations_;
71 scoped_ptr<RpcHandler> rpc_handler_;
73 DISALLOW_COPY_AND_ASSIGN(CopresenceClient);
76 } // namespace copresence
78 #endif // COMPONENTS_COPRESENCE_PUBLIC_COPRESENCE_CLIENT_H_