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_frame.h"
9 #include "extensions/common/extension_messages.h"
10 #include "extensions/renderer/script_context.h"
11 #include "third_party/WebKit/public/web/WebLocalFrame.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::WebLocalFrame
* frame
,
23 UserScript::RunLocation location
) {
24 // Notify the browser if any extensions are now executing scripts.
25 if (!executing_scripts
.empty()) {
26 content::RenderFrame
* render_frame
=
27 content::RenderFrame::FromWebFrame(frame
);
28 render_frame
->Send(new ExtensionHostMsg_ContentScriptsExecuting(
29 render_frame
->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