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

Side by Side Diff: chrome/browser/ui/webui/extensions/extensions_ui.cc

Issue 2341553002: [MD Extensions] Add some performance metrics (Closed)
Patch Set: Dan's Created 4 years, 3 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
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/browser/ui/webui/extensions/extensions_ui.h" 5 #include "chrome/browser/ui/webui/extensions/extensions_ui.h"
6 6
7 #include <memory>
8
9 #include "base/metrics/histogram_macros.h"
7 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "base/timer/elapsed_timer.h"
8 #include "build/build_config.h" 12 #include "build/build_config.h"
9 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/webui/extensions/extension_loader_handler.h" 15 #include "chrome/browser/ui/webui/extensions/extension_loader_handler.h"
12 #include "chrome/browser/ui/webui/extensions/extension_settings_handler.h" 16 #include "chrome/browser/ui/webui/extensions/extension_settings_handler.h"
13 #include "chrome/browser/ui/webui/extensions/install_extension_handler.h" 17 #include "chrome/browser/ui/webui/extensions/install_extension_handler.h"
14 #include "chrome/browser/ui/webui/metrics_handler.h" 18 #include "chrome/browser/ui/webui/metrics_handler.h"
15 #include "chrome/common/chrome_features.h" 19 #include "chrome/common/chrome_features.h"
16 #include "chrome/common/url_constants.h" 20 #include "chrome/common/url_constants.h"
17 #include "chrome/grit/browser_resources.h" 21 #include "chrome/grit/browser_resources.h"
18 #include "chrome/grit/chromium_strings.h" 22 #include "chrome/grit/chromium_strings.h"
19 #include "chrome/grit/generated_resources.h" 23 #include "chrome/grit/generated_resources.h"
20 #include "chrome/grit/theme_resources.h" 24 #include "chrome/grit/theme_resources.h"
21 #include "components/google/core/browser/google_util.h" 25 #include "components/google/core/browser/google_util.h"
26 #include "content/public/browser/web_contents.h"
27 #include "content/public/browser/web_contents_observer.h"
22 #include "content/public/browser/web_ui.h" 28 #include "content/public/browser/web_ui.h"
23 #include "content/public/browser/web_ui_data_source.h" 29 #include "content/public/browser/web_ui_data_source.h"
24 #include "extensions/common/extension_urls.h" 30 #include "extensions/common/extension_urls.h"
25 #include "ui/base/l10n/l10n_util.h" 31 #include "ui/base/l10n/l10n_util.h"
26 #include "ui/base/resource/resource_bundle.h" 32 #include "ui/base/resource/resource_bundle.h"
27 33
28 #if defined(OS_CHROMEOS) 34 #if defined(OS_CHROMEOS)
29 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h" 35 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h"
30 #include "chrome/browser/ui/webui/extensions/chromeos/kiosk_apps_handler.h" 36 #include "chrome/browser/ui/webui/extensions/chromeos/kiosk_apps_handler.h"
31 #endif 37 #endif
32 38
33 namespace extensions { 39 namespace extensions {
34 40
35 namespace { 41 namespace {
36 42
43 class ExtensionWebUiTimer : public content::WebContentsObserver {
44 public:
45 explicit ExtensionWebUiTimer(content::WebContents* web_contents, bool is_md)
46 : content::WebContentsObserver(web_contents), is_md_(is_md) {}
47 ~ExtensionWebUiTimer() override {}
48
49 void DidStartProvisionalLoadForFrame(
50 content::RenderFrameHost* render_frame_host,
51 const GURL& validated_url,
52 bool is_error_page,
53 bool is_iframe_srcdoc) override {
54 timer_.reset(new base::ElapsedTimer());
55 }
56
57 void DocumentLoadedInFrame(
Mark P 2016/09/14 19:47:31 side nit: shouldn't you have Main in the function
Devlin 2016/09/14 19:50:09 Nope, this overrides a WebContentsObserver method.
Mark P 2016/09/14 20:02:50 Acknowledged.
58 content::RenderFrameHost* render_frame_host) override {
59 if (render_frame_host != web_contents()->GetMainFrame())
60 return;
61 if (is_md_) {
62 UMA_HISTOGRAM_TIMES("Extensions.WebUi.DocumentLoadedInMainFrameTime.MD",
63 timer_->Elapsed());
64 } else {
65 UMA_HISTOGRAM_TIMES("Extensions.WebUi.DocumentLoadedInMainFrameTime.Uber",
66 timer_->Elapsed());
67 }
68 }
69
70 void DocumentOnLoadCompletedInMainFrame() override {
71 if (is_md_) {
72 UMA_HISTOGRAM_TIMES("Extensions.WebUi.LoadCompletedInMainFrame.MD",
73 timer_->Elapsed());
74 } else {
75 UMA_HISTOGRAM_TIMES("Extensions.WebUi.LoadCompletedInMainFrame.Uber",
76 timer_->Elapsed());
77 }
78 }
79
80 void WebContentsDestroyed() override { delete this; }
81
82 private:
83 // Whether this is the MD version of the chrome://extensions page.
84 bool is_md_;
85
86 std::unique_ptr<base::ElapsedTimer> timer_;
87
88 DISALLOW_COPY_AND_ASSIGN(ExtensionWebUiTimer);
89 };
90
37 content::WebUIDataSource* CreateMdExtensionsSource() { 91 content::WebUIDataSource* CreateMdExtensionsSource() {
38 content::WebUIDataSource* source = 92 content::WebUIDataSource* source =
39 content::WebUIDataSource::Create(chrome::kChromeUIExtensionsHost); 93 content::WebUIDataSource::Create(chrome::kChromeUIExtensionsHost);
40 94
41 source->SetJsonPath("strings.js"); 95 source->SetJsonPath("strings.js");
42 96
43 source->AddLocalizedString("title", 97 source->AddLocalizedString("title",
44 IDS_MANAGE_EXTENSIONS_SETTING_WINDOWS_TITLE); 98 IDS_MANAGE_EXTENSIONS_SETTING_WINDOWS_TITLE);
45 source->AddLocalizedString("toolbarTitle", IDS_MD_EXTENSIONS_TOOLBAR_TITLE); 99 source->AddLocalizedString("toolbarTitle", IDS_MD_EXTENSIONS_TOOLBAR_TITLE);
46 source->AddLocalizedString("search", IDS_MD_EXTENSIONS_SEARCH); 100 source->AddLocalizedString("search", IDS_MD_EXTENSIONS_SEARCH);
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 source->DisableDenyXFrameOptions(); 263 source->DisableDenyXFrameOptions();
210 return source; 264 return source;
211 } 265 }
212 266
213 } // namespace 267 } // namespace
214 268
215 ExtensionsUI::ExtensionsUI(content::WebUI* web_ui) : WebUIController(web_ui) { 269 ExtensionsUI::ExtensionsUI(content::WebUI* web_ui) : WebUIController(web_ui) {
216 Profile* profile = Profile::FromWebUI(web_ui); 270 Profile* profile = Profile::FromWebUI(web_ui);
217 content::WebUIDataSource* source = nullptr; 271 content::WebUIDataSource* source = nullptr;
218 272
219 if (base::FeatureList::IsEnabled(features::kMaterialDesignExtensions)) { 273 bool is_md =
274 base::FeatureList::IsEnabled(features::kMaterialDesignExtensions);
275
276 if (is_md) {
220 source = CreateMdExtensionsSource(); 277 source = CreateMdExtensionsSource();
221 InstallExtensionHandler* install_extension_handler = 278 InstallExtensionHandler* install_extension_handler =
222 new InstallExtensionHandler(); 279 new InstallExtensionHandler();
223 install_extension_handler->GetLocalizedValues(source); 280 install_extension_handler->GetLocalizedValues(source);
224 web_ui->AddMessageHandler(install_extension_handler); 281 web_ui->AddMessageHandler(install_extension_handler);
225 } else { 282 } else {
226 source = CreateExtensionsHTMLSource(); 283 source = CreateExtensionsHTMLSource();
227 284
228 ExtensionSettingsHandler* handler = new ExtensionSettingsHandler(); 285 ExtensionSettingsHandler* handler = new ExtensionSettingsHandler();
229 web_ui->AddMessageHandler(handler); 286 web_ui->AddMessageHandler(handler);
(...skipping 19 matching lines...) Expand all
249 #endif 306 #endif
250 307
251 web_ui->AddMessageHandler(new MetricsHandler()); 308 web_ui->AddMessageHandler(new MetricsHandler());
252 309
253 // Need to allow <object> elements so that the <extensionoptions> browser 310 // Need to allow <object> elements so that the <extensionoptions> browser
254 // plugin can be loaded within chrome://extensions. 311 // plugin can be loaded within chrome://extensions.
255 source->OverrideContentSecurityPolicyObjectSrc("object-src 'self';"); 312 source->OverrideContentSecurityPolicyObjectSrc("object-src 'self';");
256 } 313 }
257 314
258 content::WebUIDataSource::Add(profile, source); 315 content::WebUIDataSource::Add(profile, source);
316 // Handles its own lifetime.
317 new ExtensionWebUiTimer(web_ui->GetWebContents(), is_md);
259 } 318 }
260 319
261 ExtensionsUI::~ExtensionsUI() {} 320 ExtensionsUI::~ExtensionsUI() {}
262 321
263 // static 322 // static
264 base::RefCountedMemory* ExtensionsUI::GetFaviconResourceBytes( 323 base::RefCountedMemory* ExtensionsUI::GetFaviconResourceBytes(
265 ui::ScaleFactor scale_factor) { 324 ui::ScaleFactor scale_factor) {
266 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 325 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
267 return rb.LoadDataResourceBytesForScale(IDR_EXTENSIONS_FAVICON, scale_factor); 326 return rb.LoadDataResourceBytesForScale(IDR_EXTENSIONS_FAVICON, scale_factor);
268 } 327 }
269 328
270 } // namespace extensions 329 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698