Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(616)

Side by Side Diff: chrome/browser/extensions/api/copresence/copresence_api.cc

Issue 1828683002: [Extensions] Convert APIs to use movable types [3] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Antony's Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/copresence_api.h" 5 #include "chrome/browser/extensions/api/copresence/copresence_api.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/memory/linked_ptr.h"
11 #include "chrome/browser/copresence/chrome_whispernet_client.h" 10 #include "chrome/browser/copresence/chrome_whispernet_client.h"
12 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" 12 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h"
14 #include "chrome/common/channel_info.h" 13 #include "chrome/common/channel_info.h"
15 #include "chrome/common/extensions/api/copresence.h" 14 #include "chrome/common/extensions/api/copresence.h"
16 #include "chrome/common/extensions/manifest_handlers/copresence_manifest.h" 15 #include "chrome/common/extensions/manifest_handlers/copresence_manifest.h"
17 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
18 #include "components/copresence/copresence_manager_impl.h" 17 #include "components/copresence/copresence_manager_impl.h"
19 #include "components/copresence/proto/data.pb.h" 18 #include "components/copresence/proto/data.pb.h"
20 #include "components/copresence/proto/enums.pb.h" 19 #include "components/copresence/proto/enums.pb.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 // with subscriptions, use that instead of the apps_by_subs registry. 128 // with subscriptions, use that instead of the apps_by_subs registry.
130 std::string app_id = apps_by_subscription_id_[subscription_id]; 129 std::string app_id = apps_by_subscription_id_[subscription_id];
131 130
132 if (app_id.empty()) { 131 if (app_id.empty()) {
133 LOG(ERROR) << "Skipping message from unrecognized subscription " 132 LOG(ERROR) << "Skipping message from unrecognized subscription "
134 << subscription_id; 133 << subscription_id;
135 return; 134 return;
136 } 135 }
137 136
138 int message_count = messages.size(); 137 int message_count = messages.size();
139 std::vector<linked_ptr<api::copresence::Message>> api_messages( 138 std::vector<api::copresence::Message> api_messages(message_count);
140 message_count);
141 139
142 for (int m = 0; m < message_count; ++m) { 140 for (const copresence::Message& message : messages) {
143 api_messages[m].reset(new api::copresence::Message); 141 api::copresence::Message api_message;
144 api_messages[m]->type = messages[m].type().type(); 142 api_message.type = message.type().type();
145 api_messages[m]->payload.assign(messages[m].payload().begin(), 143 api_message.payload.assign(message.payload().begin(),
146 messages[m].payload().end()); 144 message.payload().end());
147 DVLOG(2) << "Dispatching message of type " << api_messages[m]->type << ":\n" 145 api_messages.push_back(std::move(api_message));
148 << messages[m].payload(); 146 DVLOG(2) << "Dispatching message of type " << api_message.type << ":\n"
147 << message.payload();
149 } 148 }
150 149
151 // Send the messages to the client app. 150 // Send the messages to the client app.
152 scoped_ptr<Event> event(new Event( 151 scoped_ptr<Event> event(new Event(
153 events::COPRESENCE_ON_MESSAGES_RECEIVED, OnMessagesReceived::kEventName, 152 events::COPRESENCE_ON_MESSAGES_RECEIVED, OnMessagesReceived::kEventName,
154 OnMessagesReceived::Create(subscription_id, api_messages), 153 OnMessagesReceived::Create(subscription_id, api_messages),
155 browser_context_)); 154 browser_context_));
156 EventRouter::Get(browser_context_) 155 EventRouter::Get(browser_context_)
157 ->DispatchEventToExtension(app_id, std::move(event)); 156 ->DispatchEventToExtension(app_id, std::move(event));
158 DVLOG(2) << "Passed " << api_messages.size() << " messages to app \"" 157 DVLOG(2) << "Passed " << api_messages.size() << " messages to app \""
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 scoped_ptr<SetAuthToken::Params> params(SetAuthToken::Params::Create(*args_)); 295 scoped_ptr<SetAuthToken::Params> params(SetAuthToken::Params::Create(*args_));
297 EXTENSION_FUNCTION_VALIDATE(params.get()); 296 EXTENSION_FUNCTION_VALIDATE(params.get());
298 297
299 // The token may be set to empty, to clear it. 298 // The token may be set to empty, to clear it.
300 CopresenceService::GetFactoryInstance()->Get(browser_context()) 299 CopresenceService::GetFactoryInstance()->Get(browser_context())
301 ->set_auth_token(extension_id(), params->token); 300 ->set_auth_token(extension_id(), params->token);
302 return RespondNow(NoArguments()); 301 return RespondNow(NoArguments());
303 } 302 }
304 303
305 } // namespace extensions 304 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698