| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "base/timer/timer.h" | 11 #include "base/timer/timer.h" |
| 12 #include "components/copresence/handlers/directive_handler.h" | 12 #include "components/copresence/handlers/directive_handler.h" |
| 13 #include "components/copresence/handlers/gcm_handler.h" | |
| 14 #include "components/copresence/proto/rpcs.pb.h" | 13 #include "components/copresence/proto/rpcs.pb.h" |
| 15 #include "components/copresence/public/whispernet_client.h" | 14 #include "components/copresence/public/whispernet_client.h" |
| 16 #include "components/copresence/rpc/rpc_handler.h" | 15 #include "components/copresence/rpc/rpc_handler.h" |
| 17 | 16 |
| 18 namespace { | 17 namespace { |
| 19 | 18 |
| 20 const int kPollTimerIntervalMs = 3000; // milliseconds. | 19 const int kPollTimerIntervalMs = 3000; // milliseconds. |
| 21 const int kAudioCheckIntervalMs = 1000; // milliseconds. | 20 const int kAudioCheckIntervalMs = 1000; // milliseconds. |
| 22 | 21 |
| 23 } // namespace | 22 } // namespace |
| 24 | 23 |
| 25 namespace copresence { | 24 namespace copresence { |
| 26 | 25 |
| 27 // Public functions. | 26 // Public functions. |
| 28 | 27 |
| 29 CopresenceManagerImpl::CopresenceManagerImpl(CopresenceDelegate* delegate) | 28 CopresenceManagerImpl::CopresenceManagerImpl(CopresenceDelegate* delegate) |
| 30 : delegate_(delegate), | 29 : delegate_(delegate), |
| 31 whispernet_init_callback_(base::Bind( | 30 whispernet_init_callback_(base::Bind( |
| 32 &CopresenceManagerImpl::WhispernetInitComplete, | 31 &CopresenceManagerImpl::WhispernetInitComplete, |
| 33 // This callback gets cancelled when we are destroyed. | 32 // This callback gets cancelled when we are destroyed. |
| 34 base::Unretained(this))), | 33 base::Unretained(this))), |
| 35 init_failed_(false), | |
| 36 directive_handler_(new DirectiveHandler), | 34 directive_handler_(new DirectiveHandler), |
| 37 poll_timer_(new base::RepeatingTimer<CopresenceManagerImpl>), | 35 poll_timer_(new base::RepeatingTimer<CopresenceManagerImpl>), |
| 38 audio_check_timer_(new base::RepeatingTimer<CopresenceManagerImpl>) { | 36 audio_check_timer_(new base::RepeatingTimer<CopresenceManagerImpl>), |
| 37 init_failed_(false) { |
| 39 DCHECK(delegate_); | 38 DCHECK(delegate_); |
| 40 DCHECK(delegate_->GetWhispernetClient()); | 39 DCHECK(delegate_->GetWhispernetClient()); |
| 41 delegate_->GetWhispernetClient()->Initialize( | 40 delegate_->GetWhispernetClient()->Initialize( |
| 42 whispernet_init_callback_.callback()); | 41 whispernet_init_callback_.callback()); |
| 43 | 42 |
| 44 if (delegate->GetGCMDriver()) | 43 rpc_handler_.reset(new RpcHandler(delegate_, directive_handler_.get())); |
| 45 gcm_handler_.reset(new GCMHandler(delegate->GetGCMDriver(), | |
| 46 directive_handler_.get())); | |
| 47 | |
| 48 rpc_handler_.reset(new RpcHandler(delegate, | |
| 49 directive_handler_.get(), | |
| 50 gcm_handler_.get())); | |
| 51 } | 44 } |
| 52 | 45 |
| 53 CopresenceManagerImpl::~CopresenceManagerImpl() { | 46 CopresenceManagerImpl::~CopresenceManagerImpl() { |
| 54 whispernet_init_callback_.Cancel(); | 47 whispernet_init_callback_.Cancel(); |
| 55 } | 48 } |
| 56 | 49 |
| 57 // Returns false if any operations were malformed. | 50 // Returns false if any operations were malformed. |
| 58 void CopresenceManagerImpl::ExecuteReportRequest( | 51 void CopresenceManagerImpl::ExecuteReportRequest( |
| 59 const ReportRequest& request, | 52 const ReportRequest& request, |
| 60 const std::string& app_id, | 53 const std::string& app_id, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 if (!directive_handler_->GetCurrentAudioToken(AUDIBLE).empty() && | 113 if (!directive_handler_->GetCurrentAudioToken(AUDIBLE).empty() && |
| 121 !directive_handler_->IsAudioTokenHeard(AUDIBLE)) { | 114 !directive_handler_->IsAudioTokenHeard(AUDIBLE)) { |
| 122 delegate_->HandleStatusUpdate(AUDIO_FAIL); | 115 delegate_->HandleStatusUpdate(AUDIO_FAIL); |
| 123 } else if (!directive_handler_->GetCurrentAudioToken(INAUDIBLE).empty() && | 116 } else if (!directive_handler_->GetCurrentAudioToken(INAUDIBLE).empty() && |
| 124 !directive_handler_->IsAudioTokenHeard(INAUDIBLE)) { | 117 !directive_handler_->IsAudioTokenHeard(INAUDIBLE)) { |
| 125 delegate_->HandleStatusUpdate(AUDIO_FAIL); | 118 delegate_->HandleStatusUpdate(AUDIO_FAIL); |
| 126 } | 119 } |
| 127 } | 120 } |
| 128 | 121 |
| 129 } // namespace copresence | 122 } // namespace copresence |
| OLD | NEW |