| 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 | 9 |
| 10 #include "base/cancelable_callback.h" | 10 #include "base/cancelable_callback.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
| 14 #include "components/copresence/public/copresence_manager.h" | 14 #include "components/copresence/public/copresence_manager.h" |
| 15 | 15 |
| 16 namespace base { |
| 17 class Timer; |
| 18 } |
| 19 |
| 16 namespace net { | 20 namespace net { |
| 17 class URLContextGetter; | 21 class URLContextGetter; |
| 18 } | 22 } |
| 19 | 23 |
| 20 namespace copresence { | 24 namespace copresence { |
| 21 | 25 |
| 22 class DirectiveHandler; | 26 class DirectiveHandler; |
| 23 class ReportRequest; | 27 class ReportRequest; |
| 24 class RpcHandler; | 28 class RpcHandler; |
| 25 | 29 |
| 26 struct PendingRequest { | 30 struct PendingRequest { |
| 27 PendingRequest(const ReportRequest& report, | 31 PendingRequest(const ReportRequest& report, |
| 28 const std::string& app_id, | 32 const std::string& app_id, |
| 29 const std::string& auth_token, | 33 const std::string& auth_token, |
| 30 const StatusCallback& callback); | 34 const StatusCallback& callback); |
| 31 ~PendingRequest(); | 35 ~PendingRequest(); |
| 32 | 36 |
| 33 scoped_ptr<ReportRequest> report; | 37 scoped_ptr<ReportRequest> report; |
| 34 std::string app_id; | 38 std::string app_id; |
| 35 std::string auth_token; | 39 std::string auth_token; |
| 36 StatusCallback callback; | 40 StatusCallback callback; |
| 37 }; | 41 }; |
| 38 | 42 |
| 39 // The implementation for CopresenceManager. Responsible primarily for | 43 // The implementation for CopresenceManager. Responsible primarily for |
| 40 // client-side initialization. The RpcHandler handles all the details | 44 // client-side initialization. The RpcHandler handles all the details |
| 41 // of interacting with the server. | 45 // of interacting with the server. |
| 46 // TODO(rkc): Add tests for this class. |
| 42 class CopresenceManagerImpl : public CopresenceManager { | 47 class CopresenceManagerImpl : public CopresenceManager { |
| 43 public: | 48 public: |
| 44 ~CopresenceManagerImpl() override; | 49 ~CopresenceManagerImpl() override; |
| 45 void ExecuteReportRequest(const ReportRequest& request, | 50 void ExecuteReportRequest(const ReportRequest& request, |
| 46 const std::string& app_id, | 51 const std::string& app_id, |
| 47 const StatusCallback& callback) override; | 52 const StatusCallback& callback) override; |
| 48 | 53 |
| 49 private: | 54 private: |
| 50 // Create managers with the CopresenceManager::Create() method. | 55 // Create managers with the CopresenceManager::Create() method. |
| 51 friend class CopresenceManager; | 56 friend class CopresenceManager; |
| 52 CopresenceManagerImpl(CopresenceDelegate* delegate); | 57 CopresenceManagerImpl(CopresenceDelegate* delegate); |
| 53 | 58 |
| 54 void CompleteInitialization(); | 59 void CompleteInitialization(); |
| 55 void InitStepComplete(const std::string& step, bool success); | 60 void InitStepComplete(const std::string& step, bool success); |
| 56 | 61 |
| 62 // This function will be called every kPollTimerIntervalMs milliseconds to |
| 63 // poll the server for new messages. |
| 64 void PollForMessages(); |
| 65 |
| 66 // This function will verify that we can hear the audio we're playing every |
| 67 // kAudioCheckIntervalMs milliseconds. |
| 68 void AudioCheck(); |
| 69 |
| 57 // Belongs to the caller. | 70 // Belongs to the caller. |
| 58 CopresenceDelegate* const delegate_; | 71 CopresenceDelegate* const delegate_; |
| 59 | 72 |
| 60 int pending_init_operations_; | 73 int pending_init_operations_; |
| 61 base::CancelableCallback<void(bool)> whispernet_init_callback_; | 74 base::CancelableCallback<void(bool)> whispernet_init_callback_; |
| 62 bool init_failed_; | 75 bool init_failed_; |
| 63 | 76 |
| 64 ScopedVector<PendingRequest> pending_requests_queue_; | 77 ScopedVector<PendingRequest> pending_requests_queue_; |
| 65 | 78 |
| 66 // The RpcHandler depends on the directive handler. | 79 // The RpcHandler depends on the directive handler, do not change this order. |
| 67 scoped_ptr<DirectiveHandler> directive_handler_; | 80 scoped_ptr<DirectiveHandler> directive_handler_; |
| 68 scoped_ptr<RpcHandler> rpc_handler_; | 81 scoped_ptr<RpcHandler> rpc_handler_; |
| 69 | 82 |
| 83 scoped_ptr<base::Timer> poll_timer_; |
| 84 scoped_ptr<base::Timer> audio_check_timer_; |
| 85 |
| 70 DISALLOW_COPY_AND_ASSIGN(CopresenceManagerImpl); | 86 DISALLOW_COPY_AND_ASSIGN(CopresenceManagerImpl); |
| 71 }; | 87 }; |
| 72 | 88 |
| 73 } // namespace copresence | 89 } // namespace copresence |
| 74 | 90 |
| 75 #endif // COMPONENTS_COPRESENCE_COPRESENCE_MANAGER_IMPL_H_ | 91 #endif // COMPONENTS_COPRESENCE_COPRESENCE_MANAGER_IMPL_H_ |
| OLD | NEW |