| 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/copresence/chrome_whispernet_config.h" | 8 #include "chrome/browser/copresence/chrome_whispernet_config.h" |
| 9 #include "chrome/browser/extensions/api/copresence_private/copresence_private_ap
i.h" | 9 #include "chrome/browser/extensions/api/copresence_private/copresence_private_ap
i.h" |
| 10 #include "chrome/browser/extensions/component_loader.h" | 10 #include "chrome/browser/extensions/component_loader.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 AudioType type, | 126 AudioType type, |
| 127 const TokenParameters token_params[2]) { | 127 const TokenParameters token_params[2]) { |
| 128 DCHECK(type == AUDIBLE || type == INAUDIBLE); | 128 DCHECK(type == AUDIBLE || type == INAUDIBLE); |
| 129 | 129 |
| 130 EncodeTokenParameters params; | 130 EncodeTokenParameters params; |
| 131 params.token.token = token_str; | 131 params.token.token = token_str; |
| 132 params.token.audible = (type == AUDIBLE); | 132 params.token.audible = (type == AUDIBLE); |
| 133 ConvertTokenParams(token_params[type], ¶ms.token_params); | 133 ConvertTokenParams(token_params[type], ¶ms.token_params); |
| 134 | 134 |
| 135 SendEventIfLoaded(make_scoped_ptr(new Event( | 135 SendEventIfLoaded(make_scoped_ptr(new Event( |
| 136 OnEncodeTokenRequest::kEventName, | 136 extensions::events::UNKNOWN, OnEncodeTokenRequest::kEventName, |
| 137 OnEncodeTokenRequest::Create(client_id_, params), | 137 OnEncodeTokenRequest::Create(client_id_, params), browser_context_))); |
| 138 browser_context_))); | |
| 139 } | 138 } |
| 140 | 139 |
| 141 void ChromeWhispernetClient::DecodeSamples( | 140 void ChromeWhispernetClient::DecodeSamples( |
| 142 AudioType type, | 141 AudioType type, |
| 143 const std::string& samples, | 142 const std::string& samples, |
| 144 const TokenParameters token_params[2]) { | 143 const TokenParameters token_params[2]) { |
| 145 DecodeSamplesParameters params; | 144 DecodeSamplesParameters params; |
| 146 params.samples.assign(samples.begin(), samples.end()); | 145 params.samples.assign(samples.begin(), samples.end()); |
| 147 params.decode_audible = (type == AUDIBLE || type == BOTH); | 146 params.decode_audible = (type == AUDIBLE || type == BOTH); |
| 148 params.decode_inaudible = (type == INAUDIBLE || type == BOTH); | 147 params.decode_inaudible = (type == INAUDIBLE || type == BOTH); |
| 149 ConvertTokenParams(token_params[AUDIBLE], ¶ms.audible_token_params); | 148 ConvertTokenParams(token_params[AUDIBLE], ¶ms.audible_token_params); |
| 150 ConvertTokenParams(token_params[INAUDIBLE], ¶ms.inaudible_token_params); | 149 ConvertTokenParams(token_params[INAUDIBLE], ¶ms.inaudible_token_params); |
| 151 | 150 |
| 152 SendEventIfLoaded(make_scoped_ptr(new Event( | 151 SendEventIfLoaded(make_scoped_ptr(new Event( |
| 153 OnDecodeSamplesRequest::kEventName, | 152 extensions::events::UNKNOWN, OnDecodeSamplesRequest::kEventName, |
| 154 OnDecodeSamplesRequest::Create(client_id_, params), | 153 OnDecodeSamplesRequest::Create(client_id_, params), browser_context_))); |
| 155 browser_context_))); | |
| 156 } | 154 } |
| 157 | 155 |
| 158 void ChromeWhispernetClient::RegisterTokensCallback( | 156 void ChromeWhispernetClient::RegisterTokensCallback( |
| 159 const TokensCallback& tokens_callback) { | 157 const TokensCallback& tokens_callback) { |
| 160 tokens_callback_ = tokens_callback; | 158 tokens_callback_ = tokens_callback; |
| 161 } | 159 } |
| 162 | 160 |
| 163 void ChromeWhispernetClient::RegisterSamplesCallback( | 161 void ChromeWhispernetClient::RegisterSamplesCallback( |
| 164 const SamplesCallback& samples_callback) { | 162 const SamplesCallback& samples_callback) { |
| 165 samples_callback_ = samples_callback; | 163 samples_callback_ = samples_callback; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 185 AudioParameters audio_params; | 183 AudioParameters audio_params; |
| 186 | 184 |
| 187 // We serialize AudioConfigData to a string and send it to the whispernet | 185 // We serialize AudioConfigData to a string and send it to the whispernet |
| 188 // nacl wrapper. | 186 // nacl wrapper. |
| 189 const size_t params_size = sizeof(params); | 187 const size_t params_size = sizeof(params); |
| 190 audio_params.param_data.resize(params_size); | 188 audio_params.param_data.resize(params_size); |
| 191 memcpy(vector_as_array(&audio_params.param_data), ¶ms, params_size); | 189 memcpy(vector_as_array(&audio_params.param_data), ¶ms, params_size); |
| 192 | 190 |
| 193 DVLOG(3) << "Configuring audio for client " << client_id_; | 191 DVLOG(3) << "Configuring audio for client " << client_id_; |
| 194 SendEventIfLoaded(make_scoped_ptr(new Event( | 192 SendEventIfLoaded(make_scoped_ptr(new Event( |
| 195 OnConfigAudio::kEventName, | 193 extensions::events::UNKNOWN, OnConfigAudio::kEventName, |
| 196 OnConfigAudio::Create(client_id_, audio_params), | 194 OnConfigAudio::Create(client_id_, audio_params), browser_context_))); |
| 197 browser_context_))); | |
| 198 } | 195 } |
| 199 | 196 |
| 200 void ChromeWhispernetClient::SendEventIfLoaded( | 197 void ChromeWhispernetClient::SendEventIfLoaded( |
| 201 scoped_ptr<extensions::Event> event) { | 198 scoped_ptr<extensions::Event> event) { |
| 202 DCHECK(event_router_); | 199 DCHECK(event_router_); |
| 203 | 200 |
| 204 if (extension_loaded_) { | 201 if (extension_loaded_) { |
| 205 event_router_->DispatchEventToExtension(kWhispernetProxyExtensionId, | 202 event_router_->DispatchEventToExtension(kWhispernetProxyExtensionId, |
| 206 event.Pass()); | 203 event.Pass()); |
| 207 } else { | 204 } else { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 223 // Thus we can just discard the pointers at the end. | 220 // Thus we can just discard the pointers at the end. |
| 224 DCHECK(event_router_); | 221 DCHECK(event_router_); |
| 225 for (Event* event : queued_events_) { | 222 for (Event* event : queued_events_) { |
| 226 event_router_->DispatchEventToExtension(kWhispernetProxyExtensionId, | 223 event_router_->DispatchEventToExtension(kWhispernetProxyExtensionId, |
| 227 make_scoped_ptr(event)); | 224 make_scoped_ptr(event)); |
| 228 } | 225 } |
| 229 queued_events_.weak_clear(); | 226 queued_events_.weak_clear(); |
| 230 | 227 |
| 231 extension_loaded_ = true; | 228 extension_loaded_ = true; |
| 232 } | 229 } |
| OLD | NEW |