OLD | NEW |
---|---|
(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, this entire namespace will go away. | |
not at google - send to devlin
2014/07/31 23:31:18
"this entire namespace will go away" - what namesp
rkc
2014/08/01 19:20:00
This was referring to the util namespace, that I r
| |
19 copresence::WhispernetClient* g_whispernet_client = NULL; | |
20 | |
21 copresence::WhispernetClient* GetWhispernetClient( | |
22 content::BrowserContext* context) { | |
23 // This is temporary code, this needs to be replaced by the real | |
24 // GetWhispernetClient code from c/b/e/api/copresence/copresence_util.h | |
25 DCHECK(g_whispernet_client); | |
26 return g_whispernet_client; | |
27 } | |
28 | |
29 // Copresence Private functions. | |
30 | |
31 // CopresenceSendFoundFunction implementation: | |
32 ExtensionFunction::ResponseAction CopresencePrivateSendFoundFunction::Run() { | |
33 if (!GetWhispernetClient(browser_context()) || | |
34 GetWhispernetClient(browser_context())->GetTokensCallback().is_null()) { | |
35 return RespondNow(ArgumentList(results_.Pass())); | |
not at google - send to devlin
2014/07/31 23:31:18
given there are actually no results (and no result
rkc
2014/08/01 19:20:00
Done.
| |
36 } | |
37 | |
38 scoped_ptr<api::copresence_private::SendFound::Params> params( | |
39 api::copresence_private::SendFound::Params::Create(*args_)); | |
40 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
41 GetWhispernetClient(browser_context())->GetTokensCallback().Run( | |
42 params->tokens); | |
43 return RespondNow(ArgumentList(results_.Pass())); | |
44 } | |
45 | |
46 // CopresenceSendEncodedFunction implementation: | |
47 ExtensionFunction::ResponseAction CopresencePrivateSendSamplesFunction::Run() { | |
48 if (!GetWhispernetClient(browser_context()) || | |
49 GetWhispernetClient(browser_context())->GetSamplesCallback().is_null()) { | |
50 return RespondNow(ArgumentList(results_.Pass())); | |
51 } | |
52 | |
53 scoped_ptr<api::copresence_private::SendSamples::Params> params( | |
54 api::copresence_private::SendSamples::Params::Create(*args_)); | |
55 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
56 | |
57 scoped_refptr<media::AudioBusRefCounted> samples = | |
58 media::AudioBusRefCounted::Create(1, | |
59 params->samples.size() / sizeof(float)); | |
60 | |
61 memcpy(samples->channel(0), | |
62 string_as_array(¶ms->samples), | |
63 params->samples.size()); | |
64 | |
65 GetWhispernetClient(browser_context())->GetSamplesCallback().Run( | |
66 params->token, samples); | |
67 return RespondNow(ArgumentList(results_.Pass())); | |
68 } | |
69 | |
70 // CopresenceSendDetectFunction implementation: | |
71 ExtensionFunction::ResponseAction CopresencePrivateSendDetectFunction::Run() { | |
72 if (!GetWhispernetClient(browser_context()) || | |
73 GetWhispernetClient(browser_context()) | |
74 ->GetDetectBroadcastCallback() | |
75 .is_null()) { | |
76 return RespondNow(ArgumentList(results_.Pass())); | |
77 } | |
78 | |
79 scoped_ptr<api::copresence_private::SendDetect::Params> params( | |
80 api::copresence_private::SendDetect::Params::Create(*args_)); | |
81 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
82 | |
83 GetWhispernetClient(browser_context())->GetDetectBroadcastCallback().Run( | |
84 params->detected); | |
85 return RespondNow(ArgumentList(results_.Pass())); | |
86 } | |
87 | |
88 // CopresenceSendInitializedFunction implementation: | |
89 ExtensionFunction::ResponseAction | |
90 CopresencePrivateSendInitializedFunction::Run() { | |
91 if (!GetWhispernetClient(browser_context()) || | |
92 GetWhispernetClient(browser_context()) | |
93 ->GetInitializedCallback() | |
94 .is_null()) { | |
95 return RespondNow(ArgumentList(results_.Pass())); | |
96 } | |
97 | |
98 scoped_ptr<api::copresence_private::SendInitialized::Params> params( | |
99 api::copresence_private::SendInitialized::Params::Create(*args_)); | |
100 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
101 | |
102 GetWhispernetClient(browser_context())->GetInitializedCallback().Run( | |
103 params->success); | |
104 return RespondNow(ArgumentList(results_.Pass())); | |
105 } | |
106 | |
107 void SetWhispernetClientForTesting(copresence::WhispernetClient* client) { | |
108 g_whispernet_client = client; | |
109 } | |
110 | |
111 } // namespace extensions | |
OLD | NEW |