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

Side by Side 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, 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "chrome/browser/extensions/api/copresence_private/copresence_private_ap i.h"
6
7 #include "base/lazy_instance.h"
8 #include "base/stl_util.h"
9 #include "chrome/browser/copresence/chrome_whispernet_client.h"
10 #include "chrome/common/extensions/api/copresence_private.h"
11 #include "components/copresence/public/whispernet_client.h"
12 #include "media/base/audio_bus.h"
13
14 namespace extensions {
15
16 // This code is only for testing while we don't have the rest of the
17 // CopresenceAPI service which will actually give us the whispernet client.
18 // Once we add that code, both the g_whispernet_client and the
19 // GetWhispernetClient function will go away, to be replaced by the
20 // GetWhispernetClient function that will fetch our active whispernet client
21 // from the CopresenceAPI profile keyed service.
22 copresence::WhispernetClient* g_whispernet_client = NULL;
23
24 // Copresence Private functions.
25
26 copresence::WhispernetClient* CopresencePrivateFunction::GetWhispernetClient() {
27 // This is temporary code, this needs to be replaced by the real
28 // GetWhispernetClient code from c/b/e/api/copresence/copresence_util.h
29 DCHECK(g_whispernet_client);
30 return g_whispernet_client;
31 }
32
33 // CopresenceSendFoundFunction implementation:
34 ExtensionFunction::ResponseAction CopresencePrivateSendFoundFunction::Run() {
35 if (!GetWhispernetClient() ||
36 GetWhispernetClient()->GetTokensCallback().is_null()) {
37 return RespondNow(NoArguments());
38 }
39
40 scoped_ptr<api::copresence_private::SendFound::Params> params(
41 api::copresence_private::SendFound::Params::Create(*args_));
42 EXTENSION_FUNCTION_VALIDATE(params.get());
43 GetWhispernetClient()->GetTokensCallback().Run(params->tokens);
44 return RespondNow(NoArguments());
45 }
46
47 // CopresenceSendEncodedFunction implementation:
48 ExtensionFunction::ResponseAction CopresencePrivateSendSamplesFunction::Run() {
49 if (!GetWhispernetClient() ||
50 GetWhispernetClient()->GetSamplesCallback().is_null()) {
51 return RespondNow(NoArguments());
52 }
53
54 scoped_ptr<api::copresence_private::SendSamples::Params> params(
55 api::copresence_private::SendSamples::Params::Create(*args_));
56 EXTENSION_FUNCTION_VALIDATE(params.get());
57
58 scoped_refptr<media::AudioBusRefCounted> samples =
59 media::AudioBusRefCounted::Create(1,
60 params->samples.size() / sizeof(float));
61
62 memcpy(samples->channel(0),
63 string_as_array(&params->samples),
64 params->samples.size());
65
66 GetWhispernetClient()->GetSamplesCallback().Run(params->token, samples);
67 return RespondNow(NoArguments());
68 }
69
70 // CopresenceSendDetectFunction implementation:
71 ExtensionFunction::ResponseAction CopresencePrivateSendDetectFunction::Run() {
72 if (!GetWhispernetClient() ||
73 GetWhispernetClient()->GetDetectBroadcastCallback().is_null()) {
74 return RespondNow(NoArguments());
75 }
76
77 scoped_ptr<api::copresence_private::SendDetect::Params> params(
78 api::copresence_private::SendDetect::Params::Create(*args_));
79 EXTENSION_FUNCTION_VALIDATE(params.get());
80
81 GetWhispernetClient()->GetDetectBroadcastCallback().Run(params->detected);
82 return RespondNow(NoArguments());
83 }
84
85 // CopresenceSendInitializedFunction implementation:
86 ExtensionFunction::ResponseAction
87 CopresencePrivateSendInitializedFunction::Run() {
88 if (!GetWhispernetClient() ||
89 GetWhispernetClient()->GetInitializedCallback().is_null()) {
90 return RespondNow(NoArguments());
91 }
92
93 scoped_ptr<api::copresence_private::SendInitialized::Params> params(
94 api::copresence_private::SendInitialized::Params::Create(*args_));
95 EXTENSION_FUNCTION_VALIDATE(params.get());
96
97 GetWhispernetClient()->GetInitializedCallback().Run(params->success);
98 return RespondNow(NoArguments());
99 }
100
101 void SetWhispernetClientForTesting(copresence::WhispernetClient* client) {
102 g_whispernet_client = client;
103 }
104
105 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698