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/copresence/chrome_whispernet_client.h" | 5 #include "chrome/browser/copresence/chrome_whispernet_client.h" |
6 | 6 |
7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
8 #include "chrome/browser/extensions/api/copresence_private/copresence_private_ap
i.h" | 8 #include "chrome/browser/extensions/api/copresence_private/copresence_private_ap
i.h" |
9 #include "chrome/browser/extensions/component_loader.h" | 9 #include "chrome/browser/extensions/component_loader.h" |
10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 } | 107 } |
108 | 108 |
109 void ChromeWhispernetClient::DecodeSamples(copresence::AudioType type, | 109 void ChromeWhispernetClient::DecodeSamples(copresence::AudioType type, |
110 const std::string& samples, | 110 const std::string& samples, |
111 const size_t token_length[2]) { | 111 const size_t token_length[2]) { |
112 DCHECK(extension_loaded_); | 112 DCHECK(extension_loaded_); |
113 DCHECK(browser_context_); | 113 DCHECK(browser_context_); |
114 DCHECK(extensions::EventRouter::Get(browser_context_)); | 114 DCHECK(extensions::EventRouter::Get(browser_context_)); |
115 | 115 |
116 extensions::api::copresence_private::DecodeSamplesParameters params; | 116 extensions::api::copresence_private::DecodeSamplesParameters params; |
117 params.samples = samples; | 117 params.samples.assign(samples.begin(), samples.end()); |
118 params.decode_audible = | 118 params.decode_audible = |
119 type == copresence::AUDIBLE || type == copresence::BOTH; | 119 type == copresence::AUDIBLE || type == copresence::BOTH; |
120 params.decode_inaudible = | 120 params.decode_inaudible = |
121 type == copresence::INAUDIBLE || type == copresence::BOTH; | 121 type == copresence::INAUDIBLE || type == copresence::BOTH; |
122 params.audible_token_length = token_length[copresence::AUDIBLE]; | 122 params.audible_token_length = token_length[copresence::AUDIBLE]; |
123 params.inaudible_token_length = token_length[copresence::INAUDIBLE]; | 123 params.inaudible_token_length = token_length[copresence::INAUDIBLE]; |
124 | 124 |
125 scoped_ptr<extensions::Event> event(new extensions::Event( | 125 scoped_ptr<extensions::Event> event(new extensions::Event( |
126 extensions::api::copresence_private::OnDecodeSamplesRequest::kEventName, | 126 extensions::api::copresence_private::OnDecodeSamplesRequest::kEventName, |
127 extensions::api::copresence_private::OnDecodeSamplesRequest::Create( | 127 extensions::api::copresence_private::OnDecodeSamplesRequest::Create( |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 const copresence::config::AudioParamData& params) { | 184 const copresence::config::AudioParamData& params) { |
185 DCHECK(browser_context_); | 185 DCHECK(browser_context_); |
186 DCHECK(extensions::EventRouter::Get(browser_context_)); | 186 DCHECK(extensions::EventRouter::Get(browser_context_)); |
187 | 187 |
188 extensions::api::copresence_private::AudioParameters audio_params; | 188 extensions::api::copresence_private::AudioParameters audio_params; |
189 | 189 |
190 // We serialize AudioConfigData to a string and send it to the whispernet | 190 // We serialize AudioConfigData to a string and send it to the whispernet |
191 // nacl wrapper. | 191 // nacl wrapper. |
192 const size_t params_size = sizeof(params); | 192 const size_t params_size = sizeof(params); |
193 audio_params.param_data.resize(params_size); | 193 audio_params.param_data.resize(params_size); |
194 memcpy(string_as_array(&audio_params.param_data), ¶ms, params_size); | 194 memcpy(vector_as_array(&audio_params.param_data), ¶ms, params_size); |
195 | 195 |
196 scoped_ptr<extensions::Event> event(new extensions::Event( | 196 scoped_ptr<extensions::Event> event(new extensions::Event( |
197 extensions::api::copresence_private::OnConfigAudio::kEventName, | 197 extensions::api::copresence_private::OnConfigAudio::kEventName, |
198 extensions::api::copresence_private::OnConfigAudio::Create(audio_params), | 198 extensions::api::copresence_private::OnConfigAudio::Create(audio_params), |
199 browser_context_)); | 199 browser_context_)); |
200 | 200 |
201 extensions::EventRouter::Get(browser_context_) | 201 extensions::EventRouter::Get(browser_context_) |
202 ->DispatchEventToExtension(kWhispernetProxyExtensionId, event.Pass()); | 202 ->DispatchEventToExtension(kWhispernetProxyExtensionId, event.Pass()); |
203 } | 203 } |
204 | 204 |
205 void ChromeWhispernetClient::OnExtensionLoaded(bool success) { | 205 void ChromeWhispernetClient::OnExtensionLoaded(bool success) { |
206 if (extension_loaded_) { | 206 if (extension_loaded_) { |
207 if (!init_callback_.is_null()) | 207 if (!init_callback_.is_null()) |
208 init_callback_.Run(success); | 208 init_callback_.Run(success); |
209 return; | 209 return; |
210 } | 210 } |
211 | 211 |
212 // Our extension just got loaded, initialize whispernet. | 212 // Our extension just got loaded, initialize whispernet. |
213 extension_loaded_ = true; | 213 extension_loaded_ = true; |
214 | 214 |
215 // This will fire another OnExtensionLoaded call once the initialization is | 215 // This will fire another OnExtensionLoaded call once the initialization is |
216 // done, which means we've initialized for realz, hence call the init | 216 // done, which means we've initialized for realz, hence call the init |
217 // callback. | 217 // callback. |
218 | 218 |
219 AudioConfiguration(GetDefaultAudioConfig()); | 219 AudioConfiguration(GetDefaultAudioConfig()); |
220 } | 220 } |
OLD | NEW |