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

Side by Side Diff: chrome/browser/extensions/api/messaging/extension_message_port.cc

Issue 1871713002: Convert //chrome/browser/extensions from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and fix header Created 4 years, 8 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/messaging/extension_message_port.h" 5 #include "chrome/browser/extensions/api/messaging/extension_message_port.h"
6 6
7 #include "base/memory/ptr_util.h"
7 #include "base/scoped_observer.h" 8 #include "base/scoped_observer.h"
8 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
9 #include "content/public/browser/interstitial_page.h" 10 #include "content/public/browser/interstitial_page.h"
10 #include "content/public/browser/navigation_details.h" 11 #include "content/public/browser/navigation_details.h"
11 #include "content/public/browser/render_frame_host.h" 12 #include "content/public/browser/render_frame_host.h"
12 #include "content/public/browser/render_process_host.h" 13 #include "content/public/browser/render_process_host.h"
13 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
14 #include "content/public/browser/web_contents_observer.h" 15 #include "content/public/browser/web_contents_observer.h"
15 #include "extensions/browser/extension_host.h" 16 #include "extensions/browser/extension_host.h"
16 #include "extensions/browser/process_manager.h" 17 #include "extensions/browser/process_manager.h"
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 bool ExtensionMessagePort::HasFrame(content::RenderFrameHost* rfh) const { 174 bool ExtensionMessagePort::HasFrame(content::RenderFrameHost* rfh) const {
174 return frames_.find(rfh) != frames_.end(); 175 return frames_.find(rfh) != frames_.end();
175 } 176 }
176 177
177 bool ExtensionMessagePort::IsValidPort() { 178 bool ExtensionMessagePort::IsValidPort() {
178 return !frames_.empty(); 179 return !frames_.empty();
179 } 180 }
180 181
181 void ExtensionMessagePort::DispatchOnConnect( 182 void ExtensionMessagePort::DispatchOnConnect(
182 const std::string& channel_name, 183 const std::string& channel_name,
183 scoped_ptr<base::DictionaryValue> source_tab, 184 std::unique_ptr<base::DictionaryValue> source_tab,
184 int source_frame_id, 185 int source_frame_id,
185 int guest_process_id, 186 int guest_process_id,
186 int guest_render_frame_routing_id, 187 int guest_render_frame_routing_id,
187 const std::string& source_extension_id, 188 const std::string& source_extension_id,
188 const std::string& target_extension_id, 189 const std::string& target_extension_id,
189 const GURL& source_url, 190 const GURL& source_url,
190 const std::string& tls_channel_id) { 191 const std::string& tls_channel_id) {
191 ExtensionMsg_TabConnectionInfo source; 192 ExtensionMsg_TabConnectionInfo source;
192 if (source_tab) 193 if (source_tab)
193 source.tab.Swap(source_tab.get()); 194 source.tab.Swap(source_tab.get());
194 source.frame_id = source_frame_id; 195 source.frame_id = source_frame_id;
195 196
196 ExtensionMsg_ExternalConnectionInfo info; 197 ExtensionMsg_ExternalConnectionInfo info;
197 info.target_id = target_extension_id; 198 info.target_id = target_extension_id;
198 info.source_id = source_extension_id; 199 info.source_id = source_extension_id;
199 info.source_url = source_url; 200 info.source_url = source_url;
200 info.guest_process_id = guest_process_id; 201 info.guest_process_id = guest_process_id;
201 info.guest_render_frame_routing_id = guest_render_frame_routing_id; 202 info.guest_render_frame_routing_id = guest_render_frame_routing_id;
202 203
203 SendToPort(make_scoped_ptr(new ExtensionMsg_DispatchOnConnect( 204 SendToPort(base::WrapUnique(new ExtensionMsg_DispatchOnConnect(
204 MSG_ROUTING_NONE, port_id_, channel_name, source, info, tls_channel_id))); 205 MSG_ROUTING_NONE, port_id_, channel_name, source, info, tls_channel_id)));
205 } 206 }
206 207
207 void ExtensionMessagePort::DispatchOnDisconnect( 208 void ExtensionMessagePort::DispatchOnDisconnect(
208 const std::string& error_message) { 209 const std::string& error_message) {
209 SendToPort(make_scoped_ptr(new ExtensionMsg_DispatchOnDisconnect( 210 SendToPort(base::WrapUnique(new ExtensionMsg_DispatchOnDisconnect(
210 MSG_ROUTING_NONE, port_id_, error_message))); 211 MSG_ROUTING_NONE, port_id_, error_message)));
211 } 212 }
212 213
213 void ExtensionMessagePort::DispatchOnMessage(const Message& message) { 214 void ExtensionMessagePort::DispatchOnMessage(const Message& message) {
214 SendToPort(make_scoped_ptr(new ExtensionMsg_DeliverMessage( 215 SendToPort(base::WrapUnique(
215 MSG_ROUTING_NONE, port_id_, message))); 216 new ExtensionMsg_DeliverMessage(MSG_ROUTING_NONE, port_id_, message)));
216 } 217 }
217 218
218 void ExtensionMessagePort::IncrementLazyKeepaliveCount() { 219 void ExtensionMessagePort::IncrementLazyKeepaliveCount() {
219 ProcessManager* pm = ProcessManager::Get(browser_context_); 220 ProcessManager* pm = ProcessManager::Get(browser_context_);
220 ExtensionHost* host = pm->GetBackgroundHostForExtension(extension_id_); 221 ExtensionHost* host = pm->GetBackgroundHostForExtension(extension_id_);
221 if (host && BackgroundInfo::HasLazyBackgroundPage(host->extension())) 222 if (host && BackgroundInfo::HasLazyBackgroundPage(host->extension()))
222 pm->IncrementLazyKeepaliveCount(host->extension()); 223 pm->IncrementLazyKeepaliveCount(host->extension());
223 224
224 // Keep track of the background host, so when we decrement, we only do so if 225 // Keep track of the background host, so when we decrement, we only do so if
225 // the host hasn't reloaded. 226 // the host hasn't reloaded.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 // is not triggered for |rfh|. 270 // is not triggered for |rfh|.
270 if (rfh->IsRenderFrameLive()) 271 if (rfh->IsRenderFrameLive())
271 frames_.insert(rfh); 272 frames_.insert(rfh);
272 } 273 }
273 274
274 void ExtensionMessagePort::UnregisterFrame(content::RenderFrameHost* rfh) { 275 void ExtensionMessagePort::UnregisterFrame(content::RenderFrameHost* rfh) {
275 if (frames_.erase(rfh) != 0 && frames_.empty()) 276 if (frames_.erase(rfh) != 0 && frames_.empty())
276 CloseChannel(); 277 CloseChannel();
277 } 278 }
278 279
279 void ExtensionMessagePort::SendToPort(scoped_ptr<IPC::Message> msg) { 280 void ExtensionMessagePort::SendToPort(std::unique_ptr<IPC::Message> msg) {
280 DCHECK_GT(frames_.size(), 0UL); 281 DCHECK_GT(frames_.size(), 0UL);
281 if (extension_process_) { 282 if (extension_process_) {
282 // All extension frames reside in the same process, so we can just send a 283 // All extension frames reside in the same process, so we can just send a
283 // single IPC message to the extension process as an optimization. 284 // single IPC message to the extension process as an optimization.
284 // The frame tracking is then only used to make sure that the port gets 285 // The frame tracking is then only used to make sure that the port gets
285 // closed when all frames have closed / reloaded. 286 // closed when all frames have closed / reloaded.
286 msg->set_routing_id(MSG_ROUTING_CONTROL); 287 msg->set_routing_id(MSG_ROUTING_CONTROL);
287 extension_process_->Send(msg.release()); 288 extension_process_->Send(msg.release());
288 return; 289 return;
289 } 290 }
290 for (content::RenderFrameHost* rfh : frames_) { 291 for (content::RenderFrameHost* rfh : frames_) {
291 IPC::Message* msg_copy = new IPC::Message(*msg.get()); 292 IPC::Message* msg_copy = new IPC::Message(*msg.get());
292 msg_copy->set_routing_id(rfh->GetRoutingID()); 293 msg_copy->set_routing_id(rfh->GetRoutingID());
293 rfh->Send(msg_copy); 294 rfh->Send(msg_copy);
294 } 295 }
295 } 296 }
296 297
297 } // namespace extensions 298 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698