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
3 // found in the LICENSE file.
5 #include "extensions/renderer/scripts_run_info.h"
7 #include "base/metrics/histogram.h"
8 #include "content/public/renderer/render_view.h"
9 #include "extensions/common/extension_messages.h"
10 #include "extensions/renderer/script_context.h"
11 #include "third_party/WebKit/public/web/WebFrame.h"
13 namespace extensions
{
15 ScriptsRunInfo::ScriptsRunInfo()
16 : num_css(0u), num_js(0u), num_blocking_js(0u) {
19 ScriptsRunInfo::~ScriptsRunInfo() {
22 void ScriptsRunInfo::LogRun(blink::WebFrame
* frame
,
23 UserScript::RunLocation location
) {
24 // Notify the browser if any extensions are now executing scripts.
25 if (!executing_scripts
.empty()) {
26 content::RenderView
* render_view
=
27 content::RenderView::FromWebView(frame
->view());
28 render_view
->Send(new ExtensionHostMsg_ContentScriptsExecuting(
29 render_view
->GetRoutingID(),
31 ScriptContext::GetDataSourceURLForFrame(frame
)));
35 case UserScript::DOCUMENT_START
:
36 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectStart_CssCount", num_css
);
37 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectStart_ScriptCount", num_js
);
38 if (num_blocking_js
) {
39 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectStart_BlockingScriptCount",
41 } else if (num_css
|| num_js
) {
42 UMA_HISTOGRAM_TIMES("Extensions.InjectStart_Time", timer
.Elapsed());
45 case UserScript::DOCUMENT_END
:
46 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectEnd_ScriptCount", num_js
);
47 if (num_blocking_js
) {
48 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectEnd_BlockingScriptCount",
51 UMA_HISTOGRAM_TIMES("Extensions.InjectEnd_Time", timer
.Elapsed());
54 case UserScript::DOCUMENT_IDLE
:
55 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectIdle_ScriptCount", num_js
);
56 if (num_blocking_js
) {
57 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectIdle_BlockingScriptCount",
60 UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer
.Elapsed());
63 case UserScript::RUN_DEFERRED
:
64 case UserScript::BROWSER_DRIVEN
:
65 // TODO(rdevlin.cronin): Add histograms.
67 case UserScript::UNDEFINED
:
68 case UserScript::RUN_LOCATION_LAST
:
73 } // namespace extensions