| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/api/copresence_private/copresence_private_ap
i.h" | 5 #include "chrome/browser/extensions/api/copresence_private/copresence_private_ap
i.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "chrome/browser/copresence/chrome_whispernet_client.h" | 11 #include "chrome/browser/copresence/chrome_whispernet_client.h" |
| 12 #include "chrome/browser/extensions/api/copresence/copresence_api.h" | 12 #include "chrome/browser/extensions/api/copresence/copresence_api.h" |
| 13 #include "chrome/common/extensions/api/copresence_private.h" | 13 #include "chrome/common/extensions/api/copresence_private.h" |
| 14 #include "components/copresence/public/copresence_constants.h" | |
| 15 #include "components/copresence/public/whispernet_client.h" | |
| 16 #include "media/base/audio_bus.h" | 14 #include "media/base/audio_bus.h" |
| 17 | 15 |
| 18 namespace extensions { | 16 namespace extensions { |
| 19 | 17 |
| 20 // Copresence Private functions. | 18 // Copresence Private functions. |
| 21 | 19 |
| 22 copresence::WhispernetClient* CopresencePrivateFunction::GetWhispernetClient() { | 20 audio_modem::WhispernetClient* |
| 21 CopresencePrivateFunction::GetWhispernetClient() { |
| 23 CopresenceService* service = | 22 CopresenceService* service = |
| 24 CopresenceService::GetFactoryInstance()->Get(browser_context()); | 23 CopresenceService::GetFactoryInstance()->Get(browser_context()); |
| 25 return service ? service->whispernet_client() : NULL; | 24 return service ? service->whispernet_client() : NULL; |
| 26 } | 25 } |
| 27 | 26 |
| 28 // CopresenceSendFoundFunction implementation: | 27 // CopresenceSendFoundFunction implementation: |
| 29 ExtensionFunction::ResponseAction CopresencePrivateSendFoundFunction::Run() { | 28 ExtensionFunction::ResponseAction CopresencePrivateSendFoundFunction::Run() { |
| 30 if (!GetWhispernetClient() || | 29 if (!GetWhispernetClient() || |
| 31 GetWhispernetClient()->GetTokensCallback().is_null()) { | 30 GetWhispernetClient()->GetTokensCallback().is_null()) { |
| 32 return RespondNow(NoArguments()); | 31 return RespondNow(NoArguments()); |
| 33 } | 32 } |
| 34 | 33 |
| 35 scoped_ptr<api::copresence_private::SendFound::Params> params( | 34 scoped_ptr<api::copresence_private::SendFound::Params> params( |
| 36 api::copresence_private::SendFound::Params::Create(*args_)); | 35 api::copresence_private::SendFound::Params::Create(*args_)); |
| 37 EXTENSION_FUNCTION_VALIDATE(params.get()); | 36 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 38 std::vector<copresence::AudioToken> tokens; | 37 std::vector<audio_modem::AudioToken> tokens; |
| 39 for (size_t i = 0; i < params->tokens.size(); ++i) { | 38 for (size_t i = 0; i < params->tokens.size(); ++i) { |
| 40 tokens.push_back(copresence::AudioToken(params->tokens[i]->token, | 39 tokens.push_back(audio_modem::AudioToken(params->tokens[i]->token, |
| 41 params->tokens[i]->audible)); | 40 params->tokens[i]->audible)); |
| 42 } | 41 } |
| 43 GetWhispernetClient()->GetTokensCallback().Run(tokens); | 42 GetWhispernetClient()->GetTokensCallback().Run(tokens); |
| 44 return RespondNow(NoArguments()); | 43 return RespondNow(NoArguments()); |
| 45 } | 44 } |
| 46 | 45 |
| 47 // CopresenceSendEncodedFunction implementation: | 46 // CopresenceSendEncodedFunction implementation: |
| 48 ExtensionFunction::ResponseAction CopresencePrivateSendSamplesFunction::Run() { | 47 ExtensionFunction::ResponseAction CopresencePrivateSendSamplesFunction::Run() { |
| 49 if (!GetWhispernetClient() || | 48 if (!GetWhispernetClient() || |
| 50 GetWhispernetClient()->GetSamplesCallback().is_null()) { | 49 GetWhispernetClient()->GetSamplesCallback().is_null()) { |
| 51 return RespondNow(NoArguments()); | 50 return RespondNow(NoArguments()); |
| 52 } | 51 } |
| 53 | 52 |
| 54 scoped_ptr<api::copresence_private::SendSamples::Params> params( | 53 scoped_ptr<api::copresence_private::SendSamples::Params> params( |
| 55 api::copresence_private::SendSamples::Params::Create(*args_)); | 54 api::copresence_private::SendSamples::Params::Create(*args_)); |
| 56 EXTENSION_FUNCTION_VALIDATE(params.get()); | 55 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 57 | 56 |
| 58 scoped_refptr<media::AudioBusRefCounted> samples = | 57 scoped_refptr<media::AudioBusRefCounted> samples = |
| 59 media::AudioBusRefCounted::Create(1, | 58 media::AudioBusRefCounted::Create(1, |
| 60 params->samples.size() / sizeof(float)); | 59 params->samples.size() / sizeof(float)); |
| 61 | 60 |
| 62 memcpy(samples->channel(0), vector_as_array(¶ms->samples), | 61 memcpy(samples->channel(0), vector_as_array(¶ms->samples), |
| 63 params->samples.size()); | 62 params->samples.size()); |
| 64 | 63 |
| 65 GetWhispernetClient()->GetSamplesCallback().Run( | 64 GetWhispernetClient()->GetSamplesCallback().Run( |
| 66 params->token.audible ? copresence::AUDIBLE : copresence::INAUDIBLE, | 65 params->token.audible ? audio_modem::AUDIBLE : audio_modem::INAUDIBLE, |
| 67 params->token.token, samples); | 66 params->token.token, samples); |
| 68 return RespondNow(NoArguments()); | 67 return RespondNow(NoArguments()); |
| 69 } | 68 } |
| 70 | 69 |
| 71 // CopresenceSendDetectFunction implementation: | 70 // CopresenceSendDetectFunction implementation: |
| 72 ExtensionFunction::ResponseAction CopresencePrivateSendDetectFunction::Run() { | 71 ExtensionFunction::ResponseAction CopresencePrivateSendDetectFunction::Run() { |
| 73 if (!GetWhispernetClient() || | 72 if (!GetWhispernetClient() || |
| 74 GetWhispernetClient()->GetDetectBroadcastCallback().is_null()) { | 73 GetWhispernetClient()->GetDetectBroadcastCallback().is_null()) { |
| 75 return RespondNow(NoArguments()); | 74 return RespondNow(NoArguments()); |
| 76 } | 75 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 93 | 92 |
| 94 scoped_ptr<api::copresence_private::SendInitialized::Params> params( | 93 scoped_ptr<api::copresence_private::SendInitialized::Params> params( |
| 95 api::copresence_private::SendInitialized::Params::Create(*args_)); | 94 api::copresence_private::SendInitialized::Params::Create(*args_)); |
| 96 EXTENSION_FUNCTION_VALIDATE(params.get()); | 95 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 97 | 96 |
| 98 GetWhispernetClient()->GetInitializedCallback().Run(params->success); | 97 GetWhispernetClient()->GetInitializedCallback().Run(params->success); |
| 99 return RespondNow(NoArguments()); | 98 return RespondNow(NoArguments()); |
| 100 } | 99 } |
| 101 | 100 |
| 102 } // namespace extensions | 101 } // namespace extensions |
| OLD | NEW |