| 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> | |
| 10 | 9 |
| 11 #include "base/cancelable_callback.h" | 10 #include "base/cancelable_callback.h" |
| 12 #include "base/macros.h" | 11 #include "base/macros.h" |
| 13 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 14 #include "components/copresence/copresence_state_impl.h" | |
| 15 #include "components/copresence/public/copresence_manager.h" | 13 #include "components/copresence/public/copresence_manager.h" |
| 16 | 14 |
| 17 namespace base { | 15 namespace base { |
| 18 class Timer; | 16 class Timer; |
| 19 } | 17 } |
| 20 | 18 |
| 21 namespace net { | 19 namespace net { |
| 22 class URLContextGetter; | 20 class URLContextGetter; |
| 23 } | 21 } |
| 24 | 22 |
| 25 namespace copresence { | 23 namespace copresence { |
| 26 | 24 |
| 27 class DirectiveHandler; | 25 class DirectiveHandler; |
| 28 class GCMHandler; | 26 class GCMHandler; |
| 29 class ReportRequest; | 27 class ReportRequest; |
| 30 class RpcHandler; | 28 class RpcHandler; |
| 31 class WhispernetClient; | 29 class WhispernetClient; |
| 32 | 30 |
| 33 // The implementation for CopresenceManager. Responsible primarily for | 31 // The implementation for CopresenceManager. Responsible primarily for |
| 34 // client-side initialization. The RpcHandler handles all the details | 32 // client-side initialization. The RpcHandler handles all the details |
| 35 // of interacting with the server. | 33 // of interacting with the server. |
| 36 // TODO(rkc): Add tests for this class. | 34 // TODO(rkc): Add tests for this class. |
| 37 class CopresenceManagerImpl : public CopresenceManager { | 35 class CopresenceManagerImpl : public CopresenceManager { |
| 38 public: | 36 public: |
| 39 // The delegate is owned by the caller, and must outlive the manager. | 37 // The delegate is owned by the caller, and must outlive the manager. |
| 40 explicit CopresenceManagerImpl(CopresenceDelegate* delegate); | 38 explicit CopresenceManagerImpl(CopresenceDelegate* delegate); |
| 41 | 39 |
| 42 ~CopresenceManagerImpl() override; | 40 ~CopresenceManagerImpl() override; |
| 43 | 41 |
| 44 // CopresenceManager overrides. | |
| 45 CopresenceState* state() override; | |
| 46 void ExecuteReportRequest(const ReportRequest& request, | 42 void ExecuteReportRequest(const ReportRequest& request, |
| 47 const std::string& app_id, | 43 const std::string& app_id, |
| 48 const std::string& auth_token, | 44 const std::string& auth_token, |
| 49 const StatusCallback& callback) override; | 45 const StatusCallback& callback) override; |
| 50 | 46 |
| 51 private: | 47 private: |
| 52 void WhispernetInitComplete(bool success); | 48 void WhispernetInitComplete(bool success); |
| 53 | 49 |
| 54 // Handle tokens decoded by Whispernet. | 50 // This function will be called every kPollTimerIntervalMs milliseconds to |
| 55 // TODO(ckehoe): Replace AudioToken with ReceivedToken. | 51 // poll the server for new messages. |
| 56 void ReceivedTokens(const std::vector<AudioToken>& tokens); | |
| 57 | |
| 58 // This function will be called every kPollTimerIntervalMs milliseconds | |
| 59 // to poll the server for new messages. | |
| 60 void PollForMessages(); | 52 void PollForMessages(); |
| 61 | 53 |
| 62 // Verify that we can hear the audio we're playing | 54 // This function will verify that we can hear the audio we're playing every |
| 63 // every kAudioCheckIntervalMs milliseconds. | 55 // kAudioCheckIntervalMs milliseconds. |
| 64 void AudioCheck(); | 56 void AudioCheck(); |
| 65 | 57 |
| 66 // Belongs to the caller. | 58 // Belongs to the caller. |
| 67 CopresenceDelegate* const delegate_; | 59 CopresenceDelegate* const delegate_; |
| 68 | 60 |
| 69 // We use a CancelableCallback here because Whispernet | 61 // We use a CancelableCallback here because Whispernet |
| 70 // does not provide a way to unregister its init callback. | 62 // does not provide a way to unregister its init callback. |
| 71 base::CancelableCallback<void(bool)> whispernet_init_callback_; | 63 base::CancelableCallback<void(bool)> whispernet_init_callback_; |
| 72 | 64 |
| 73 bool init_failed_; | 65 bool init_failed_; |
| 74 | 66 |
| 75 // This order is required because each object | 67 // The GCMHandler must destruct before the DirectiveHandler, |
| 76 // makes calls to those listed before it. | 68 // which must destruct before the RpcHandler. Do not change this order. |
| 77 scoped_ptr<CopresenceStateImpl> state_; | |
| 78 scoped_ptr<RpcHandler> rpc_handler_; | 69 scoped_ptr<RpcHandler> rpc_handler_; |
| 79 scoped_ptr<DirectiveHandler> directive_handler_; | 70 scoped_ptr<DirectiveHandler> directive_handler_; |
| 80 scoped_ptr<GCMHandler> gcm_handler_; | 71 scoped_ptr<GCMHandler> gcm_handler_; |
| 81 | 72 |
| 82 scoped_ptr<base::Timer> poll_timer_; | 73 scoped_ptr<base::Timer> poll_timer_; |
| 83 scoped_ptr<base::Timer> audio_check_timer_; | 74 scoped_ptr<base::Timer> audio_check_timer_; |
| 84 | 75 |
| 85 DISALLOW_COPY_AND_ASSIGN(CopresenceManagerImpl); | 76 DISALLOW_COPY_AND_ASSIGN(CopresenceManagerImpl); |
| 86 }; | 77 }; |
| 87 | 78 |
| 88 } // namespace copresence | 79 } // namespace copresence |
| 89 | 80 |
| 90 #endif // COMPONENTS_COPRESENCE_COPRESENCE_MANAGER_IMPL_H_ | 81 #endif // COMPONENTS_COPRESENCE_COPRESENCE_MANAGER_IMPL_H_ |
| OLD | NEW |