Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Unified Diff: components/copresence/handlers/directive_handler.cc

Issue 419073002: Add the copresence DirectiveHandler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/copresence/handlers/directive_handler.cc
diff --git a/components/copresence/handlers/directive_handler.cc b/components/copresence/handlers/directive_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..79ddf8fbe243a582cb861272304651226224a6a2
--- /dev/null
+++ b/components/copresence/handlers/directive_handler.cc
@@ -0,0 +1,38 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/copresence/handlers/directive_handler.h"
+
+#include "base/time/time.h"
+#include "components/copresence/handlers/audio/audio_directive_handler.h"
+#include "components/copresence/proto/data.pb.h"
+
+namespace copresence {
+
+DirectiveHandler::DirectiveHandler(
+ const AudioRecorder::DecodeSamplesCallback& decode_cb,
+ const AudioDirectiveList::EncodeTokenCallback& encode_cb)
+ : audio_handler_(new AudioDirectiveHandler(decode_cb, encode_cb)) {
+ audio_handler_->Initialize();
+}
+
+DirectiveHandler::~DirectiveHandler() {
+}
+
+void DirectiveHandler::AddDirective(const Directive& directive) {
+ // We only handle Token directives; wifi/ble requests aren't implemented.
+ DCHECK_EQ(directive.instruction_type(), TOKEN);
+
+ const TokenInstruction& ti = directive.token_instruction();
+ // We currently only support audio.
+ DCHECK_EQ(ti.medium(), AUDIO_ULTRASOUND_PASSBAND);
+ audio_handler_->AddInstruction(
+ ti, base::TimeDelta::FromMilliseconds(directive.ttl_millis()));
+}
+
+void DirectiveHandler::RemoveDirectives(const std::string& /* op_id */) {
+ // TODO(rkc): Forward the remove directive call to all the directive handlers.
+}
+
+} // namespace copresence

Powered by Google App Engine
This is Rietveld 408576698