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

Side by Side Diff: chrome/browser/extensions/extension_event_router.cc

Issue 9562017: Keep lazy background page alive while there are pending network requests or (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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 | Annotate | Revision Log
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/extension_event_router.h" 5 #include "chrome/browser/extensions/extension_event_router.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/extensions/extension_devtools_manager.h" 10 #include "chrome/browser/extensions/extension_devtools_manager.h"
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 for (std::set<ListenerProcess>::iterator listener = listeners.begin(); 354 for (std::set<ListenerProcess>::iterator listener = listeners.begin();
355 listener != listeners.end(); ++listener) { 355 listener != listeners.end(); ++listener) {
356 if (!extension_id.empty() && extension_id != listener->extension_id) 356 if (!extension_id.empty() && extension_id != listener->extension_id)
357 continue; 357 continue;
358 358
359 const Extension* extension = service->extensions()->GetByID( 359 const Extension* extension = service->extensions()->GetByID(
360 listener->extension_id); 360 listener->extension_id);
361 361
362 if (extension && !CanDispatchEventNow(extension)) { 362 if (extension && !CanDispatchEventNow(extension)) {
363 AppendEvent(extension->id(), event); 363 AppendEvent(extension->id(), event);
364 pm->CreateBackgroundHost(extension, extension->GetBackgroundURL()); 364 if (!pm->GetBackgroundHostForExtension(extension->id())) {
365 // Balanced in DispatchPendingEvents, after the page has loaded.
Yoyo Zhou 2012/03/02 03:10:46 Is it possible for there to be a race between load
Matt Perry 2012/03/02 20:25:21 The only thing that causes a lazy bg page to load
366 pm->IncrementLazyKeepaliveCount(extension);
367 pm->CreateBackgroundHost(extension, extension->GetBackgroundURL());
368 }
365 } 369 }
366 } 370 }
367 } 371 }
368 372
369 void ExtensionEventRouter::IncrementInFlightEvents(const Extension* extension) { 373 void ExtensionEventRouter::IncrementInFlightEvents(const Extension* extension) {
370 if (!extension->background_page_persists()) { 374 if (!extension->background_page_persists()) {
371 profile_->GetExtensionProcessManager()->IncrementLazyKeepaliveCount( 375 profile_->GetExtensionProcessManager()->IncrementLazyKeepaliveCount(
372 extension); 376 extension);
373 } 377 }
374 } 378 }
(...skipping 26 matching lines...) Expand all
401 void ExtensionEventRouter::DispatchPendingEvents( 405 void ExtensionEventRouter::DispatchPendingEvents(
402 const std::string& extension_id) { 406 const std::string& extension_id) {
403 CHECK(!extension_id.empty()); 407 CHECK(!extension_id.empty());
404 PendingEventsPerExtMap::const_iterator map_it = 408 PendingEventsPerExtMap::const_iterator map_it =
405 pending_events_.find(extension_id); 409 pending_events_.find(extension_id);
406 if (map_it == pending_events_.end()) { 410 if (map_it == pending_events_.end()) {
407 NOTREACHED(); // lazy page should not load without any pending events 411 NOTREACHED(); // lazy page should not load without any pending events
408 return; 412 return;
409 } 413 }
410 414
411 // Temporarily increment the keepalive count while dispatching the events.
412 // This also ensures that if no events were dispatched, the extension returns
413 // to "idle" and is shut down.
414 const Extension* extension =
415 profile_->GetExtensionService()->extensions()->GetByID(extension_id);
416 ExtensionProcessManager* pm = profile_->GetExtensionProcessManager();
417 pm->IncrementLazyKeepaliveCount(extension);
418
419 PendingEventsList* events_list = map_it->second.get(); 415 PendingEventsList* events_list = map_it->second.get();
420 for (PendingEventsList::const_iterator it = events_list->begin(); 416 for (PendingEventsList::const_iterator it = events_list->begin();
421 it != events_list->end(); ++it) 417 it != events_list->end(); ++it)
422 DispatchEventImpl(extension_id, *it, true); 418 DispatchEventImpl(extension_id, *it, true);
423 419
424 events_list->clear(); 420 events_list->clear();
425 pending_events_.erase(extension_id); 421 pending_events_.erase(extension_id);
426 422
423 // Balance the keepalive addref in LoadLazyBackgroundPagesForEvent.
424 const Extension* extension =
425 profile_->GetExtensionService()->extensions()->GetByID(extension_id);
426 ExtensionProcessManager* pm = profile_->GetExtensionProcessManager();
427 pm->DecrementLazyKeepaliveCount(extension); 427 pm->DecrementLazyKeepaliveCount(extension);
428 } 428 }
429 429
430 void ExtensionEventRouter::Observe( 430 void ExtensionEventRouter::Observe(
431 int type, 431 int type,
432 const content::NotificationSource& source, 432 const content::NotificationSource& source,
433 const content::NotificationDetails& details) { 433 const content::NotificationDetails& details) {
434 switch (type) { 434 switch (type) {
435 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: 435 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED:
436 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { 436 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 extension->id(), kOnInstalledEvent, "[]", NULL, GURL()); 499 extension->id(), kOnInstalledEvent, "[]", NULL, GURL());
500 break; 500 break;
501 } 501 }
502 502
503 // TODO(tessamac): if background page crashed/failed clear queue. 503 // TODO(tessamac): if background page crashed/failed clear queue.
504 default: 504 default:
505 NOTREACHED(); 505 NOTREACHED();
506 return; 506 return;
507 } 507 }
508 } 508 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698