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

Unified Diff: chrome/browser/extensions/api/copresence_private/copresence_private_api.cc

Issue 438513002: Add the whispernet proxy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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: chrome/browser/extensions/api/copresence_private/copresence_private_api.cc
diff --git a/chrome/browser/extensions/api/copresence_private/copresence_private_api.cc b/chrome/browser/extensions/api/copresence_private/copresence_private_api.cc
new file mode 100644
index 0000000000000000000000000000000000000000..609ac347656f773e1e906770dfccc72692b326c3
--- /dev/null
+++ b/chrome/browser/extensions/api/copresence_private/copresence_private_api.cc
@@ -0,0 +1,110 @@
+// 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 "chrome/browser/extensions/api/copresence_private/copresence_private_api.h"
+
+#include "base/lazy_instance.h"
+#include "base/stl_util.h"
+#include "chrome/browser/copresence/chrome_whispernet_client.h"
+#include "chrome/common/extensions/api/copresence_private.h"
+#include "components/copresence/public/whispernet_client.h"
+#include "media/base/audio_bus.h"
+
+namespace extensions {
+
+// This code is only for testing while we don't have the rest of the
+// CopresenceAPI service which will actually give us the whispernet client.
+// Once we add that code, both the g_whispernet_client and the
+// GetWhispernetClient function will go away, to be replaced by the
+// GetWhispernetClient function that will fetch our active whispernet client
+// from the CopresenceAPI profile keyed service.
+copresence::WhispernetClient* g_whispernet_client = NULL;
+
+copresence::WhispernetClient* GetWhispernetClient(
not at google - send to devlin 2014/08/01 21:11:58 just inline the content of this function in the ot
rkc 2014/08/01 21:21:12 Done.
+ content::BrowserContext* context) {
+ // This is temporary code, this needs to be replaced by the real
+ // GetWhispernetClient code from c/b/e/api/copresence/copresence_util.h
+ DCHECK(g_whispernet_client);
+ return g_whispernet_client;
+}
+
+// Copresence Private functions.
+
+copresence::WhispernetClient* CopresencePrivateFunction::GetWhispernetClient() {
+ return extensions::GetWhispernetClient(browser_context());
+}
+
+// CopresenceSendFoundFunction implementation:
+ExtensionFunction::ResponseAction CopresencePrivateSendFoundFunction::Run() {
+ if (!GetWhispernetClient() ||
+ GetWhispernetClient()->GetTokensCallback().is_null()) {
+ return RespondNow(NoArguments());
+ }
+
+ scoped_ptr<api::copresence_private::SendFound::Params> params(
+ api::copresence_private::SendFound::Params::Create(*args_));
+ EXTENSION_FUNCTION_VALIDATE(params.get());
+ GetWhispernetClient()->GetTokensCallback().Run(params->tokens);
+ return RespondNow(NoArguments());
+}
+
+// CopresenceSendEncodedFunction implementation:
+ExtensionFunction::ResponseAction CopresencePrivateSendSamplesFunction::Run() {
+ if (!GetWhispernetClient() ||
+ GetWhispernetClient()->GetSamplesCallback().is_null()) {
+ return RespondNow(NoArguments());
+ }
+
+ scoped_ptr<api::copresence_private::SendSamples::Params> params(
+ api::copresence_private::SendSamples::Params::Create(*args_));
+ EXTENSION_FUNCTION_VALIDATE(params.get());
+
+ scoped_refptr<media::AudioBusRefCounted> samples =
+ media::AudioBusRefCounted::Create(1,
+ params->samples.size() / sizeof(float));
+
+ memcpy(samples->channel(0),
+ string_as_array(&params->samples),
+ params->samples.size());
+
+ GetWhispernetClient()->GetSamplesCallback().Run(params->token, samples);
+ return RespondNow(NoArguments());
+}
+
+// CopresenceSendDetectFunction implementation:
+ExtensionFunction::ResponseAction CopresencePrivateSendDetectFunction::Run() {
+ if (!GetWhispernetClient() ||
+ GetWhispernetClient()->GetDetectBroadcastCallback().is_null()) {
+ return RespondNow(NoArguments());
+ }
+
+ scoped_ptr<api::copresence_private::SendDetect::Params> params(
+ api::copresence_private::SendDetect::Params::Create(*args_));
+ EXTENSION_FUNCTION_VALIDATE(params.get());
+
+ GetWhispernetClient()->GetDetectBroadcastCallback().Run(params->detected);
+ return RespondNow(NoArguments());
+}
+
+// CopresenceSendInitializedFunction implementation:
+ExtensionFunction::ResponseAction
+CopresencePrivateSendInitializedFunction::Run() {
+ if (!GetWhispernetClient() ||
+ GetWhispernetClient()->GetInitializedCallback().is_null()) {
+ return RespondNow(NoArguments());
+ }
+
+ scoped_ptr<api::copresence_private::SendInitialized::Params> params(
+ api::copresence_private::SendInitialized::Params::Create(*args_));
+ EXTENSION_FUNCTION_VALIDATE(params.get());
+
+ GetWhispernetClient()->GetInitializedCallback().Run(params->success);
+ return RespondNow(NoArguments());
+}
+
+void SetWhispernetClientForTesting(copresence::WhispernetClient* client) {
+ g_whispernet_client = client;
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698