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

Side by Side Diff: extensions/browser/process_manager.cc

Issue 111563006: Test Keeping NaCl plugins used in app background pages alive when active. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update after yzshen comments on impl patch 5 Created 7 years 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "extensions/browser/process_manager.h" 5 #include "extensions/browser/process_manager.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/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 return; 415 return;
416 416
417 BackgroundPageData& bd = background_page_data_[extension->id()]; 417 BackgroundPageData& bd = background_page_data_[extension->id()];
418 418
419 if (!bd.keepalive_impulse) { 419 if (!bd.keepalive_impulse) {
420 bd.keepalive_impulse = true; 420 bd.keepalive_impulse = true;
421 if (!bd.previous_keepalive_impulse) { 421 if (!bd.previous_keepalive_impulse) {
422 IncrementLazyKeepaliveCount(extension); 422 IncrementLazyKeepaliveCount(extension);
423 } 423 }
424 } 424 }
425
426 if (!keepalive_impulse_callback_for_testing_.is_null())
427 keepalive_impulse_callback_for_testing_.Run(extension->id());
425 } 428 }
426 429
427 // DecrementLazyKeepaliveCount is called when no calls to KeepaliveImpulse 430 // DecrementLazyKeepaliveCount is called when no calls to KeepaliveImpulse
428 // have been made for at least event_page_idle_time_. In the best case an 431 // have been made for at least event_page_idle_time_. In the best case an
429 // impulse was made just before being cleared, and the decrement will occur 432 // impulse was made just before being cleared, and the decrement will occur
430 // event_page_idle_time_ later, causing a 2 * event_page_idle_time_ total time 433 // event_page_idle_time_ later, causing a 2 * event_page_idle_time_ total time
431 // for extension to be shut down based on impulses. Worst case is an impulse 434 // for extension to be shut down based on impulses. Worst case is an impulse
432 // just after a clear, adding one check cycle and resulting in 3x total time. 435 // just after a clear, adding one check cycle and resulting in 3x total time.
433 void ProcessManager::OnKeepaliveImpulseCheck() { 436 void ProcessManager::OnKeepaliveImpulseCheck() {
434 for (BackgroundPageDataMap::iterator i = background_page_data_.begin(); 437 for (BackgroundPageDataMap::iterator i = background_page_data_.begin();
435 i != background_page_data_.end(); 438 i != background_page_data_.end();
436 ++i) { 439 ++i) {
437 if (i->second.previous_keepalive_impulse && !i->second.keepalive_impulse) 440 if (i->second.previous_keepalive_impulse && !i->second.keepalive_impulse) {
438 DecrementLazyKeepaliveCount(i->first); 441 DecrementLazyKeepaliveCount(i->first);
442 if (!keepalive_impulse_decrement_callback_for_testing_.is_null())
443 keepalive_impulse_decrement_callback_for_testing_.Run(i->first);
444 }
439 445
440 i->second.previous_keepalive_impulse = i->second.keepalive_impulse; 446 i->second.previous_keepalive_impulse = i->second.keepalive_impulse;
441 i->second.keepalive_impulse = false; 447 i->second.keepalive_impulse = false;
442 } 448 }
443 449
444 // OnKeepaliveImpulseCheck() is always called in constructor, but in unit 450 // OnKeepaliveImpulseCheck() is always called in constructor, but in unit
445 // tests there will be no message loop. In that event don't schedule tasks. 451 // tests there will be no message loop. In that event don't schedule tasks.
446 if (base::MessageLoop::current()) { 452 if (base::MessageLoop::current()) {
447 base::MessageLoop::current()->PostDelayedTask( 453 base::MessageLoop::current()->PostDelayedTask(
448 FROM_HERE, 454 FROM_HERE,
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 if (!service || !service->is_ready()) 563 if (!service || !service->is_ready())
558 return; 564 return;
559 565
560 CreateBackgroundHostsForProfileStartup(); 566 CreateBackgroundHostsForProfileStartup();
561 } 567 }
562 568
563 content::BrowserContext* ProcessManager::GetBrowserContext() const { 569 content::BrowserContext* ProcessManager::GetBrowserContext() const {
564 return site_instance_->GetBrowserContext(); 570 return site_instance_->GetBrowserContext();
565 } 571 }
566 572
573 void ProcessManager::SetKeepaliveImpulseCallbackForTesting(
574 const ImpulseCallbackForTesting& callback) {
575 keepalive_impulse_callback_for_testing_ = callback;
576 }
577
578 void ProcessManager::SetKeepaliveImpulseDecrementCallbackForTesting(
579 const ImpulseCallbackForTesting& callback) {
580 keepalive_impulse_decrement_callback_for_testing_ = callback;
581 }
582
567 void ProcessManager::Observe(int type, 583 void ProcessManager::Observe(int type,
568 const content::NotificationSource& source, 584 const content::NotificationSource& source,
569 const content::NotificationDetails& details) { 585 const content::NotificationDetails& details) {
570 switch (type) { 586 switch (type) {
571 case chrome::NOTIFICATION_EXTENSIONS_READY: 587 case chrome::NOTIFICATION_EXTENSIONS_READY:
572 case chrome::NOTIFICATION_PROFILE_CREATED: { 588 case chrome::NOTIFICATION_PROFILE_CREATED: {
573 CreateBackgroundHostsForProfileStartup(); 589 CreateBackgroundHostsForProfileStartup();
574 break; 590 break;
575 } 591 }
576 592
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 } 880 }
865 881
866 bool IncognitoProcessManager::IsIncognitoEnabled(const Extension* extension) { 882 bool IncognitoProcessManager::IsIncognitoEnabled(const Extension* extension) {
867 // Keep in sync with duplicate in extension_info_map.cc. 883 // Keep in sync with duplicate in extension_info_map.cc.
868 ExtensionService* service = ExtensionSystem::GetForBrowserContext( 884 ExtensionService* service = ExtensionSystem::GetForBrowserContext(
869 GetBrowserContext())->extension_service(); 885 GetBrowserContext())->extension_service();
870 return extension_util::IsIncognitoEnabled(extension->id(), service); 886 return extension_util::IsIncognitoEnabled(extension->id(), service);
871 } 887 }
872 888
873 } // namespace extensions 889 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698