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

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..0d2ea19158b7e78bd194adbdd0e27a65125c5a62
--- /dev/null
+++ b/chrome/browser/extensions/api/copresence_private/copresence_private_api.cc
@@ -0,0 +1,122 @@
+// 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, this entire namespace will go away.
+namespace util {
not at google - send to devlin 2014/07/31 15:24:17 I don't think the namespace is necessary.
rkc 2014/07/31 23:12:52 Done.
+
+copresence::WhispernetClient* g_whispernet_client = NULL;
+
+copresence::WhispernetClient* GetWhispernetClient(
+ content::BrowserContext* context) {
+ if (!g_whispernet_client)
+ g_whispernet_client = new ChromeWhispernetClient(context);
not at google - send to devlin 2014/07/31 15:24:17 this is a leak, use base::LazyInstance.
rkc 2014/07/31 23:12:53 This code will never get exercised, removed. This
+ return g_whispernet_client;
+}
+
+} // namespace util
+
+// Copresence Private functions.
+
+// CopresenceSendFoundFunction implementation:
+bool CopresencePrivateSendFoundFunction::RunSync() {
+ if (!util::GetWhispernetClient(browser_context()) ||
not at google - send to devlin 2014/07/31 15:24:17 how can !util::GetWhispernetClient(browser_context
rkc 2014/07/31 23:12:52 Answered in the comment above :) The current GetWh
not at google - send to devlin 2014/07/31 23:31:17 you haven't Done the second part of this comment.
rkc 2014/08/01 19:20:00 Done.
+ util::GetWhispernetClient(browser_context())
+ ->GetTokensCallback()
+ .is_null()) {
+ return true;
not at google - send to devlin 2014/07/31 15:24:17 seems like this should be an error?
rkc 2014/07/31 23:12:52 If we don't have a callback registered right now,
+ }
+
+ scoped_ptr<api::copresence_private::SendFound::Params> params(
+ api::copresence_private::SendFound::Params::Create(*args_));
+ EXTENSION_FUNCTION_VALIDATE(params.get());
+ util::GetWhispernetClient(browser_context())->GetTokensCallback().Run(
+ params->tokens);
+ return true;
+}
+
+// CopresenceSendEncodedFunction implementation:
+bool CopresencePrivateSendSamplesFunction::RunSync() {
+ if (!util::GetWhispernetClient(browser_context()) ||
+ util::GetWhispernetClient(browser_context())
+ ->GetSamplesCallback()
+ .is_null()) {
+ return true;
+ }
+
+ 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());
not at google - send to devlin 2014/07/31 15:24:17 this doesn't look safe to me, where is the guarant
rkc 2014/07/31 23:12:52 The AudioBusRefCounted constructor ensures that we
+
+ util::GetWhispernetClient(browser_context())->GetSamplesCallback().Run(
+ params->token, samples);
not at google - send to devlin 2014/07/31 15:24:17 should this take ownership of |samples|, and |samp
rkc 2014/07/31 23:12:52 We store the samples in STL data structures, and i
not at google - send to devlin 2014/07/31 23:31:17 ref counting doesn't make good interfaces. It seem
rkc 2014/08/01 19:20:00 Discussed offline.
+ return true;
+}
+
+// CopresenceSendDetectFunction implementation:
+bool CopresencePrivateSendDetectFunction::RunSync() {
+ if (!util::GetWhispernetClient(browser_context()) ||
+ util::GetWhispernetClient(browser_context())
+ ->GetDetectBroadcastCallback()
+ .is_null()) {
+ return true;
+ }
+
+ scoped_ptr<api::copresence_private::SendDetect::Params> params(
+ api::copresence_private::SendDetect::Params::Create(*args_));
+ EXTENSION_FUNCTION_VALIDATE(params.get());
+
+ util::GetWhispernetClient(browser_context())
+ ->GetDetectBroadcastCallback()
+ .Run(params->detected);
+ return true;
+}
+
+// CopresenceSendInitializedFunction implementation:
+bool CopresencePrivateSendInitializedFunction::RunSync() {
+ LOG(ERROR) << "RKC: Got Init! context is: " << browser_context();
not at google - send to devlin 2014/07/31 15:24:17 remove debugging?
rkc 2014/07/31 23:12:52 Whoops. Done.
+
+ if (!util::GetWhispernetClient(browser_context()) ||
+ util::GetWhispernetClient(browser_context())
+ ->GetInitializedCallback()
+ .is_null()) {
+ return true;
+ }
+
+ LOG(ERROR) << "RKC: Got Init and got profile!!";
not at google - send to devlin 2014/07/31 15:24:17 remove debugging?
rkc 2014/07/31 23:12:52 Done.
+
+ scoped_ptr<api::copresence_private::SendInitialized::Params> params(
+ api::copresence_private::SendInitialized::Params::Create(*args_));
+ EXTENSION_FUNCTION_VALIDATE(params.get());
+
+ util::GetWhispernetClient(browser_context())->GetInitializedCallback().Run(
+ params->success);
+ return true;
+}
+
+void SetWhispernetClientForTesting(copresence::WhispernetClient* client) {
+ util::g_whispernet_client = client;
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698