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