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

Side by Side 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: Add test, remove log 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 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 "extensions/browser/extension_host.h" 5 #include "extensions/browser/extension_host.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/metrics/field_trial.h" 8 #include "base/metrics/field_trial.h"
9 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "base/profiler/scoped_tracker.h" 10 #include "base/profiler/scoped_tracker.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 } 94 }
95 content::NotificationService::current()->Notify( 95 content::NotificationService::current()->Notify(
96 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, 96 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED,
97 content::Source<BrowserContext>(browser_context_), 97 content::Source<BrowserContext>(browser_context_),
98 content::Details<ExtensionHost>(this)); 98 content::Details<ExtensionHost>(this));
99 FOR_EACH_OBSERVER(ExtensionHostObserver, observer_list_, 99 FOR_EACH_OBSERVER(ExtensionHostObserver, observer_list_,
100 OnExtensionHostDestroyed(this)); 100 OnExtensionHostDestroyed(this));
101 FOR_EACH_OBSERVER(DeferredStartRenderHostObserver, 101 FOR_EACH_OBSERVER(DeferredStartRenderHostObserver,
102 deferred_start_render_host_observer_list_, 102 deferred_start_render_host_observer_list_,
103 OnDeferredStartRenderHostDestroyed(this)); 103 OnDeferredStartRenderHostDestroyed(this));
104
105 // Call DidStopLoading if we haven't already, because we're about to prevent
106 // it being called.
107 if (!did_stop_loading_)
108 DidStopLoading(render_view_host());
109
110 // Remove ourselves from the queue as late as possible (before effectively
111 // destroying self, but after everything else) so that queues that are
112 // monitoring lifetime get a chance to see stop-loading events.
104 delegate_->GetExtensionHostQueue()->Remove(this); 113 delegate_->GetExtensionHostQueue()->Remove(this);
105 // Immediately stop observing |host_contents_| because its destruction events 114
106 // (like DidStopLoading, it turns out) can call back into ExtensionHost 115 // Deliberately stop observing |host_contents_| because its destruction
107 // re-entrantly, when anything declared after |host_contents_| has already 116 // events (like DidStopLoading, it turns out) can call back into
108 // been destroyed. 117 // ExtensionHost re-entrantly, when anything declared after |host_contents_|
118 // has already been destroyed.
109 content::WebContentsObserver::Observe(nullptr); 119 content::WebContentsObserver::Observe(nullptr);
110 } 120 }
111 121
112 content::RenderProcessHost* ExtensionHost::render_process_host() const { 122 content::RenderProcessHost* ExtensionHost::render_process_host() const {
113 return render_view_host()->GetProcess(); 123 return render_view_host()->GetProcess();
114 } 124 }
115 125
116 RenderViewHost* ExtensionHost::render_view_host() const { 126 RenderViewHost* ExtensionHost::render_view_host() const {
117 // TODO(mpcomplete): This can be null. How do we handle that? 127 // TODO(mpcomplete): This can be null. How do we handle that?
118 return render_view_host_; 128 return render_view_host_;
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 content::Details<ExtensionHost>(this)); 271 content::Details<ExtensionHost>(this));
262 } 272 }
263 273
264 void ExtensionHost::DidStartLoading(content::RenderViewHost* render_view_host) { 274 void ExtensionHost::DidStartLoading(content::RenderViewHost* render_view_host) {
265 FOR_EACH_OBSERVER(DeferredStartRenderHostObserver, 275 FOR_EACH_OBSERVER(DeferredStartRenderHostObserver,
266 deferred_start_render_host_observer_list_, 276 deferred_start_render_host_observer_list_,
267 OnDeferredStartRenderHostDidStartLoading(this)); 277 OnDeferredStartRenderHostDidStartLoading(this));
268 } 278 }
269 279
270 void ExtensionHost::DidStopLoading(content::RenderViewHost* render_view_host) { 280 void ExtensionHost::DidStopLoading(content::RenderViewHost* render_view_host) {
271 bool notify = !did_stop_loading_; 281 CHECK(!did_stop_loading_);
Yoyo Zhou 2015/03/10 22:48:13 I think this is wrong. Say the background page nav
not at google - send to devlin 2015/03/12 22:46:51 Yeap, hopefully that explains the epic set of cras
272 did_stop_loading_ = true; 282 did_stop_loading_ = true;
283
273 OnDidStopLoading(); 284 OnDidStopLoading();
274 if (notify) { 285 CHECK(load_start_.get());
275 CHECK(load_start_.get()); 286 if (extension_host_type_ == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) {
276 if (extension_host_type_ == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { 287 if (extension_ && BackgroundInfo::HasLazyBackgroundPage(extension_)) {
277 if (extension_ && BackgroundInfo::HasLazyBackgroundPage(extension_)) { 288 UMA_HISTOGRAM_MEDIUM_TIMES("Extensions.EventPageLoadTime2",
278 UMA_HISTOGRAM_MEDIUM_TIMES("Extensions.EventPageLoadTime2", 289 load_start_->Elapsed());
279 load_start_->Elapsed()); 290 } else {
280 } else { 291 UMA_HISTOGRAM_MEDIUM_TIMES("Extensions.BackgroundPageLoadTime2",
281 UMA_HISTOGRAM_MEDIUM_TIMES("Extensions.BackgroundPageLoadTime2",
282 load_start_->Elapsed());
283 }
284 } else if (extension_host_type_ == VIEW_TYPE_EXTENSION_POPUP) {
285 UMA_HISTOGRAM_MEDIUM_TIMES("Extensions.PopupLoadTime2",
286 load_start_->Elapsed()); 292 load_start_->Elapsed());
287 } 293 }
288 content::NotificationService::current()->Notify( 294 } else if (extension_host_type_ == VIEW_TYPE_EXTENSION_POPUP) {
289 extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, 295 UMA_HISTOGRAM_MEDIUM_TIMES("Extensions.PopupLoadTime2",
290 content::Source<BrowserContext>(browser_context_), 296 load_start_->Elapsed());
291 content::Details<ExtensionHost>(this));
292 FOR_EACH_OBSERVER(DeferredStartRenderHostObserver,
293 deferred_start_render_host_observer_list_,
294 OnDeferredStartRenderHostDidStopLoading(this));
295 } 297 }
298
299 content::NotificationService::current()->Notify(
300 extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING,
301 content::Source<BrowserContext>(browser_context_),
302 content::Details<ExtensionHost>(this));
303 FOR_EACH_OBSERVER(DeferredStartRenderHostObserver,
304 deferred_start_render_host_observer_list_,
305 OnDeferredStartRenderHostDidStopLoading(this));
296 } 306 }
297 307
298 void ExtensionHost::OnDidStopLoading() { 308 void ExtensionHost::OnDidStopLoading() {
299 DCHECK(extension_host_type_ == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); 309 DCHECK(extension_host_type_ == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE);
300 // Nothing to do for background pages. 310 // Nothing to do for background pages.
301 } 311 }
302 312
303 void ExtensionHost::DocumentAvailableInMainFrame() { 313 void ExtensionHost::DocumentAvailableInMainFrame() {
304 // If the document has already been marked as available for this host, then 314 // If the document has already been marked as available for this host, then
305 // bail. No need for the redundant setup. http://crbug.com/31170 315 // bail. No need for the redundant setup. http://crbug.com/31170
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 return delegate_->CheckMediaAccessPermission( 465 return delegate_->CheckMediaAccessPermission(
456 web_contents, security_origin, type, extension()); 466 web_contents, security_origin, type, extension());
457 } 467 }
458 468
459 bool ExtensionHost::IsNeverVisible(content::WebContents* web_contents) { 469 bool ExtensionHost::IsNeverVisible(content::WebContents* web_contents) {
460 ViewType view_type = extensions::GetViewType(web_contents); 470 ViewType view_type = extensions::GetViewType(web_contents);
461 return view_type == extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE; 471 return view_type == extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE;
462 } 472 }
463 473
464 } // namespace extensions 474 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698