| 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.h" | 5 #include "components/copresence/handlers/directive_handler.h" |
| 6 | 6 |
| 7 #include "base/time/time.h" | 7 #include "base/time/time.h" |
| 8 #include "components/copresence/handlers/audio/audio_directive_handler.h" | 8 #include "components/copresence/handlers/audio/audio_directive_handler.h" |
| 9 #include "components/copresence/proto/data.pb.h" | 9 #include "components/copresence/proto/data.pb.h" |
| 10 | 10 |
| 11 namespace copresence { | 11 namespace copresence { |
| 12 | 12 |
| 13 DirectiveHandler::DirectiveHandler( | 13 DirectiveHandler::DirectiveHandler() {} |
| 14 |
| 15 void DirectiveHandler::Initialize( |
| 14 const AudioRecorder::DecodeSamplesCallback& decode_cb, | 16 const AudioRecorder::DecodeSamplesCallback& decode_cb, |
| 15 const AudioDirectiveList::EncodeTokenCallback& encode_cb) | 17 const AudioDirectiveList::EncodeTokenCallback& encode_cb) { |
| 16 : audio_handler_(new AudioDirectiveHandler(decode_cb, encode_cb)) { | 18 audio_handler_.reset(new AudioDirectiveHandler(decode_cb, encode_cb)); |
| 17 audio_handler_->Initialize(); | 19 audio_handler_->Initialize(); |
| 18 } | 20 } |
| 19 | 21 |
| 20 DirectiveHandler::~DirectiveHandler() { | 22 DirectiveHandler::~DirectiveHandler() { |
| 21 } | 23 } |
| 22 | 24 |
| 23 void DirectiveHandler::AddDirective(const Directive& directive) { | 25 void DirectiveHandler::AddDirective(const Directive& directive) { |
| 24 // We only handle Token directives; wifi/ble requests aren't implemented. | 26 // We only handle Token directives; wifi/ble requests aren't implemented. |
| 25 DCHECK_EQ(directive.instruction_type(), TOKEN); | 27 DCHECK_EQ(directive.instruction_type(), TOKEN); |
| 26 | 28 |
| 27 const TokenInstruction& ti = directive.token_instruction(); | 29 const TokenInstruction& ti = directive.token_instruction(); |
| 28 // We currently only support audio. | 30 // We currently only support audio. |
| 29 DCHECK_EQ(ti.medium(), AUDIO_ULTRASOUND_PASSBAND); | 31 DCHECK_EQ(ti.medium(), AUDIO_ULTRASOUND_PASSBAND); |
| 32 DCHECK(audio_handler_.get()) << "Clients must call Initialize() before " |
| 33 << "any other DirectiveHandler methods."; |
| 30 audio_handler_->AddInstruction( | 34 audio_handler_->AddInstruction( |
| 31 ti, base::TimeDelta::FromMilliseconds(directive.ttl_millis())); | 35 ti, base::TimeDelta::FromMilliseconds(directive.ttl_millis())); |
| 32 } | 36 } |
| 33 | 37 |
| 34 void DirectiveHandler::RemoveDirectives(const std::string& /* op_id */) { | 38 void DirectiveHandler::RemoveDirectives(const std::string& /* op_id */) { |
| 35 // TODO(rkc): Forward the remove directive call to all the directive handlers. | 39 // TODO(rkc): Forward the remove directive call to all the directive handlers. |
| 40 DCHECK(audio_handler_.get()) << "Clients must call Initialize() before " |
| 41 << "any other DirectiveHandler methods."; |
| 36 } | 42 } |
| 37 | 43 |
| 38 } // namespace copresence | 44 } // namespace copresence |
| OLD | NEW |