| 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" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
| 14 #include "components/audio_modem/public/whispernet_client.h" |
| 14 #include "components/copresence/copresence_state_impl.h" | 15 #include "components/copresence/copresence_state_impl.h" |
| 15 #include "components/copresence/handlers/directive_handler_impl.h" | 16 #include "components/copresence/handlers/directive_handler_impl.h" |
| 16 #include "components/copresence/handlers/gcm_handler_impl.h" | 17 #include "components/copresence/handlers/gcm_handler_impl.h" |
| 17 #include "components/copresence/proto/rpcs.pb.h" | 18 #include "components/copresence/proto/rpcs.pb.h" |
| 18 #include "components/copresence/public/whispernet_client.h" | |
| 19 #include "components/copresence/rpc/rpc_handler.h" | 19 #include "components/copresence/rpc/rpc_handler.h" |
| 20 | 20 |
| 21 using google::protobuf::RepeatedPtrField; | 21 using google::protobuf::RepeatedPtrField; |
| 22 | 22 |
| 23 using audio_modem::AUDIBLE; |
| 24 using audio_modem::AudioToken; |
| 25 using audio_modem::INAUDIBLE; |
| 26 |
| 23 namespace { | 27 namespace { |
| 24 | 28 |
| 25 const int kPollTimerIntervalMs = 3000; // milliseconds. | 29 const int kPollTimerIntervalMs = 3000; // milliseconds. |
| 26 const int kAudioCheckIntervalMs = 1000; // milliseconds. | 30 const int kAudioCheckIntervalMs = 1000; // milliseconds. |
| 27 | 31 |
| 28 const int kQueuedMessageTimeout = 10; // seconds. | 32 const int kQueuedMessageTimeout = 10; // seconds. |
| 29 const int kMaxQueuedMessages = 1000; | 33 const int kMaxQueuedMessages = 1000; |
| 30 | 34 |
| 31 } // namespace | 35 } // namespace |
| 32 | 36 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 57 // will be destructed before the CopresenceState instance. | 61 // will be destructed before the CopresenceState instance. |
| 58 base::Bind(&CopresenceStateImpl::UpdateDirectives, | 62 base::Bind(&CopresenceStateImpl::UpdateDirectives, |
| 59 base::Unretained(state_.get())))), | 63 base::Unretained(state_.get())))), |
| 60 poll_timer_(new base::RepeatingTimer<CopresenceManagerImpl>), | 64 poll_timer_(new base::RepeatingTimer<CopresenceManagerImpl>), |
| 61 audio_check_timer_(new base::RepeatingTimer<CopresenceManagerImpl>), | 65 audio_check_timer_(new base::RepeatingTimer<CopresenceManagerImpl>), |
| 62 queued_messages_by_token_( | 66 queued_messages_by_token_( |
| 63 base::TimeDelta::FromSeconds(kQueuedMessageTimeout), | 67 base::TimeDelta::FromSeconds(kQueuedMessageTimeout), |
| 64 kMaxQueuedMessages) { | 68 kMaxQueuedMessages) { |
| 65 DCHECK(delegate_); | 69 DCHECK(delegate_); |
| 66 DCHECK(delegate_->GetWhispernetClient()); | 70 DCHECK(delegate_->GetWhispernetClient()); |
| 71 // TODO(ckehoe): Handle whispernet initialization in the whispernet component. |
| 67 delegate_->GetWhispernetClient()->Initialize( | 72 delegate_->GetWhispernetClient()->Initialize( |
| 68 whispernet_init_callback_.callback()); | 73 whispernet_init_callback_.callback()); |
| 69 | 74 |
| 70 MessagesCallback messages_callback = base::Bind( | 75 MessagesCallback messages_callback = base::Bind( |
| 71 &CopresenceManagerImpl::DispatchMessages, | 76 &CopresenceManagerImpl::DispatchMessages, |
| 72 // This will only be passed to objects that we own. | 77 // This will only be passed to objects that we own. |
| 73 base::Unretained(this)); | 78 base::Unretained(this)); |
| 74 | 79 |
| 75 if (delegate->GetGCMDriver()) | 80 if (delegate->GetGCMDriver()) |
| 76 gcm_handler_.reset(new GCMHandlerImpl(delegate->GetGCMDriver(), | 81 gcm_handler_.reset(new GCMHandlerImpl(delegate->GetGCMDriver(), |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 for (const auto& map_entry : messages_by_subscription) { | 262 for (const auto& map_entry : messages_by_subscription) { |
| 258 // TODO(ckehoe): Once we have the app ID from the server, we need to pass | 263 // 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. | 264 // it in here and get rid of the app id registry from the main API class. |
| 260 const std::string& subscription = map_entry.first; | 265 const std::string& subscription = map_entry.first; |
| 261 const std::vector<Message>& messages = map_entry.second; | 266 const std::vector<Message>& messages = map_entry.second; |
| 262 delegate_->HandleMessages(std::string(), subscription, messages); | 267 delegate_->HandleMessages(std::string(), subscription, messages); |
| 263 } | 268 } |
| 264 } | 269 } |
| 265 | 270 |
| 266 } // namespace copresence | 271 } // namespace copresence |
| OLD | NEW |