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 #include "components/copresence/copresence_manager_impl.h" | 5 #include "components/copresence/copresence_manager_impl.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 if (delegate->GetGCMDriver()) | 75 if (delegate->GetGCMDriver()) |
76 gcm_handler_.reset(new GCMHandlerImpl(delegate->GetGCMDriver(), | 76 gcm_handler_.reset(new GCMHandlerImpl(delegate->GetGCMDriver(), |
77 directive_handler_.get(), | 77 directive_handler_.get(), |
78 messages_callback)); | 78 messages_callback)); |
79 | 79 |
80 rpc_handler_.reset(new RpcHandler(delegate, | 80 rpc_handler_.reset(new RpcHandler(delegate, |
81 state_.get(), | 81 state_.get(), |
82 directive_handler_.get(), | 82 directive_handler_.get(), |
83 gcm_handler_.get(), | 83 gcm_handler_.get(), |
84 messages_callback)); | 84 messages_callback)); |
| 85 |
| 86 directive_handler_->Start(delegate_->GetWhispernetClient(), |
| 87 base::Bind(&CopresenceManagerImpl::ReceivedTokens, |
| 88 base::Unretained(this))); |
85 } | 89 } |
86 | 90 |
87 CopresenceManagerImpl::~CopresenceManagerImpl() { | 91 CopresenceManagerImpl::~CopresenceManagerImpl() { |
88 whispernet_init_callback_.Cancel(); | 92 whispernet_init_callback_.Cancel(); |
89 } | 93 } |
90 | 94 |
91 CopresenceState* CopresenceManagerImpl::state() { | 95 CopresenceState* CopresenceManagerImpl::state() { |
92 return state_.get(); | 96 return state_.get(); |
93 } | 97 } |
94 | 98 |
(...skipping 14 matching lines...) Expand all Loading... |
109 rpc_handler_->SendReportRequest( | 113 rpc_handler_->SendReportRequest( |
110 request_copy.Pass(), app_id, auth_token, callback); | 114 request_copy.Pass(), app_id, auth_token, callback); |
111 } | 115 } |
112 | 116 |
113 | 117 |
114 // Private functions. | 118 // Private functions. |
115 | 119 |
116 void CopresenceManagerImpl::WhispernetInitComplete(bool success) { | 120 void CopresenceManagerImpl::WhispernetInitComplete(bool success) { |
117 if (success) { | 121 if (success) { |
118 DVLOG(3) << "Whispernet initialized successfully."; | 122 DVLOG(3) << "Whispernet initialized successfully."; |
119 | |
120 directive_handler_->Start(delegate_->GetWhispernetClient(), | |
121 base::Bind(&CopresenceManagerImpl::ReceivedTokens, | |
122 base::Unretained(this))); | |
123 | |
124 // Start up timers. | |
125 poll_timer_->Start(FROM_HERE, | 123 poll_timer_->Start(FROM_HERE, |
126 base::TimeDelta::FromMilliseconds(kPollTimerIntervalMs), | 124 base::TimeDelta::FromMilliseconds(kPollTimerIntervalMs), |
127 base::Bind(&CopresenceManagerImpl::PollForMessages, | 125 base::Bind(&CopresenceManagerImpl::PollForMessages, |
128 base::Unretained(this))); | 126 base::Unretained(this))); |
129 audio_check_timer_->Start( | 127 audio_check_timer_->Start( |
130 FROM_HERE, base::TimeDelta::FromMilliseconds(kAudioCheckIntervalMs), | 128 FROM_HERE, base::TimeDelta::FromMilliseconds(kAudioCheckIntervalMs), |
131 base::Bind(&CopresenceManagerImpl::AudioCheck, base::Unretained(this))); | 129 base::Bind(&CopresenceManagerImpl::AudioCheck, base::Unretained(this))); |
132 } else { | 130 } else { |
133 LOG(ERROR) << "Whispernet initialization failed!"; | 131 LOG(ERROR) << "Whispernet initialization failed!"; |
134 init_failed_ = true; | 132 init_failed_ = true; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 for (const auto& map_entry : messages_by_subscription) { | 255 for (const auto& map_entry : messages_by_subscription) { |
258 // TODO(ckehoe): Once we have the app ID from the server, we need to pass | 256 // TODO(ckehoe): Once we have the app ID from the server, we need to pass |
259 // it in here and get rid of the app id registry from the main API class. | 257 // it in here and get rid of the app id registry from the main API class. |
260 const std::string& subscription = map_entry.first; | 258 const std::string& subscription = map_entry.first; |
261 const std::vector<Message>& messages = map_entry.second; | 259 const std::vector<Message>& messages = map_entry.second; |
262 delegate_->HandleMessages(std::string(), subscription, messages); | 260 delegate_->HandleMessages(std::string(), subscription, messages); |
263 } | 261 } |
264 } | 262 } |
265 | 263 |
266 } // namespace copresence | 264 } // namespace copresence |
OLD | NEW |