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