| 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/handlers/directive_handler_impl.h" | 5 #include "components/copresence/handlers/directive_handler_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/guid.h" | 8 #include "base/guid.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 update_directives_callback))) {} | 28 update_directives_callback))) {} |
| 29 | 29 |
| 30 DirectiveHandlerImpl::DirectiveHandlerImpl( | 30 DirectiveHandlerImpl::DirectiveHandlerImpl( |
| 31 const DirectivesCallback& update_directives_callback, | 31 const DirectivesCallback& update_directives_callback, |
| 32 scoped_ptr<AudioDirectiveHandler> audio_handler) | 32 scoped_ptr<AudioDirectiveHandler> audio_handler) |
| 33 : audio_handler_(audio_handler.Pass()), | 33 : audio_handler_(audio_handler.Pass()), |
| 34 is_started_(false) {} | 34 is_started_(false) {} |
| 35 | 35 |
| 36 DirectiveHandlerImpl::~DirectiveHandlerImpl() {} | 36 DirectiveHandlerImpl::~DirectiveHandlerImpl() {} |
| 37 | 37 |
| 38 void DirectiveHandlerImpl::Start(WhispernetClient* whispernet_client, | 38 void DirectiveHandlerImpl::Start( |
| 39 const TokensCallback& tokens_cb) { | 39 audio_modem::WhispernetClient* whispernet_client, |
| 40 const audio_modem::TokensCallback& tokens_cb) { |
| 40 audio_handler_->Initialize(whispernet_client, tokens_cb); | 41 audio_handler_->Initialize(whispernet_client, tokens_cb); |
| 41 DVLOG(2) << "Directive handler starting"; | 42 DVLOG(2) << "Directive handler starting"; |
| 42 | 43 |
| 43 is_started_ = true; | 44 is_started_ = true; |
| 44 | 45 |
| 45 // Run all the queued directives. | 46 // Run all the queued directives. |
| 46 for (const auto& op_id : pending_directives_) { | 47 for (const auto& op_id : pending_directives_) { |
| 47 for (const Directive& directive : op_id.second) | 48 for (const Directive& directive : op_id.second) |
| 48 StartDirective(op_id.first, directive); | 49 StartDirective(op_id.first, directive); |
| 49 } | 50 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 87 |
| 87 void DirectiveHandlerImpl::RemoveDirectives(const std::string& op_id) { | 88 void DirectiveHandlerImpl::RemoveDirectives(const std::string& op_id) { |
| 88 // If whispernet_client_ is null, audio_handler_ hasn't been Initialized. | 89 // If whispernet_client_ is null, audio_handler_ hasn't been Initialized. |
| 89 if (is_started_) { | 90 if (is_started_) { |
| 90 audio_handler_->RemoveInstructions(op_id); | 91 audio_handler_->RemoveInstructions(op_id); |
| 91 } else { | 92 } else { |
| 92 pending_directives_.erase(op_id); | 93 pending_directives_.erase(op_id); |
| 93 } | 94 } |
| 94 } | 95 } |
| 95 | 96 |
| 96 const std::string DirectiveHandlerImpl::GetCurrentAudioToken(AudioType type) | 97 const std::string DirectiveHandlerImpl::GetCurrentAudioToken( |
| 97 const { | 98 audio_modem::AudioType type) const { |
| 98 // If whispernet_client_ is null, audio_handler_ hasn't been Initialized. | 99 // If whispernet_client_ is null, audio_handler_ hasn't been Initialized. |
| 99 return is_started_ ? audio_handler_->PlayingToken(type) : ""; | 100 return is_started_ ? audio_handler_->PlayingToken(type) : ""; |
| 100 } | 101 } |
| 101 | 102 |
| 102 bool DirectiveHandlerImpl::IsAudioTokenHeard(AudioType type) const { | 103 bool DirectiveHandlerImpl::IsAudioTokenHeard( |
| 104 audio_modem::AudioType type) const { |
| 103 return is_started_ ? audio_handler_->IsPlayingTokenHeard(type) : false; | 105 return is_started_ ? audio_handler_->IsPlayingTokenHeard(type) : false; |
| 104 } | 106 } |
| 105 | 107 |
| 106 | 108 |
| 107 // Private functions. | 109 // Private functions. |
| 108 | 110 |
| 109 void DirectiveHandlerImpl::StartDirective(const std::string& op_id, | 111 void DirectiveHandlerImpl::StartDirective(const std::string& op_id, |
| 110 const Directive& directive) { | 112 const Directive& directive) { |
| 111 DCHECK(is_started_); | 113 DCHECK(is_started_); |
| 112 DLOG_IF(WARNING, directive.delay_millis() > 0) | 114 DLOG_IF(WARNING, directive.delay_millis() > 0) |
| 113 << "Ignoring " << directive.delay_millis() << " delay for directive"; | 115 << "Ignoring " << directive.delay_millis() << " delay for directive"; |
| 114 const TokenMedium& medium = directive.token_instruction().medium(); | 116 const TokenMedium& medium = directive.token_instruction().medium(); |
| 115 DCHECK(medium == AUDIO_ULTRASOUND_PASSBAND || medium == AUDIO_AUDIBLE_DTMF) | 117 DCHECK(medium == AUDIO_ULTRASOUND_PASSBAND || medium == AUDIO_AUDIBLE_DTMF) |
| 116 << "Received directive for unimplemented medium " << medium; | 118 << "Received directive for unimplemented medium " << medium; |
| 117 audio_handler_->AddInstruction(directive, op_id); | 119 audio_handler_->AddInstruction(directive, op_id); |
| 118 } | 120 } |
| 119 | 121 |
| 120 } // namespace copresence | 122 } // namespace copresence |
| OLD | NEW |