Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #ifndef COMPONENTS_COPRESENCE_PUBLIC_COPRESENCE_CLIENT_H_ | |
| 6 #define COMPONENTS_COPRESENCE_PUBLIC_COPRESENCE_CLIENT_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 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" | |
| 17 | |
| 18 namespace net { | |
| 19 class URLContextGetter; | |
| 20 } | |
| 21 | |
| 22 namespace copresence { | |
| 23 | |
| 24 class CopresenceClientDelegate; | |
| 25 class RpcHandler; | |
| 26 class WhispernetClient; | |
| 27 | |
| 28 struct PendingRequest { | |
| 29 PendingRequest(const copresence::ReportRequest& report, | |
| 30 const std::string app_id, | |
| 31 const StatusCallback& callback); | |
| 32 ~PendingRequest(); | |
| 33 | |
| 34 copresence::ReportRequest report; | |
| 35 std::string app_id; | |
| 36 StatusCallback callback; | |
| 37 }; | |
| 38 | |
| 39 // The CopresenceClient class is the central interface for Copresence | |
| 40 // functionality. This class handles all the initialization and delegation of | |
| 41 // copresence tasks. Any user of copresence only needs to interact with this | |
| 42 // client. | |
| 43 class CopresenceClient : public base::SupportsWeakPtr<CopresenceClient> { | |
| 44 public: | |
| 45 // We do not take ownership of the delegate but we do take ownership of the | |
| 46 // whispernet_client. This is because the whispernet_client is tied to this | |
| 47 // copresence client (and various objects that it owns) while no such | |
| 48 // restriction exists for the delegate. Theoretically a client could use the | |
| 49 // same delegate for multiple CopresenceClients, not the case a | |
| 50 // 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
| |
| 51 CopresenceClient(CopresenceClientDelegate* delegate, | |
| 52 scoped_ptr<WhispernetClient> whispernet_client); | |
| 53 virtual ~CopresenceClient(); | |
| 54 | |
| 55 WhispernetClient* whispernet_client(); | |
| 56 | |
| 57 // This method will execute a report request. Each report request can have | |
| 58 // multiple (un)publishes, (un)subscribes. This will ensure that once the | |
| 59 // client is initialized, it sends all request to the server and handles | |
| 60 // the response. If an error is encountered, the status callback is used | |
| 61 // to relay it to the requester. | |
| 62 void ExecuteReportRequest(copresence::ReportRequest request, | |
| 63 const std::string& app_id, | |
| 64 const StatusCallback& callback); | |
| 65 | |
| 66 // Called before the API (and thus the Client) is destructed. | |
| 67 void Shutdown(); | |
| 68 | |
| 69 private: | |
| 70 void CompleteInitialization(); | |
| 71 void InitStepComplete(const std::string& step, bool success); | |
| 72 | |
| 73 bool init_failed_; | |
| 74 std::vector<PendingRequest> pending_requests_queue_; | |
| 75 | |
| 76 // TODO(rkc): This code is almost identical to what we use in feedback to | |
| 77 // perform multiple blocking tasks and then run a post process method. Look | |
| 78 // into refactoring it all out to a common construct, like maybe a | |
| 79 // PostMultipleTasksAndReply? | |
| 80 size_t pending_init_operations_; | |
| 81 | |
| 82 scoped_ptr<WhispernetClient> whispernet_client_; | |
| 83 scoped_ptr<RpcHandler> rpc_handler_; | |
| 84 | |
| 85 DISALLOW_COPY_AND_ASSIGN(CopresenceClient); | |
| 86 }; | |
| 87 | |
| 88 } // namespace copresence | |
| 89 | |
| 90 #endif // COMPONENTS_COPRESENCE_PUBLIC_COPRESENCE_CLIENT_H_ | |
| OLD | NEW |