1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "extensions/renderer/scripts_run_info.h"
#include "base/metrics/histogram.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_thread.h"
#include "extensions/common/extension_messages.h"
#include "extensions/renderer/script_context.h"
#include "third_party/WebKit/public/web/WebLocalFrame.h"
namespace extensions {
ScriptsRunInfo::ScriptsRunInfo(content::RenderFrame* render_frame,
UserScript::RunLocation location)
: num_css(0u),
num_js(0u),
num_blocking_js(0u),
routing_id_(render_frame->GetRoutingID()),
run_location_(location),
frame_url_(ScriptContext::GetDataSourceURLForFrame(
render_frame->GetWebFrame())) {
}
ScriptsRunInfo::~ScriptsRunInfo() {
}
void ScriptsRunInfo::LogRun() {
// Notify the browser if any extensions are now executing scripts.
if (!executing_scripts.empty()) {
content::RenderThread::Get()->Send(
new ExtensionHostMsg_ContentScriptsExecuting(
routing_id_, executing_scripts, frame_url_));
}
switch (run_location_) {
case UserScript::DOCUMENT_START:
UMA_HISTOGRAM_COUNTS_100("Extensions.InjectStart_CssCount", num_css);
UMA_HISTOGRAM_COUNTS_100("Extensions.InjectStart_ScriptCount", num_js);
if (num_blocking_js) {
UMA_HISTOGRAM_COUNTS_100("Extensions.InjectStart_BlockingScriptCount",
num_blocking_js);
} else if (num_css || num_js) {
UMA_HISTOGRAM_TIMES("Extensions.InjectStart_Time", timer.Elapsed());
}
break;
case UserScript::DOCUMENT_END:
UMA_HISTOGRAM_COUNTS_100("Extensions.InjectEnd_ScriptCount", num_js);
if (num_blocking_js) {
UMA_HISTOGRAM_COUNTS_100("Extensions.InjectEnd_BlockingScriptCount",
num_blocking_js);
} else if (num_js) {
UMA_HISTOGRAM_TIMES("Extensions.InjectEnd_Time", timer.Elapsed());
}
break;
case UserScript::DOCUMENT_IDLE:
UMA_HISTOGRAM_COUNTS_100("Extensions.InjectIdle_ScriptCount", num_js);
if (num_blocking_js) {
UMA_HISTOGRAM_COUNTS_100("Extensions.InjectIdle_BlockingScriptCount",
num_blocking_js);
} else if (num_js) {
UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer.Elapsed());
}
break;
case UserScript::RUN_DEFERRED:
case UserScript::BROWSER_DRIVEN:
// TODO(rdevlin.cronin): Add histograms.
break;
case UserScript::UNDEFINED:
case UserScript::RUN_LOCATION_LAST:
NOTREACHED();
}
}
} // namespace extensions
|