| 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" |
| 14 #include "components/copresence/public/whispernet_client.h" | 15 #include "components/copresence/public/whispernet_client.h" |
| 15 #include "media/base/audio_bus.h" | 16 #include "media/base/audio_bus.h" |
| 16 | 17 |
| 17 namespace extensions { | 18 namespace extensions { |
| 18 | 19 |
| 19 // Copresence Private functions. | 20 // Copresence Private functions. |
| 20 | 21 |
| 21 copresence::WhispernetClient* CopresencePrivateFunction::GetWhispernetClient() { | 22 copresence::WhispernetClient* CopresencePrivateFunction::GetWhispernetClient() { |
| 22 CopresenceService* service = | 23 CopresenceService* service = |
| 23 CopresenceService::GetFactoryInstance()->Get(browser_context()); | 24 CopresenceService::GetFactoryInstance()->Get(browser_context()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 | 57 |
| 57 scoped_refptr<media::AudioBusRefCounted> samples = | 58 scoped_refptr<media::AudioBusRefCounted> samples = |
| 58 media::AudioBusRefCounted::Create(1, | 59 media::AudioBusRefCounted::Create(1, |
| 59 params->samples.size() / sizeof(float)); | 60 params->samples.size() / sizeof(float)); |
| 60 | 61 |
| 61 memcpy(samples->channel(0), | 62 memcpy(samples->channel(0), |
| 62 string_as_array(¶ms->samples), | 63 string_as_array(¶ms->samples), |
| 63 params->samples.size()); | 64 params->samples.size()); |
| 64 | 65 |
| 65 GetWhispernetClient()->GetSamplesCallback().Run( | 66 GetWhispernetClient()->GetSamplesCallback().Run( |
| 66 params->token.token, params->token.audible, samples); | 67 params->token.token, |
| 68 params->token.audible ? copresence::AUDIBLE : copresence::INAUDIBLE, |
| 69 samples); |
| 67 return RespondNow(NoArguments()); | 70 return RespondNow(NoArguments()); |
| 68 } | 71 } |
| 69 | 72 |
| 70 // CopresenceSendDetectFunction implementation: | 73 // CopresenceSendDetectFunction implementation: |
| 71 ExtensionFunction::ResponseAction CopresencePrivateSendDetectFunction::Run() { | 74 ExtensionFunction::ResponseAction CopresencePrivateSendDetectFunction::Run() { |
| 72 if (!GetWhispernetClient() || | 75 if (!GetWhispernetClient() || |
| 73 GetWhispernetClient()->GetDetectBroadcastCallback().is_null()) { | 76 GetWhispernetClient()->GetDetectBroadcastCallback().is_null()) { |
| 74 return RespondNow(NoArguments()); | 77 return RespondNow(NoArguments()); |
| 75 } | 78 } |
| 76 | 79 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 92 | 95 |
| 93 scoped_ptr<api::copresence_private::SendInitialized::Params> params( | 96 scoped_ptr<api::copresence_private::SendInitialized::Params> params( |
| 94 api::copresence_private::SendInitialized::Params::Create(*args_)); | 97 api::copresence_private::SendInitialized::Params::Create(*args_)); |
| 95 EXTENSION_FUNCTION_VALIDATE(params.get()); | 98 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 96 | 99 |
| 97 GetWhispernetClient()->GetInitializedCallback().Run(params->success); | 100 GetWhispernetClient()->GetInitializedCallback().Run(params->success); |
| 98 return RespondNow(NoArguments()); | 101 return RespondNow(NoArguments()); |
| 99 } | 102 } |
| 100 | 103 |
| 101 } // namespace extensions | 104 } // namespace extensions |
| OLD | NEW |