OLD | NEW |
---|---|
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 <list> | 7 #include <list> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/metrics/field_trial.h" | 14 #include "base/metrics/field_trial.h" |
15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram_macros.h" |
16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
18 #include "content/public/browser/browser_context.h" | 18 #include "content/public/browser/browser_context.h" |
19 #include "content/public/browser/content_browser_client.h" | 19 #include "content/public/browser/content_browser_client.h" |
20 #include "content/public/browser/native_web_keyboard_event.h" | 20 #include "content/public/browser/native_web_keyboard_event.h" |
21 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
22 #include "content/public/browser/notification_source.h" | 22 #include "content/public/browser/notification_source.h" |
23 #include "content/public/browser/notification_types.h" | 23 #include "content/public/browser/notification_types.h" |
24 #include "content/public/browser/render_process_host.h" | 24 #include "content/public/browser/render_process_host.h" |
25 #include "content/public/browser/render_view_host.h" | 25 #include "content/public/browser/render_view_host.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 registrar_.Add(this, | 145 registrar_.Add(this, |
146 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, | 146 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, |
147 content::Source<BrowserContext>(browser_context_)); | 147 content::Source<BrowserContext>(browser_context_)); |
148 | 148 |
149 // Set up web contents observers and pref observers. | 149 // Set up web contents observers and pref observers. |
150 delegate_->OnExtensionHostCreated(host_contents()); | 150 delegate_->OnExtensionHostCreated(host_contents()); |
151 } | 151 } |
152 | 152 |
153 ExtensionHost::~ExtensionHost() { | 153 ExtensionHost::~ExtensionHost() { |
154 if (extension_host_type_ == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE && | 154 if (extension_host_type_ == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE && |
155 extension_ && BackgroundInfo::HasLazyBackgroundPage(extension_)) { | 155 extension_ && BackgroundInfo::HasLazyBackgroundPage(extension_) && |
156 since_created_.get()) { | |
156 UMA_HISTOGRAM_LONG_TIMES("Extensions.EventPageActiveTime", | 157 UMA_HISTOGRAM_LONG_TIMES("Extensions.EventPageActiveTime", |
157 since_created_.Elapsed()); | 158 since_created_->Elapsed()); |
158 } | 159 } |
159 content::NotificationService::current()->Notify( | 160 content::NotificationService::current()->Notify( |
160 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 161 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
161 content::Source<BrowserContext>(browser_context_), | 162 content::Source<BrowserContext>(browser_context_), |
162 content::Details<ExtensionHost>(this)); | 163 content::Details<ExtensionHost>(this)); |
163 FOR_EACH_OBSERVER(ExtensionHostObserver, observer_list_, | 164 FOR_EACH_OBSERVER(ExtensionHostObserver, observer_list_, |
164 OnExtensionHostDestroyed(this)); | 165 OnExtensionHostDestroyed(this)); |
165 ProcessCreationQueue::GetInstance()->Remove(this); | 166 ProcessCreationQueue::GetInstance()->Remove(this); |
166 } | 167 } |
167 | 168 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
231 void ExtensionHost::OnNetworkRequestDone(uint64 request_id) { | 232 void ExtensionHost::OnNetworkRequestDone(uint64 request_id) { |
232 FOR_EACH_OBSERVER(ExtensionHostObserver, observer_list_, | 233 FOR_EACH_OBSERVER(ExtensionHostObserver, observer_list_, |
233 OnNetworkRequestDone(this, request_id)); | 234 OnNetworkRequestDone(this, request_id)); |
234 } | 235 } |
235 | 236 |
236 const GURL& ExtensionHost::GetURL() const { | 237 const GURL& ExtensionHost::GetURL() const { |
237 return host_contents()->GetURL(); | 238 return host_contents()->GetURL(); |
238 } | 239 } |
239 | 240 |
240 void ExtensionHost::LoadInitialURL() { | 241 void ExtensionHost::LoadInitialURL() { |
242 since_created_.reset(new base::ElapsedTimer()); | |
241 host_contents_->GetController().LoadURL( | 243 host_contents_->GetController().LoadURL( |
242 initial_url_, content::Referrer(), ui::PAGE_TRANSITION_LINK, | 244 initial_url_, content::Referrer(), ui::PAGE_TRANSITION_LINK, |
243 std::string()); | 245 std::string()); |
244 } | 246 } |
245 | 247 |
246 bool ExtensionHost::IsBackgroundPage() const { | 248 bool ExtensionHost::IsBackgroundPage() const { |
247 DCHECK(extension_host_type_ == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); | 249 DCHECK(extension_host_type_ == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); |
248 return true; | 250 return true; |
249 } | 251 } |
250 | 252 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
299 extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, | 301 extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, |
300 content::Source<BrowserContext>(browser_context_), | 302 content::Source<BrowserContext>(browser_context_), |
301 content::Details<ExtensionHost>(this)); | 303 content::Details<ExtensionHost>(this)); |
302 } | 304 } |
303 | 305 |
304 void ExtensionHost::DidStopLoading(content::RenderViewHost* render_view_host) { | 306 void ExtensionHost::DidStopLoading(content::RenderViewHost* render_view_host) { |
305 bool notify = !did_stop_loading_; | 307 bool notify = !did_stop_loading_; |
306 did_stop_loading_ = true; | 308 did_stop_loading_ = true; |
307 OnDidStopLoading(); | 309 OnDidStopLoading(); |
308 if (notify) { | 310 if (notify) { |
311 CHECK(since_created_.get()); | |
309 if (extension_host_type_ == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { | 312 if (extension_host_type_ == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { |
310 if (extension_ && BackgroundInfo::HasLazyBackgroundPage(extension_)) { | 313 if (extension_ && BackgroundInfo::HasLazyBackgroundPage(extension_)) { |
311 UMA_HISTOGRAM_TIMES("Extensions.EventPageLoadTime", | 314 UMA_HISTOGRAM_MEDIUM_TIMES("Extensions.EventPageLoadTime", |
Yoyo Zhou
2015/02/06 01:59:12
I think this is the right change, even though on m
| |
312 since_created_.Elapsed()); | 315 since_created_->Elapsed()); |
313 } else { | 316 } else { |
314 UMA_HISTOGRAM_TIMES("Extensions.BackgroundPageLoadTime", | 317 UMA_HISTOGRAM_MEDIUM_TIMES("Extensions.BackgroundPageLoadTime", |
315 since_created_.Elapsed()); | 318 since_created_->Elapsed()); |
Ilya Sherman
2015/02/06 02:56:13
If you change what macro is used -- really, if you
| |
316 } | 319 } |
317 } else if (extension_host_type_ == VIEW_TYPE_EXTENSION_DIALOG) { | 320 } else if (extension_host_type_ == VIEW_TYPE_EXTENSION_DIALOG) { |
318 UMA_HISTOGRAM_TIMES("Extensions.DialogLoadTime", | 321 UMA_HISTOGRAM_TIMES("Extensions.DialogLoadTime", |
319 since_created_.Elapsed()); | 322 since_created_->Elapsed()); |
320 } else if (extension_host_type_ == VIEW_TYPE_EXTENSION_POPUP) { | 323 } else if (extension_host_type_ == VIEW_TYPE_EXTENSION_POPUP) { |
321 UMA_HISTOGRAM_TIMES("Extensions.PopupLoadTime", | 324 UMA_HISTOGRAM_TIMES("Extensions.PopupLoadTime", |
322 since_created_.Elapsed()); | 325 since_created_->Elapsed()); |
323 } else if (extension_host_type_ == VIEW_TYPE_EXTENSION_INFOBAR) { | 326 } else if (extension_host_type_ == VIEW_TYPE_EXTENSION_INFOBAR) { |
324 UMA_HISTOGRAM_TIMES("Extensions.InfobarLoadTime", | 327 UMA_HISTOGRAM_TIMES("Extensions.InfobarLoadTime", |
325 since_created_.Elapsed()); | 328 since_created_->Elapsed()); |
326 } | 329 } |
327 | 330 |
328 // Send the notification last, because it might result in this being | 331 // Send the notification last, because it might result in this being |
329 // deleted. | 332 // deleted. |
330 content::NotificationService::current()->Notify( | 333 content::NotificationService::current()->Notify( |
331 extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, | 334 extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, |
332 content::Source<BrowserContext>(browser_context_), | 335 content::Source<BrowserContext>(browser_context_), |
333 content::Details<ExtensionHost>(this)); | 336 content::Details<ExtensionHost>(this)); |
334 } | 337 } |
335 } | 338 } |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
486 return delegate_->CheckMediaAccessPermission( | 489 return delegate_->CheckMediaAccessPermission( |
487 web_contents, security_origin, type, extension()); | 490 web_contents, security_origin, type, extension()); |
488 } | 491 } |
489 | 492 |
490 bool ExtensionHost::IsNeverVisible(content::WebContents* web_contents) { | 493 bool ExtensionHost::IsNeverVisible(content::WebContents* web_contents) { |
491 ViewType view_type = extensions::GetViewType(web_contents); | 494 ViewType view_type = extensions::GetViewType(web_contents); |
492 return view_type == extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE; | 495 return view_type == extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE; |
493 } | 496 } |
494 | 497 |
495 } // namespace extensions | 498 } // namespace extensions |
OLD | NEW |