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

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

Issue 10804020: Introduce runtime.onSuspendCanceled() event. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 105
106 struct ExtensionProcessManager::BackgroundPageData { 106 struct ExtensionProcessManager::BackgroundPageData {
107 // The count of things keeping the lazy background page alive. 107 // The count of things keeping the lazy background page alive.
108 int lazy_keepalive_count; 108 int lazy_keepalive_count;
109 109
110 // This is used with the ShouldUnload message, to ensure that the extension 110 // This is used with the ShouldUnload message, to ensure that the extension
111 // remained idle between sending the message and receiving the ack. 111 // remained idle between sending the message and receiving the ack.
112 int close_sequence_id; 112 int close_sequence_id;
113 113
114 // True if the page responded to the ShouldUnload message and is currently 114 // True if the page responded to the ShouldUnload message and is currently
115 // dispatching the unload event. We use this to ignore any activity 115 // dispatching the unload event. During this time any events that arrive will
116 // generated during the unload event that would otherwise keep the 116 // cancel the unload process and an onSuspendCanceled event will be dispatched
117 // extension alive. 117 // to the page.
118 bool is_closing; 118 bool is_closing;
benwells 2012/07/19 04:01:21 Can we change this name too?
koz (OOO until 15th September) 2012/07/19 06:52:11 See previous comment.
119 119
120 // Keeps track of when this page was last unloaded. Used for perf metrics. 120 // Keeps track of when this page was last unloaded. Used for perf metrics.
121 linked_ptr<PerfTimer> since_unloaded; 121 linked_ptr<PerfTimer> since_unloaded;
122 122
123 BackgroundPageData() 123 BackgroundPageData()
124 : lazy_keepalive_count(0), close_sequence_id(0), is_closing(false) {} 124 : lazy_keepalive_count(0), close_sequence_id(0), is_closing(false) {}
125 }; 125 };
126 126
127 // 127 //
128 // ExtensionProcessManager 128 // ExtensionProcessManager
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 return 0; 410 return 0;
411 411
412 return background_page_data_[extension->id()].lazy_keepalive_count; 412 return background_page_data_[extension->id()].lazy_keepalive_count;
413 } 413 }
414 414
415 int ExtensionProcessManager::IncrementLazyKeepaliveCount( 415 int ExtensionProcessManager::IncrementLazyKeepaliveCount(
416 const Extension* extension) { 416 const Extension* extension) {
417 if (!extension->has_lazy_background_page()) 417 if (!extension->has_lazy_background_page())
418 return 0; 418 return 0;
419 419
420 background_page_data_[extension->id()].is_closing = false;
420 int& count = background_page_data_[extension->id()].lazy_keepalive_count; 421 int& count = background_page_data_[extension->id()].lazy_keepalive_count;
421 if (++count == 1) 422 if (++count == 1)
422 OnLazyBackgroundPageActive(extension->id()); 423 OnLazyBackgroundPageActive(extension->id());
423 424
424 return count; 425 return count;
425 } 426 }
426 427
427 int ExtensionProcessManager::DecrementLazyKeepaliveCount( 428 int ExtensionProcessManager::DecrementLazyKeepaliveCount(
428 const Extension* extension) { 429 const Extension* extension) {
429 if (!extension->has_lazy_background_page()) 430 if (!extension->has_lazy_background_page())
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 void ExtensionProcessManager::OnShouldUnloadAck( 486 void ExtensionProcessManager::OnShouldUnloadAck(
486 const std::string& extension_id, int sequence_id) { 487 const std::string& extension_id, int sequence_id) {
487 ExtensionHost* host = GetBackgroundHostForExtension(extension_id); 488 ExtensionHost* host = GetBackgroundHostForExtension(extension_id);
488 if (host && 489 if (host &&
489 sequence_id == background_page_data_[extension_id].close_sequence_id) { 490 sequence_id == background_page_data_[extension_id].close_sequence_id) {
490 host->render_view_host()->Send(new ExtensionMsg_Unload(extension_id)); 491 host->render_view_host()->Send(new ExtensionMsg_Unload(extension_id));
491 } 492 }
492 } 493 }
493 494
494 void ExtensionProcessManager::OnUnloadAck(const std::string& extension_id) { 495 void ExtensionProcessManager::OnUnloadAck(const std::string& extension_id) {
496 background_page_data_[extension_id].is_closing = true;
497 int sequence_id = background_page_data_[extension_id].close_sequence_id;
495 MessageLoop::current()->PostDelayedTask( 498 MessageLoop::current()->PostDelayedTask(
496 FROM_HERE, 499 FROM_HERE,
497 base::Bind(&ExtensionProcessManager::CloseLazyBackgroundPageNow, 500 base::Bind(&ExtensionProcessManager::CloseLazyBackgroundPageNow,
498 weak_ptr_factory_.GetWeakPtr(), extension_id), 501 weak_ptr_factory_.GetWeakPtr(), extension_id, sequence_id),
499 event_page_unloading_time_); 502 event_page_unloading_time_);
500 } 503 }
501 504
502 void ExtensionProcessManager::CloseLazyBackgroundPageNow( 505 void ExtensionProcessManager::CloseLazyBackgroundPageNow(
503 const std::string& extension_id) { 506 const std::string& extension_id, int sequence_id) {
504 background_page_data_[extension_id].is_closing = true;
505 ExtensionHost* host = GetBackgroundHostForExtension(extension_id); 507 ExtensionHost* host = GetBackgroundHostForExtension(extension_id);
506 if (host) 508 if (host &&
507 CloseBackgroundHost(host); 509 sequence_id == background_page_data_[extension_id].close_sequence_id) {
benwells 2012/07/19 04:01:21 Any change to sequence_id will cancel the unload.
koz (OOO until 15th September) 2012/07/19 06:52:11 Good point. I've changed it so that only dispatchi
510 ExtensionHost* host = GetBackgroundHostForExtension(extension_id);
511 if (host)
512 CloseBackgroundHost(host);
513 }
508 } 514 }
509 515
510 void ExtensionProcessManager::OnNetworkRequestStarted( 516 void ExtensionProcessManager::OnNetworkRequestStarted(
511 RenderViewHost* render_view_host) { 517 RenderViewHost* render_view_host) {
512 ExtensionHost* host = GetBackgroundHostForExtension( 518 ExtensionHost* host = GetBackgroundHostForExtension(
513 GetExtensionID(render_view_host)); 519 GetExtensionID(render_view_host));
514 if (host && host->render_view_host() == render_view_host) 520 if (host && host->render_view_host() == render_view_host)
515 IncrementLazyKeepaliveCount(host->extension()); 521 IncrementLazyKeepaliveCount(host->extension());
516 } 522 }
517 523
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 if (service && service->is_ready()) 785 if (service && service->is_ready())
780 CreateBackgroundHostsForProfileStartup(this, service->extensions()); 786 CreateBackgroundHostsForProfileStartup(this, service->extensions());
781 } 787 }
782 break; 788 break;
783 } 789 }
784 default: 790 default:
785 ExtensionProcessManager::Observe(type, source, details); 791 ExtensionProcessManager::Observe(type, source, details);
786 break; 792 break;
787 } 793 }
788 } 794 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698