Chromium Code Reviews| 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, 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::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.
| |
| 25 content::BrowserContext* context) { | |
| 26 // This is temporary code, this needs to be replaced by the real | |
| 27 // GetWhispernetClient code from c/b/e/api/copresence/copresence_util.h | |
| 28 DCHECK(g_whispernet_client); | |
| 29 return g_whispernet_client; | |
| 30 } | |
| 31 | |
| 32 // Copresence Private functions. | |
| 33 | |
| 34 copresence::WhispernetClient* CopresencePrivateFunction::GetWhispernetClient() { | |
| 35 return extensions::GetWhispernetClient(browser_context()); | |
| 36 } | |
| 37 | |
| 38 // CopresenceSendFoundFunction implementation: | |
| 39 ExtensionFunction::ResponseAction CopresencePrivateSendFoundFunction::Run() { | |
| 40 if (!GetWhispernetClient() || | |
| 41 GetWhispernetClient()->GetTokensCallback().is_null()) { | |
| 42 return RespondNow(NoArguments()); | |
| 43 } | |
| 44 | |
| 45 scoped_ptr<api::copresence_private::SendFound::Params> params( | |
| 46 api::copresence_private::SendFound::Params::Create(*args_)); | |
| 47 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
| 48 GetWhispernetClient()->GetTokensCallback().Run(params->tokens); | |
| 49 return RespondNow(NoArguments()); | |
| 50 } | |
| 51 | |
| 52 // CopresenceSendEncodedFunction implementation: | |
| 53 ExtensionFunction::ResponseAction CopresencePrivateSendSamplesFunction::Run() { | |
| 54 if (!GetWhispernetClient() || | |
| 55 GetWhispernetClient()->GetSamplesCallback().is_null()) { | |
| 56 return RespondNow(NoArguments()); | |
| 57 } | |
| 58 | |
| 59 scoped_ptr<api::copresence_private::SendSamples::Params> params( | |
| 60 api::copresence_private::SendSamples::Params::Create(*args_)); | |
| 61 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
| 62 | |
| 63 scoped_refptr<media::AudioBusRefCounted> samples = | |
| 64 media::AudioBusRefCounted::Create(1, | |
| 65 params->samples.size() / sizeof(float)); | |
| 66 | |
| 67 memcpy(samples->channel(0), | |
| 68 string_as_array(¶ms->samples), | |
| 69 params->samples.size()); | |
| 70 | |
| 71 GetWhispernetClient()->GetSamplesCallback().Run(params->token, samples); | |
| 72 return RespondNow(NoArguments()); | |
| 73 } | |
| 74 | |
| 75 // CopresenceSendDetectFunction implementation: | |
| 76 ExtensionFunction::ResponseAction CopresencePrivateSendDetectFunction::Run() { | |
| 77 if (!GetWhispernetClient() || | |
| 78 GetWhispernetClient()->GetDetectBroadcastCallback().is_null()) { | |
| 79 return RespondNow(NoArguments()); | |
| 80 } | |
| 81 | |
| 82 scoped_ptr<api::copresence_private::SendDetect::Params> params( | |
| 83 api::copresence_private::SendDetect::Params::Create(*args_)); | |
| 84 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
| 85 | |
| 86 GetWhispernetClient()->GetDetectBroadcastCallback().Run(params->detected); | |
| 87 return RespondNow(NoArguments()); | |
| 88 } | |
| 89 | |
| 90 // CopresenceSendInitializedFunction implementation: | |
| 91 ExtensionFunction::ResponseAction | |
| 92 CopresencePrivateSendInitializedFunction::Run() { | |
| 93 if (!GetWhispernetClient() || | |
| 94 GetWhispernetClient()->GetInitializedCallback().is_null()) { | |
| 95 return RespondNow(NoArguments()); | |
| 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()->GetInitializedCallback().Run(params->success); | |
| 103 return RespondNow(NoArguments()); | |
| 104 } | |
| 105 | |
| 106 void SetWhispernetClientForTesting(copresence::WhispernetClient* client) { | |
| 107 g_whispernet_client = client; | |
| 108 } | |
| 109 | |
| 110 } // namespace extensions | |
| OLD | NEW |