Update V8 to version 3.30.4 (based on bleeding_edge revision r24443)
[chromium-blink-merge.git] / components / copresence / handlers / directive_handler.cc
blobe76dde6fed26116274c1e57ef3403717f132d058
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
3 // found in the LICENSE file.
5 #include "components/copresence/handlers/directive_handler.h"
7 #include "base/time/time.h"
8 #include "components/copresence/handlers/audio/audio_directive_handler.h"
9 #include "components/copresence/proto/data.pb.h"
11 namespace copresence {
13 DirectiveHandler::DirectiveHandler() {}
15 void DirectiveHandler::Initialize(
16 const AudioRecorder::DecodeSamplesCallback& decode_cb,
17 const AudioDirectiveHandler::EncodeTokenCallback& encode_cb) {
18 audio_handler_.reset(new AudioDirectiveHandler(decode_cb, encode_cb));
19 audio_handler_->Initialize();
22 DirectiveHandler::~DirectiveHandler() {
25 void DirectiveHandler::AddDirective(const Directive& directive) {
26 // We only handle Token directives; wifi/ble requests aren't implemented.
27 DCHECK_EQ(directive.instruction_type(), TOKEN);
29 std::string op_id;
30 if (directive.has_published_message_id()) {
31 op_id = directive.published_message_id();
32 } else if (directive.has_subscription_id()) {
33 op_id = directive.subscription_id();
34 } else {
35 NOTREACHED() << "No operation associated with directive!";
36 return;
39 const TokenInstruction& ti = directive.token_instruction();
40 DCHECK(audio_handler_.get()) << "Clients must call Initialize() before "
41 << "any other DirectiveHandler methods.";
42 // We currently only support audio.
43 if (ti.medium() == AUDIO_ULTRASOUND_PASSBAND ||
44 ti.medium() == AUDIO_AUDIBLE_DTMF) {
45 audio_handler_->AddInstruction(
46 ti, op_id, base::TimeDelta::FromMilliseconds(directive.ttl_millis()));
50 void DirectiveHandler::RemoveDirectives(const std::string& op_id) {
51 DCHECK(audio_handler_.get()) << "Clients must call Initialize() before "
52 << "any other DirectiveHandler methods.";
53 audio_handler_->RemoveInstructions(op_id);
56 const std::string& DirectiveHandler::CurrentAudibleToken() const {
57 return audio_handler_->PlayingAudibleToken();
60 const std::string& DirectiveHandler::CurrentInaudibleToken() const {
61 return audio_handler_->PlayingInaudibleToken();
64 } // namespace copresence