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

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: Addressed comments. 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 << "\"";
256
257 // Register the cleanup callback for when this view is destroyed.
258 RegisterViewDestructionCallback(embedder_process_id,
259 view_instance_id,
260 base::Bind(view_it->second.cleanup_function,
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_destruction_callback_map_.find(embedder_process_id);
270 if (embedder_it == view_destruction_callback_map_.end())
271 return;
272 CallbacksForEachViewID& callbacks_for_embedder = embedder_it->second;
273 auto view_it = callbacks_for_embedder.find(view_instance_id);
274 if (view_it == callbacks_for_embedder.end())
275 return;
276 Callbacks& 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_function.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::RegisterViewDestructionCallback(
302 int embedder_process_id,
303 int view_instance_id,
304 const base::Closure& callback) {
305 view_destruction_callback_map_[embedder_process_id][view_instance_id]
306 .push_back(callback);
307 }
308
267 bool GuestViewManager::IsGuestAvailableToContext(GuestViewBase* guest) { 309 bool GuestViewManager::IsGuestAvailableToContext(GuestViewBase* guest) {
268 return delegate_->IsGuestAvailableToContext(guest); 310 return delegate_->IsGuestAvailableToContext(guest);
269 } 311 }
270 312
271 void GuestViewManager::DispatchEvent(const std::string& event_name, 313 void GuestViewManager::DispatchEvent(const std::string& event_name,
272 scoped_ptr<base::DictionaryValue> args, 314 scoped_ptr<base::DictionaryValue> args,
273 GuestViewBase* guest, 315 GuestViewBase* guest,
274 int instance_id) { 316 int instance_id) {
275 // TODO(fsamuel): GuestViewManager should probably do something more useful 317 // TODO(fsamuel): GuestViewManager should probably do something more useful
276 // here like log an error if the event could not be dispatched. 318 // here like log an error if the event could not be dispatched.
277 delegate_->DispatchEvent(event_name, args.Pass(), guest, instance_id); 319 delegate_->DispatchEvent(event_name, args.Pass(), guest, instance_id);
278 } 320 }
279 321
322 void GuestViewManager::EmbedderWillBeDestroyed(int embedder_process_id) {
323 // Find and call any callbacks associated with the embedder that is being
324 // destroyed.
325 auto embedder_it = view_destruction_callback_map_.find(embedder_process_id);
326 if (embedder_it == view_destruction_callback_map_.end())
327 return;
328 CallbacksForEachViewID& callbacks_for_embedder = embedder_it->second;
329 for (auto& view_pair : callbacks_for_embedder) {
330 Callbacks& callbacks_for_view = view_pair.second;
331 for (auto& callback : callbacks_for_view) {
332 callback.Run();
333 }
334 }
335 view_destruction_callback_map_.erase(embedder_it);
336 }
337
280 content::WebContents* GuestViewManager::GetGuestByInstanceID( 338 content::WebContents* GuestViewManager::GetGuestByInstanceID(
281 int guest_instance_id) { 339 int guest_instance_id) {
282 auto it = guest_web_contents_by_instance_id_.find(guest_instance_id); 340 auto it = guest_web_contents_by_instance_id_.find(guest_instance_id);
283 if (it == guest_web_contents_by_instance_id_.end()) 341 if (it == guest_web_contents_by_instance_id_.end())
284 return nullptr; 342 return nullptr;
285 return it->second; 343 return it->second;
286 } 344 }
287 345
288 bool GuestViewManager::CanEmbedderAccessInstanceIDMaybeKill( 346 bool GuestViewManager::CanEmbedderAccessInstanceIDMaybeKill(
289 int embedder_render_process_id, 347 int embedder_render_process_id,
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 const GuestViewManager::ElementInstanceKey& other) const { 421 const GuestViewManager::ElementInstanceKey& other) const {
364 if (embedder_process_id != other.embedder_process_id) 422 if (embedder_process_id != other.embedder_process_id)
365 return embedder_process_id < other.embedder_process_id; 423 return embedder_process_id < other.embedder_process_id;
366 424
367 return element_instance_id < other.element_instance_id; 425 return element_instance_id < other.element_instance_id;
368 } 426 }
369 427
370 bool GuestViewManager::ElementInstanceKey::operator==( 428 bool GuestViewManager::ElementInstanceKey::operator==(
371 const GuestViewManager::ElementInstanceKey& other) const { 429 const GuestViewManager::ElementInstanceKey& other) const {
372 return (embedder_process_id == other.embedder_process_id) && 430 return (embedder_process_id == other.embedder_process_id) &&
373 (element_instance_id == other.element_instance_id); 431 (element_instance_id == other.element_instance_id);
374 } 432 }
375 433
434 GuestViewManager::GuestViewData::GuestViewData(
435 const GuestViewCreateFunction& create_function,
436 const GuestViewCleanUpFunction& cleanup_function)
437 : create_function(create_function), cleanup_function(cleanup_function) {}
438
439 GuestViewManager::GuestViewData::~GuestViewData() {}
440
376 } // namespace guest_view 441 } // namespace guest_view
OLDNEW
« no previous file with comments | « components/guest_view/browser/guest_view_manager.h ('k') | components/guest_view/browser/guest_view_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698