Chromium Code Reviews| Index: chrome/browser/extensions/api/audio_modem/audio_modem_api.cc |
| diff --git a/chrome/browser/extensions/api/audio_modem/audio_modem_api.cc b/chrome/browser/extensions/api/audio_modem/audio_modem_api.cc |
| index 947e32399acdd54c248e344a2ded52bd53e6a16d..70c27ba8907e8f983c73f41361112f4c4dac31a7 100644 |
| --- a/chrome/browser/extensions/api/audio_modem/audio_modem_api.cc |
| +++ b/chrome/browser/extensions/api/audio_modem/audio_modem_api.cc |
| @@ -226,16 +226,18 @@ void AudioModemAPI::WhispernetInitComplete(bool success) { |
| void AudioModemAPI::TokensReceived(const std::vector<AudioToken>& tokens) { |
| // Distribute the tokens to the appropriate app(s). |
| - std::map<std::string, std::vector<linked_ptr<ReceivedToken>>> tokens_by_app; |
| + std::list<ReceivedToken> all_tokens; |
| + std::map<std::string, std::vector<ReceivedToken*>> tokens_by_app; |
| for (const AudioToken& token : tokens) { |
| - linked_ptr<ReceivedToken> api_token(new ReceivedToken); |
| + ReceivedToken api_token; |
| const std::string& raw_token = DecodeBase64Token(token.token); |
| - api_token->token.assign(raw_token.c_str(), |
| - raw_token.c_str() + raw_token.size()); |
| - api_token->band = token.audible ? AUDIOBAND_AUDIBLE : AUDIOBAND_INAUDIBLE; |
| + api_token.token.assign(raw_token.c_str(), |
| + raw_token.c_str() + raw_token.size()); |
| + api_token.band = token.audible ? AUDIOBAND_AUDIBLE : AUDIOBAND_INAUDIBLE; |
| + all_tokens.push_back(std::move(api_token)); |
| for (const auto& receiver : |
| receive_timers_[token.audible ? AUDIBLE : INAUDIBLE]) { |
| - tokens_by_app[receiver.first].push_back(api_token); |
| + tokens_by_app[receiver.first].push_back(&all_tokens.back()); |
| } |
| } |
| @@ -246,11 +248,21 @@ void AudioModemAPI::TokensReceived(const std::vector<AudioToken>& tokens) { |
| if (app_id.empty()) |
| continue; |
| + // Construct the event arguments by hand because the generated version |
| + // takes a std::vector<ReceivedToken>, but we use a |
| + // std::vector<ReceivedToken> since the same token can go to multiple |
|
asargent_no_longer_on_chrome
2016/03/30 19:39:24
Something in this comment isn't quite right, or at
Devlin
2016/03/30 22:23:43
Heh whoops. One of those was supposed to be a std
|
| + // listeners. |
| + scoped_ptr<base::ListValue> tokens_value(new base::ListValue()); |
| + for (const ReceivedToken* token : tokens) |
| + tokens_value->Append(token->ToValue()); |
| + scoped_ptr<base::ListValue> args(new base::ListValue()); |
| + args->Append(std::move(tokens_value)); |
| + |
| EventRouter::Get(browser_context_) |
| ->DispatchEventToExtension( |
| app_id, make_scoped_ptr(new Event(events::AUDIO_MODEM_ON_RECEIVED, |
| OnReceived::kEventName, |
| - OnReceived::Create(tokens)))); |
| + std::move(args)))); |
| } |
| } |