| 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" |
| 11 #include "components/copresence/handlers/audio/audio_directive_handler_impl.h" | 11 #include "components/copresence/handlers/audio/audio_directive_handler_impl.h" |
| 12 #include "components/copresence/proto/data.pb.h" | 12 #include "components/copresence/proto/data.pb.h" |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 const int kMaxUnlabeledDirectiveTtl = 60000; // 1 minute | 16 const int kMaxUnlabeledDirectiveTtl = 60000; // 1 minute |
| 17 | 17 |
| 18 } // namespace | 18 } // namespace |
| 19 | 19 |
| 20 namespace copresence { | 20 namespace copresence { |
| 21 | 21 |
| 22 // Public functions | 22 // Public functions. |
| 23 | 23 |
| 24 DirectiveHandlerImpl::DirectiveHandlerImpl( | 24 DirectiveHandlerImpl::DirectiveHandlerImpl( |
| 25 const DirectivesCallback& update_directives_callback) |
| 26 : DirectiveHandlerImpl(update_directives_callback, |
| 27 make_scoped_ptr(new AudioDirectiveHandlerImpl( |
| 28 update_directives_callback))) {} |
| 29 |
| 30 DirectiveHandlerImpl::DirectiveHandlerImpl( |
| 31 const DirectivesCallback& update_directives_callback, |
| 25 scoped_ptr<AudioDirectiveHandler> audio_handler) | 32 scoped_ptr<AudioDirectiveHandler> audio_handler) |
| 26 : audio_handler_(audio_handler.Pass()), is_started_(false) {} | 33 : audio_handler_(audio_handler.Pass()), |
| 34 is_started_(false) {} |
| 27 | 35 |
| 28 DirectiveHandlerImpl::~DirectiveHandlerImpl() {} | 36 DirectiveHandlerImpl::~DirectiveHandlerImpl() {} |
| 29 | 37 |
| 30 void DirectiveHandlerImpl::Start(WhispernetClient* whispernet_client, | 38 void DirectiveHandlerImpl::Start(WhispernetClient* whispernet_client, |
| 31 const TokensCallback& tokens_cb) { | 39 const TokensCallback& tokens_cb) { |
| 32 audio_handler_->Initialize(whispernet_client, tokens_cb); | 40 audio_handler_->Initialize(whispernet_client, tokens_cb); |
| 33 DVLOG(2) << "Directive handler starting"; | 41 DVLOG(2) << "Directive handler starting"; |
| 34 | 42 |
| 35 is_started_ = true; | 43 is_started_ = true; |
| 36 | 44 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 const std::string DirectiveHandlerImpl::GetCurrentAudioToken(AudioType type) | 96 const std::string DirectiveHandlerImpl::GetCurrentAudioToken(AudioType type) |
| 89 const { | 97 const { |
| 90 // If whispernet_client_ is null, audio_handler_ hasn't been Initialized. | 98 // If whispernet_client_ is null, audio_handler_ hasn't been Initialized. |
| 91 return is_started_ ? audio_handler_->PlayingToken(type) : ""; | 99 return is_started_ ? audio_handler_->PlayingToken(type) : ""; |
| 92 } | 100 } |
| 93 | 101 |
| 94 bool DirectiveHandlerImpl::IsAudioTokenHeard(AudioType type) const { | 102 bool DirectiveHandlerImpl::IsAudioTokenHeard(AudioType type) const { |
| 95 return is_started_ ? audio_handler_->IsPlayingTokenHeard(type) : false; | 103 return is_started_ ? audio_handler_->IsPlayingTokenHeard(type) : false; |
| 96 } | 104 } |
| 97 | 105 |
| 98 // Private functions | 106 |
| 107 // Private functions. |
| 99 | 108 |
| 100 void DirectiveHandlerImpl::StartDirective(const std::string& op_id, | 109 void DirectiveHandlerImpl::StartDirective(const std::string& op_id, |
| 101 const Directive& directive) { | 110 const Directive& directive) { |
| 102 DCHECK(is_started_); | 111 DCHECK(is_started_); |
| 103 const TokenInstruction& ti = directive.token_instruction(); | 112 DLOG_IF(WARNING, directive.delay_millis() > 0) |
| 104 if (ti.medium() == AUDIO_ULTRASOUND_PASSBAND || | 113 << "Ignoring " << directive.delay_millis() << " delay for directive"; |
| 105 ti.medium() == AUDIO_AUDIBLE_DTMF) { | 114 const TokenMedium& medium = directive.token_instruction().medium(); |
| 106 audio_handler_->AddInstruction( | 115 DCHECK(medium == AUDIO_ULTRASOUND_PASSBAND || medium == AUDIO_AUDIBLE_DTMF) |
| 107 ti, op_id, base::TimeDelta::FromMilliseconds(directive.ttl_millis())); | 116 << "Received directive for unimplemented medium " << medium; |
| 108 } else { | 117 audio_handler_->AddInstruction(directive, op_id); |
| 109 // We should only get audio directives. | |
| 110 NOTREACHED() << "Received directive for unimplemented medium " | |
| 111 << ti.medium(); | |
| 112 } | |
| 113 } | 118 } |
| 114 | 119 |
| 115 } // namespace copresence | 120 } // namespace copresence |
| OLD | NEW |