| 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/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/weak_ptr.h" | |
| 15 #include "components/copresence/proto/rpcs.pb.h" | 14 #include "components/copresence/proto/rpcs.pb.h" |
| 16 #include "components/copresence/public/copresence_manager.h" | 15 #include "components/copresence/public/copresence_manager.h" |
| 17 | 16 |
| 18 namespace net { | 17 namespace net { |
| 19 class URLContextGetter; | 18 class URLContextGetter; |
| 20 } | 19 } |
| 21 | 20 |
| 22 namespace copresence { | 21 namespace copresence { |
| 23 | 22 |
| 24 class RpcHandler; | 23 class RpcHandler; |
| 25 | 24 |
| 26 struct PendingRequest { | 25 struct PendingRequest { |
| 27 PendingRequest(const ReportRequest& report, | 26 PendingRequest(const ReportRequest& report, |
| 28 const std::string app_id, | 27 const std::string app_id, |
| 29 const StatusCallback& callback); | 28 const StatusCallback& callback); |
| 30 ~PendingRequest(); | 29 ~PendingRequest(); |
| 31 | 30 |
| 32 ReportRequest report; | 31 ReportRequest report; |
| 33 std::string app_id; | 32 std::string app_id; |
| 34 StatusCallback callback; | 33 StatusCallback callback; |
| 35 }; | 34 }; |
| 36 | 35 |
| 37 // The implementation for CopresenceManager. | 36 // The implementation for CopresenceManager. |
| 38 class CopresenceManagerImpl : public CopresenceManager, | 37 class CopresenceManagerImpl : public CopresenceManager { |
| 39 public base::SupportsWeakPtr<CopresenceManagerImpl> { | |
| 40 public: | 38 public: |
| 41 virtual ~CopresenceManagerImpl(); | 39 virtual ~CopresenceManagerImpl(); |
| 42 virtual void ExecuteReportRequest(ReportRequest request, | 40 virtual void ExecuteReportRequest(ReportRequest request, |
| 43 const std::string& app_id, | 41 const std::string& app_id, |
| 44 const StatusCallback& callback) OVERRIDE; | 42 const StatusCallback& callback) OVERRIDE; |
| 45 | 43 |
| 46 private: | 44 private: |
| 47 // Create managers with the CopresenceManager::Create() method. | 45 // Create managers with the CopresenceManager::Create() method. |
| 48 friend class CopresenceManager; | 46 friend class CopresenceManager; |
| 49 CopresenceManagerImpl(CopresenceDelegate* delegate); | 47 CopresenceManagerImpl(CopresenceDelegate* delegate); |
| 50 | 48 |
| 51 void CompleteInitialization(); | 49 void CompleteInitialization(); |
| 52 void InitStepComplete(const std::string& step, bool success); | 50 void InitStepComplete(const std::string& step, bool success); |
| 53 | 51 |
| 54 bool init_failed_; | 52 bool init_failed_; |
| 55 std::vector<PendingRequest> pending_requests_queue_; | 53 std::vector<PendingRequest> pending_requests_queue_; |
| 56 | 54 |
| 55 base::CancelableCallback<void(bool)> init_callback_; |
| 56 |
| 57 // TODO(rkc): This code is almost identical to what we use in feedback to | 57 // TODO(rkc): This code is almost identical to what we use in feedback to |
| 58 // perform multiple blocking tasks and then run a post process method. Look | 58 // perform multiple blocking tasks and then run a post process method. Look |
| 59 // into refactoring it all out to a common construct, like maybe a | 59 // into refactoring it all out to a common construct, like maybe a |
| 60 // PostMultipleTasksAndReply? | 60 // PostMultipleTasksAndReply? |
| 61 size_t pending_init_operations_; | 61 size_t pending_init_operations_; |
| 62 | 62 |
| 63 CopresenceDelegate* const delegate_; | 63 CopresenceDelegate* const delegate_; |
| 64 scoped_ptr<RpcHandler> rpc_handler_; | 64 scoped_ptr<RpcHandler> rpc_handler_; |
| 65 | 65 |
| 66 DISALLOW_COPY_AND_ASSIGN(CopresenceManagerImpl); | 66 DISALLOW_COPY_AND_ASSIGN(CopresenceManagerImpl); |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 } // namespace copresence | 69 } // namespace copresence |
| 70 | 70 |
| 71 #endif // COMPONENTS_COPRESENCE_COPRESENCE_MANAGER_IMPL_H_ | 71 #endif // COMPONENTS_COPRESENCE_COPRESENCE_MANAGER_IMPL_H_ |
| OLD | NEW |