| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 void BrowserContextKeyedAPIFactory<CopresencePrivateService> | 85 void BrowserContextKeyedAPIFactory<CopresencePrivateService> |
| 86 ::DeclareFactoryDependencies() { | 86 ::DeclareFactoryDependencies() { |
| 87 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); | 87 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); |
| 88 } | 88 } |
| 89 | 89 |
| 90 | 90 |
| 91 // Copresence Private functions. | 91 // Copresence Private functions. |
| 92 | 92 |
| 93 // CopresenceSendFoundFunction implementation: | 93 // CopresenceSendFoundFunction implementation: |
| 94 ExtensionFunction::ResponseAction CopresencePrivateSendFoundFunction::Run() { | 94 ExtensionFunction::ResponseAction CopresencePrivateSendFoundFunction::Run() { |
| 95 scoped_ptr<SendFound::Params> params(SendFound::Params::Create(*args_)); | 95 std::unique_ptr<SendFound::Params> params(SendFound::Params::Create(*args_)); |
| 96 EXTENSION_FUNCTION_VALIDATE(params.get()); | 96 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 97 | 97 |
| 98 WhispernetClient* whispernet_client = | 98 WhispernetClient* whispernet_client = |
| 99 CopresencePrivateService::GetFactoryInstance()->Get(browser_context()) | 99 CopresencePrivateService::GetFactoryInstance()->Get(browser_context()) |
| 100 ->GetWhispernetClient(params->client_id); | 100 ->GetWhispernetClient(params->client_id); |
| 101 if (whispernet_client->GetTokensCallback().is_null()) | 101 if (whispernet_client->GetTokensCallback().is_null()) |
| 102 return RespondNow(NoArguments()); | 102 return RespondNow(NoArguments()); |
| 103 | 103 |
| 104 std::vector<audio_modem::AudioToken> tokens; | 104 std::vector<audio_modem::AudioToken> tokens; |
| 105 for (size_t i = 0; i < params->tokens.size(); ++i) { | 105 for (size_t i = 0; i < params->tokens.size(); ++i) { |
| 106 tokens.push_back(audio_modem::AudioToken(params->tokens[i].token, | 106 tokens.push_back(audio_modem::AudioToken(params->tokens[i].token, |
| 107 params->tokens[i].audible)); | 107 params->tokens[i].audible)); |
| 108 } | 108 } |
| 109 whispernet_client->GetTokensCallback().Run(tokens); | 109 whispernet_client->GetTokensCallback().Run(tokens); |
| 110 return RespondNow(NoArguments()); | 110 return RespondNow(NoArguments()); |
| 111 } | 111 } |
| 112 | 112 |
| 113 // CopresenceSendEncodedFunction implementation: | 113 // CopresenceSendEncodedFunction implementation: |
| 114 ExtensionFunction::ResponseAction CopresencePrivateSendSamplesFunction::Run() { | 114 ExtensionFunction::ResponseAction CopresencePrivateSendSamplesFunction::Run() { |
| 115 scoped_ptr<SendSamples::Params> params(SendSamples::Params::Create(*args_)); | 115 std::unique_ptr<SendSamples::Params> params( |
| 116 SendSamples::Params::Create(*args_)); |
| 116 EXTENSION_FUNCTION_VALIDATE(params.get()); | 117 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 117 | 118 |
| 118 WhispernetClient* whispernet_client = | 119 WhispernetClient* whispernet_client = |
| 119 CopresencePrivateService::GetFactoryInstance()->Get(browser_context()) | 120 CopresencePrivateService::GetFactoryInstance()->Get(browser_context()) |
| 120 ->GetWhispernetClient(params->client_id); | 121 ->GetWhispernetClient(params->client_id); |
| 121 if (whispernet_client->GetSamplesCallback().is_null()) | 122 if (whispernet_client->GetSamplesCallback().is_null()) |
| 122 return RespondNow(NoArguments()); | 123 return RespondNow(NoArguments()); |
| 123 | 124 |
| 124 scoped_refptr<media::AudioBusRefCounted> samples = | 125 scoped_refptr<media::AudioBusRefCounted> samples = |
| 125 media::AudioBusRefCounted::Create(1, // Mono | 126 media::AudioBusRefCounted::Create(1, // Mono |
| 126 params->samples.size() / sizeof(float)); | 127 params->samples.size() / sizeof(float)); |
| 127 | 128 |
| 128 memcpy(samples->channel(0), params->samples.data(), params->samples.size()); | 129 memcpy(samples->channel(0), params->samples.data(), params->samples.size()); |
| 129 | 130 |
| 130 whispernet_client->GetSamplesCallback().Run( | 131 whispernet_client->GetSamplesCallback().Run( |
| 131 params->token.audible ? audio_modem::AUDIBLE : audio_modem::INAUDIBLE, | 132 params->token.audible ? audio_modem::AUDIBLE : audio_modem::INAUDIBLE, |
| 132 params->token.token, samples); | 133 params->token.token, samples); |
| 133 return RespondNow(NoArguments()); | 134 return RespondNow(NoArguments()); |
| 134 } | 135 } |
| 135 | 136 |
| 136 // CopresenceSendInitializedFunction implementation: | 137 // CopresenceSendInitializedFunction implementation: |
| 137 ExtensionFunction::ResponseAction | 138 ExtensionFunction::ResponseAction |
| 138 CopresencePrivateSendInitializedFunction::Run() { | 139 CopresencePrivateSendInitializedFunction::Run() { |
| 139 scoped_ptr<SendInitialized::Params> params( | 140 std::unique_ptr<SendInitialized::Params> params( |
| 140 SendInitialized::Params::Create(*args_)); | 141 SendInitialized::Params::Create(*args_)); |
| 141 EXTENSION_FUNCTION_VALIDATE(params.get()); | 142 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 142 | 143 |
| 143 CopresencePrivateService::GetFactoryInstance()->Get(browser_context()) | 144 CopresencePrivateService::GetFactoryInstance()->Get(browser_context()) |
| 144 ->OnWhispernetInitialized(params->success); | 145 ->OnWhispernetInitialized(params->success); |
| 145 | 146 |
| 146 return RespondNow(NoArguments()); | 147 return RespondNow(NoArguments()); |
| 147 } | 148 } |
| 148 | 149 |
| 149 } // namespace extensions | 150 } // namespace extensions |
| OLD | NEW |