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

Side by Side Diff: components/guest_view/browser/guest_view_manager.cc

Issue 1143333008: Getting rid of more webview memory leaks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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 "components/guest_view/browser/guest_view_manager.h" 5 #include "components/guest_view/browser/guest_view_manager.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "components/guest_view/browser/guest_view_base.h" 9 #include "components/guest_view/browser/guest_view_base.h"
10 #include "components/guest_view/browser/guest_view_manager_delegate.h" 10 #include "components/guest_view/browser/guest_view_manager_delegate.h"
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 if (instance_id != last_instance_id_removed_ + 1) 238 if (instance_id != last_instance_id_removed_ + 1)
239 break; 239 break;
240 ++last_instance_id_removed_; 240 ++last_instance_id_removed_;
241 removed_instance_ids_.erase(iter++); 241 removed_instance_ids_.erase(iter++);
242 } 242 }
243 } else { 243 } else {
244 removed_instance_ids_.insert(guest_instance_id); 244 removed_instance_ids_.insert(guest_instance_id);
245 } 245 }
246 } 246 }
247 247
248 void GuestViewManager::ViewCreated(int embedder_process_id,
249 int view_instance_id,
250 const std::string& view_type) {
251 if (guest_view_registry_.empty())
252 RegisterGuestViewTypes();
253 auto view_it = guest_view_registry_.find(view_type);
254 CHECK(view_it != guest_view_registry_.end()) <<
255 "Invalid GuestView created of type \"" << view_type << "\"";
lazyboy 2015/06/05 23:09:55 Duplicate GuestView created of type ...
paulmeyer 2015/06/08 17:53:58 This CHECK isn't checking for duplicates. It check
256
257 // Register the cleanup callback for when this view is destroyed.
258 RegisterViewCallback(embedder_process_id,
259 view_instance_id,
260 base::Bind(view_it->second.clean_up,
261 embedder_process_id,
262 view_instance_id));
263 }
264
265 void GuestViewManager::ViewGarbageCollected(int embedder_process_id,
266 int view_instance_id) {
267 // Find and call any callbacks associated with the view that has been garbage
268 // collected.
269 auto embedder_it = view_callback_map_.find(embedder_process_id);
270 if (embedder_it == view_callback_map_.end())
271 return;
272 auto& callbacks_for_embedder = embedder_it->second;
lazyboy 2015/06/05 23:09:55 I'm already lost here with auto-s :) I'd highly en
paulmeyer 2015/06/08 17:53:58 Hahaha, Good call. I am using quite a lot of autos
273 auto view_it = callbacks_for_embedder.find(view_instance_id);
274 if (view_it == callbacks_for_embedder.end())
275 return;
276 auto& callbacks_for_view = view_it->second;
277 for (auto& callback : callbacks_for_view)
278 callback.Run();
279 callbacks_for_embedder.erase(view_it);
280 }
281
248 GuestViewBase* GuestViewManager::CreateGuestInternal( 282 GuestViewBase* GuestViewManager::CreateGuestInternal(
249 content::WebContents* owner_web_contents, 283 content::WebContents* owner_web_contents,
250 const std::string& view_type) { 284 const std::string& view_type) {
251 if (guest_view_registry_.empty()) 285 if (guest_view_registry_.empty())
252 RegisterGuestViewTypes(); 286 RegisterGuestViewTypes();
253 287
254 auto it = guest_view_registry_.find(view_type); 288 auto it = guest_view_registry_.find(view_type);
255 if (it == guest_view_registry_.end()) { 289 if (it == guest_view_registry_.end()) {
256 NOTREACHED(); 290 NOTREACHED();
257 return nullptr; 291 return nullptr;
258 } 292 }
259 293
260 return it->second.Run(owner_web_contents); 294 return it->second.create.Run(owner_web_contents);
261 } 295 }
262 296
263 void GuestViewManager::RegisterGuestViewTypes() { 297 void GuestViewManager::RegisterGuestViewTypes() {
264 delegate_->RegisterAdditionalGuestViewTypes(); 298 delegate_->RegisterAdditionalGuestViewTypes();
265 } 299 }
266 300
301 void GuestViewManager::RegisterViewCallback(int embedder_process_id,
302 int view_instance_id,
303 const base::Closure& callback) {
304 view_callback_map_[embedder_process_id][view_instance_id].push_back(callback);
305 }
306
267 bool GuestViewManager::IsGuestAvailableToContext(GuestViewBase* guest) { 307 bool GuestViewManager::IsGuestAvailableToContext(GuestViewBase* guest) {
268 return delegate_->IsGuestAvailableToContext(guest); 308 return delegate_->IsGuestAvailableToContext(guest);
269 } 309 }
270 310
271 void GuestViewManager::DispatchEvent(const std::string& event_name, 311 void GuestViewManager::DispatchEvent(const std::string& event_name,
272 scoped_ptr<base::DictionaryValue> args, 312 scoped_ptr<base::DictionaryValue> args,
273 GuestViewBase* guest, 313 GuestViewBase* guest,
274 int instance_id) { 314 int instance_id) {
275 // TODO(fsamuel): GuestViewManager should probably do something more useful 315 // TODO(fsamuel): GuestViewManager should probably do something more useful
276 // here like log an error if the event could not be dispatched. 316 // here like log an error if the event could not be dispatched.
277 delegate_->DispatchEvent(event_name, args.Pass(), guest, instance_id); 317 delegate_->DispatchEvent(event_name, args.Pass(), guest, instance_id);
278 } 318 }
279 319
320 void GuestViewManager::EmbedderWillBeDestroyed(int embedder_process_id) {
321 // Find and call any callbacks associated with the embedder that is being
322 // destroyed.
323 auto embedder_it = view_callback_map_.find(embedder_process_id);
324 if (embedder_it == view_callback_map_.end())
325 return;
326 auto& callbacks_for_embedder = embedder_it->second;
327 for (auto& view_pair : callbacks_for_embedder) {
328 auto& callbacks_for_view = view_pair.second;
329 for (auto& callback : callbacks_for_view) {
330 callback.Run();
331 }
332 }
333 view_callback_map_.erase(embedder_it);
334 }
335
280 content::WebContents* GuestViewManager::GetGuestByInstanceID( 336 content::WebContents* GuestViewManager::GetGuestByInstanceID(
281 int guest_instance_id) { 337 int guest_instance_id) {
282 auto it = guest_web_contents_by_instance_id_.find(guest_instance_id); 338 auto it = guest_web_contents_by_instance_id_.find(guest_instance_id);
283 if (it == guest_web_contents_by_instance_id_.end()) 339 if (it == guest_web_contents_by_instance_id_.end())
284 return nullptr; 340 return nullptr;
285 return it->second; 341 return it->second;
286 } 342 }
287 343
288 bool GuestViewManager::CanEmbedderAccessInstanceIDMaybeKill( 344 bool GuestViewManager::CanEmbedderAccessInstanceIDMaybeKill(
289 int embedder_render_process_id, 345 int embedder_render_process_id,
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 const GuestViewManager::ElementInstanceKey& other) const { 419 const GuestViewManager::ElementInstanceKey& other) const {
364 if (embedder_process_id != other.embedder_process_id) 420 if (embedder_process_id != other.embedder_process_id)
365 return embedder_process_id < other.embedder_process_id; 421 return embedder_process_id < other.embedder_process_id;
366 422
367 return element_instance_id < other.element_instance_id; 423 return element_instance_id < other.element_instance_id;
368 } 424 }
369 425
370 bool GuestViewManager::ElementInstanceKey::operator==( 426 bool GuestViewManager::ElementInstanceKey::operator==(
371 const GuestViewManager::ElementInstanceKey& other) const { 427 const GuestViewManager::ElementInstanceKey& other) const {
372 return (embedder_process_id == other.embedder_process_id) && 428 return (embedder_process_id == other.embedder_process_id) &&
373 (element_instance_id == other.element_instance_id); 429 (element_instance_id == other.element_instance_id);
374 } 430 }
375 431
432 GuestViewManager::GuestViewData::GuestViewData(
433 const GuestViewCreateFunction& create,
434 const GuestViewCleanUpFunction& clean_up)
435 : create(create), clean_up(clean_up) {}
436
437 GuestViewManager::GuestViewData::~GuestViewData() {}
438
376 } // namespace guest_view 439 } // namespace guest_view
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698