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 that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_COPRESENCE_COPRESENCE_MANAGER_IMPL_H_ | 5 #ifndef COMPONENTS_COPRESENCE_COPRESENCE_MANAGER_IMPL_H_ |
6 #define COMPONENTS_COPRESENCE_COPRESENCE_MANAGER_IMPL_H_ | 6 #define COMPONENTS_COPRESENCE_COPRESENCE_MANAGER_IMPL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/cancelable_callback.h" | 12 #include "base/cancelable_callback.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "components/copresence/proto/rpcs.pb.h" | 15 #include "components/copresence/proto/rpcs.pb.h" |
16 #include "components/copresence/public/copresence_manager.h" | 16 #include "components/copresence/public/copresence_manager.h" |
17 | 17 |
18 namespace net { | 18 namespace net { |
19 class URLContextGetter; | 19 class URLContextGetter; |
20 } | 20 } |
21 | 21 |
22 namespace copresence { | 22 namespace copresence { |
23 | 23 |
24 class RpcHandler; | 24 class RpcHandler; |
25 | 25 |
26 struct PendingRequest { | 26 struct PendingRequest { |
27 PendingRequest(const ReportRequest& report, | 27 PendingRequest(const ReportRequest& report, |
28 const std::string app_id, | 28 const std::string& app_id, |
29 const std::string& auth_token, | |
29 const StatusCallback& callback); | 30 const StatusCallback& callback); |
30 ~PendingRequest(); | 31 ~PendingRequest(); |
31 | 32 |
32 ReportRequest report; | 33 scoped_ptr<ReportRequest> report; |
33 std::string app_id; | 34 std::string app_id; |
35 std::string auth_token; | |
34 StatusCallback callback; | 36 StatusCallback callback; |
35 }; | 37 }; |
36 | 38 |
37 // The implementation for CopresenceManager. | 39 // The implementation for CopresenceManager. Responsible primarily for |
40 // client-side initialization. The RpcHandler handles all the details | |
41 // of interacting with the server. | |
38 class CopresenceManagerImpl : public CopresenceManager { | 42 class CopresenceManagerImpl : public CopresenceManager { |
39 public: | 43 public: |
40 ~CopresenceManagerImpl() override; | 44 ~CopresenceManagerImpl() override; |
41 void ExecuteReportRequest(ReportRequest request, | 45 void ExecuteReportRequest(const ReportRequest& request, |
42 const std::string& app_id, | 46 const std::string& app_id, |
43 const StatusCallback& callback) override; | 47 const StatusCallback& callback) override; |
44 | 48 |
45 private: | 49 private: |
46 // Create managers with the CopresenceManager::Create() method. | 50 // Create managers with the CopresenceManager::Create() method. |
47 friend class CopresenceManager; | 51 friend class CopresenceManager; |
48 CopresenceManagerImpl(CopresenceDelegate* delegate); | 52 CopresenceManagerImpl(CopresenceDelegate* delegate); |
49 | 53 |
50 void CompleteInitialization(); | 54 void CompleteInitialization(); |
51 void InitStepComplete(const std::string& step, bool success); | 55 void InitStepComplete(const std::string& step, bool success); |
52 | 56 |
53 bool init_failed_; | 57 bool init_failed_; |
54 std::vector<PendingRequest> pending_requests_queue_; | 58 std::vector<scoped_ptr<PendingRequest>> pending_requests_queue_; |
rkc
2014/10/28 04:12:46
Don't use scoped_ptrs in std C++ containers; they
Charlie
2014/10/28 22:51:52
Actually the ScopedVector works just fine. We don'
| |
55 | 59 |
56 base::CancelableCallback<void(bool)> init_callback_; | 60 base::CancelableCallback<void(bool)> whispernet_init_callback_; |
57 | 61 |
58 // TODO(rkc): This code is almost identical to what we use in feedback to | 62 // TODO(rkc): This code is almost identical to what we use in feedback to |
59 // perform multiple blocking tasks and then run a post process method. Look | 63 // perform multiple blocking tasks and then run a post process method. Look |
60 // into refactoring it all out to a common construct, like maybe a | 64 // into refactoring it all out to a common construct, like maybe a |
61 // PostMultipleTasksAndReply? | 65 // PostMultipleTasksAndReply? |
62 size_t pending_init_operations_; | 66 int pending_init_operations_; |
63 | 67 |
64 CopresenceDelegate* const delegate_; | 68 CopresenceDelegate* const delegate_; |
65 scoped_ptr<RpcHandler> rpc_handler_; | 69 scoped_ptr<RpcHandler> rpc_handler_; |
66 | 70 |
67 DISALLOW_COPY_AND_ASSIGN(CopresenceManagerImpl); | 71 DISALLOW_COPY_AND_ASSIGN(CopresenceManagerImpl); |
68 }; | 72 }; |
69 | 73 |
70 } // namespace copresence | 74 } // namespace copresence |
71 | 75 |
72 #endif // COMPONENTS_COPRESENCE_COPRESENCE_MANAGER_IMPL_H_ | 76 #endif // COMPONENTS_COPRESENCE_COPRESENCE_MANAGER_IMPL_H_ |
OLD | NEW |