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

Unified Diff: extensions/browser/extension_host.cc

Issue 995983002: Make LoadMonitoringExtensionHostQueue remove itself as an ExtensionHost observer at the correct tim… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: aha Created 5 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 side-by-side diff with in-line comments
Download patch
Index: extensions/browser/extension_host.cc
diff --git a/extensions/browser/extension_host.cc b/extensions/browser/extension_host.cc
index bbf51ef4913b41b8d784b07c8eae28e7ed6eebad..350eece2c97a3dfa724b92a6b04096ecbb35d650 100644
--- a/extensions/browser/extension_host.cc
+++ b/extensions/browser/extension_host.cc
@@ -58,7 +58,8 @@ ExtensionHost::ExtensionHost(const Extension* extension,
extension_id_(extension->id()),
browser_context_(site_instance->GetBrowserContext()),
render_view_host_(nullptr),
- did_stop_loading_(false),
+ is_loading_(false),
+ has_loaded_once_(false),
document_element_available_(false),
initial_url_(url),
extension_function_dispatcher_(browser_context_, this),
@@ -92,6 +93,11 @@ ExtensionHost::~ExtensionHost() {
UMA_HISTOGRAM_LONG_TIMES("Extensions.EventPageActiveTime2",
load_start_->Elapsed());
}
+
+ // Record UMA now because we're about to stop observing our WebContents.
Yoyo Zhou 2015/03/12 22:57:29 We'll be recording incomplete loads? Hope that's o
not at google - send to devlin 2015/03/12 23:29:22 Yeah I couldn't decide whether or not this was a g
+ if (is_loading_)
+ RecordStopLoadingUMA();
+
content::NotificationService::current()->Notify(
extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED,
content::Source<BrowserContext>(browser_context_),
@@ -101,11 +107,16 @@ ExtensionHost::~ExtensionHost() {
FOR_EACH_OBSERVER(DeferredStartRenderHostObserver,
deferred_start_render_host_observer_list_,
OnDeferredStartRenderHostDestroyed(this));
+
+ // Remove ourselves from the queue as late as possible (before effectively
+ // destroying self, but after everything else) so that queues that are
+ // monitoring lifetime get a chance to see stop-loading events.
delegate_->GetExtensionHostQueue()->Remove(this);
- // Immediately stop observing |host_contents_| because its destruction events
- // (like DidStopLoading, it turns out) can call back into ExtensionHost
- // re-entrantly, when anything declared after |host_contents_| has already
- // been destroyed.
+
+ // Deliberately stop observing |host_contents_| because its destruction
+ // events (like DidStopLoading, it turns out) can call back into
+ // ExtensionHost re-entrantly, when anything declared after |host_contents_|
+ // has already been destroyed.
content::WebContentsObserver::Observe(nullptr);
}
@@ -219,7 +230,7 @@ void ExtensionHost::LoadInitialURL() {
}
bool ExtensionHost::IsBackgroundPage() const {
- DCHECK(extension_host_type_ == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE);
+ DCHECK_EQ(extension_host_type_, VIEW_TYPE_EXTENSION_BACKGROUND_PAGE);
return true;
}
@@ -262,41 +273,29 @@ void ExtensionHost::RenderProcessGone(base::TerminationStatus status) {
}
void ExtensionHost::DidStartLoading(content::RenderViewHost* render_view_host) {
+ CHECK(!is_loading_);
+ is_loading_ = true;
FOR_EACH_OBSERVER(DeferredStartRenderHostObserver,
deferred_start_render_host_observer_list_,
OnDeferredStartRenderHostDidStartLoading(this));
}
void ExtensionHost::DidStopLoading(content::RenderViewHost* render_view_host) {
- bool notify = !did_stop_loading_;
- did_stop_loading_ = true;
- OnDidStopLoading();
- if (notify) {
- CHECK(load_start_.get());
- if (extension_host_type_ == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) {
- if (extension_ && BackgroundInfo::HasLazyBackgroundPage(extension_)) {
- UMA_HISTOGRAM_MEDIUM_TIMES("Extensions.EventPageLoadTime2",
- load_start_->Elapsed());
- } else {
- UMA_HISTOGRAM_MEDIUM_TIMES("Extensions.BackgroundPageLoadTime2",
- load_start_->Elapsed());
- }
- } else if (extension_host_type_ == VIEW_TYPE_EXTENSION_POPUP) {
- UMA_HISTOGRAM_MEDIUM_TIMES("Extensions.PopupLoadTime2",
- load_start_->Elapsed());
- }
- content::NotificationService::current()->Notify(
- extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING,
- content::Source<BrowserContext>(browser_context_),
- content::Details<ExtensionHost>(this));
- FOR_EACH_OBSERVER(DeferredStartRenderHostObserver,
- deferred_start_render_host_observer_list_,
- OnDeferredStartRenderHostDidStopLoading(this));
- }
+ CHECK(is_loading_);
+ is_loading_ = false;
+ has_loaded_once_ = true;
+ RecordStopLoadingUMA();
+ content::NotificationService::current()->Notify(
+ extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING,
+ content::Source<BrowserContext>(browser_context_),
+ content::Details<ExtensionHost>(this));
+ FOR_EACH_OBSERVER(DeferredStartRenderHostObserver,
+ deferred_start_render_host_observer_list_,
+ OnDeferredStartRenderHostDidStopLoading(this));
}
void ExtensionHost::OnDidStopLoading() {
- DCHECK(extension_host_type_ == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE);
+ DCHECK_EQ(extension_host_type_, VIEW_TYPE_EXTENSION_BACKGROUND_PAGE);
// Nothing to do for background pages.
}
@@ -461,4 +460,20 @@ bool ExtensionHost::IsNeverVisible(content::WebContents* web_contents) {
return view_type == extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE;
}
+void ExtensionHost::RecordStopLoadingUMA() {
+ CHECK(load_start_.get());
+ if (extension_host_type_ == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) {
+ if (extension_ && BackgroundInfo::HasLazyBackgroundPage(extension_)) {
+ UMA_HISTOGRAM_MEDIUM_TIMES("Extensions.EventPageLoadTime2",
+ load_start_->Elapsed());
+ } else {
+ UMA_HISTOGRAM_MEDIUM_TIMES("Extensions.BackgroundPageLoadTime2",
+ load_start_->Elapsed());
+ }
+ } else if (extension_host_type_ == VIEW_TYPE_EXTENSION_POPUP) {
+ UMA_HISTOGRAM_MEDIUM_TIMES("Extensions.PopupLoadTime2",
+ load_start_->Elapsed());
+ }
+}
+
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698