[email protected] | c11e659 | 2014-06-27 17:07:34 | [diff] [blame] | 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. |
| 4 | |
| 5 | #include "extensions/renderer/scripts_run_info.h" |
| 6 | |
asvitkine | f5d4ee56 | 2016-11-07 18:57:08 | [diff] [blame] | 7 | #include "base/metrics/histogram_macros.h" |
rdevlin.cronin | 45dca7f | 2015-06-08 19:47:03 | [diff] [blame] | 8 | #include "content/public/renderer/render_frame.h" |
rdevlin.cronin | 3ae4a3201 | 2015-06-30 17:43:19 | [diff] [blame] | 9 | #include "content/public/renderer/render_thread.h" |
[email protected] | c11e659 | 2014-06-27 17:07:34 | [diff] [blame] | 10 | #include "extensions/common/extension_messages.h" |
| 11 | #include "extensions/renderer/script_context.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 12 | #include "third_party/blink/public/web/web_local_frame.h" |
[email protected] | c11e659 | 2014-06-27 17:07:34 | [diff] [blame] | 13 | |
| 14 | namespace extensions { |
| 15 | |
rdevlin.cronin | 3ae4a3201 | 2015-06-30 17:43:19 | [diff] [blame] | 16 | ScriptsRunInfo::ScriptsRunInfo(content::RenderFrame* render_frame, |
| 17 | UserScript::RunLocation location) |
| 18 | : num_css(0u), |
| 19 | num_js(0u), |
| 20 | num_blocking_js(0u), |
| 21 | routing_id_(render_frame->GetRoutingID()), |
| 22 | run_location_(location), |
Takeshi Yoshino | 41b671a | 2017-08-01 12:17:51 | [diff] [blame] | 23 | frame_url_(ScriptContext::GetDocumentLoaderURLForFrame( |
| 24 | render_frame->GetWebFrame())) {} |
[email protected] | c11e659 | 2014-06-27 17:07:34 | [diff] [blame] | 25 | |
| 26 | ScriptsRunInfo::~ScriptsRunInfo() { |
| 27 | } |
| 28 | |
rdevlin.cronin | 6fba7ec | 2016-06-24 16:15:05 | [diff] [blame] | 29 | void ScriptsRunInfo::LogRun(bool send_script_activity) { |
[email protected] | c11e659 | 2014-06-27 17:07:34 | [diff] [blame] | 30 | // Notify the browser if any extensions are now executing scripts. |
rdevlin.cronin | 6fba7ec | 2016-06-24 16:15:05 | [diff] [blame] | 31 | if (!executing_scripts.empty() && send_script_activity) { |
rdevlin.cronin | 3ae4a3201 | 2015-06-30 17:43:19 | [diff] [blame] | 32 | content::RenderThread::Get()->Send( |
| 33 | new ExtensionHostMsg_ContentScriptsExecuting( |
| 34 | routing_id_, executing_scripts, frame_url_)); |
[email protected] | c11e659 | 2014-06-27 17:07:34 | [diff] [blame] | 35 | } |
| 36 | |
Kunihiko Sakamoto | cf8f3b58 | 2017-08-29 02:40:21 | [diff] [blame] | 37 | base::TimeDelta elapsed = timer.Elapsed(); |
| 38 | |
rdevlin.cronin | 3ae4a3201 | 2015-06-30 17:43:19 | [diff] [blame] | 39 | switch (run_location_) { |
[email protected] | c11e659 | 2014-06-27 17:07:34 | [diff] [blame] | 40 | case UserScript::DOCUMENT_START: |
| 41 | UMA_HISTOGRAM_COUNTS_100("Extensions.InjectStart_CssCount", num_css); |
| 42 | UMA_HISTOGRAM_COUNTS_100("Extensions.InjectStart_ScriptCount", num_js); |
kozyatinskiy | c8bc9a58 | 2015-03-06 09:33:41 | [diff] [blame] | 43 | if (num_blocking_js) { |
| 44 | UMA_HISTOGRAM_COUNTS_100("Extensions.InjectStart_BlockingScriptCount", |
| 45 | num_blocking_js); |
| 46 | } else if (num_css || num_js) { |
Kunihiko Sakamoto | cf8f3b58 | 2017-08-29 02:40:21 | [diff] [blame] | 47 | UMA_HISTOGRAM_TIMES("Extensions.InjectStart_Time", elapsed); |
kozyatinskiy | c8bc9a58 | 2015-03-06 09:33:41 | [diff] [blame] | 48 | } |
[email protected] | c11e659 | 2014-06-27 17:07:34 | [diff] [blame] | 49 | break; |
| 50 | case UserScript::DOCUMENT_END: |
| 51 | UMA_HISTOGRAM_COUNTS_100("Extensions.InjectEnd_ScriptCount", num_js); |
kozyatinskiy | c8bc9a58 | 2015-03-06 09:33:41 | [diff] [blame] | 52 | if (num_blocking_js) { |
| 53 | UMA_HISTOGRAM_COUNTS_100("Extensions.InjectEnd_BlockingScriptCount", |
| 54 | num_blocking_js); |
| 55 | } else if (num_js) { |
Kunihiko Sakamoto | cf8f3b58 | 2017-08-29 02:40:21 | [diff] [blame] | 56 | UMA_HISTOGRAM_TIMES("Extensions.InjectEnd_Time", elapsed); |
kozyatinskiy | c8bc9a58 | 2015-03-06 09:33:41 | [diff] [blame] | 57 | } |
[email protected] | c11e659 | 2014-06-27 17:07:34 | [diff] [blame] | 58 | break; |
| 59 | case UserScript::DOCUMENT_IDLE: |
| 60 | UMA_HISTOGRAM_COUNTS_100("Extensions.InjectIdle_ScriptCount", num_js); |
kozyatinskiy | c8bc9a58 | 2015-03-06 09:33:41 | [diff] [blame] | 61 | if (num_blocking_js) { |
| 62 | UMA_HISTOGRAM_COUNTS_100("Extensions.InjectIdle_BlockingScriptCount", |
| 63 | num_blocking_js); |
| 64 | } else if (num_js) { |
Kunihiko Sakamoto | cf8f3b58 | 2017-08-29 02:40:21 | [diff] [blame] | 65 | UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", elapsed); |
kozyatinskiy | c8bc9a58 | 2015-03-06 09:33:41 | [diff] [blame] | 66 | } |
[email protected] | c11e659 | 2014-06-27 17:07:34 | [diff] [blame] | 67 | break; |
| 68 | case UserScript::RUN_DEFERRED: |
markdittmer | 3ac20004 | 2014-08-28 23:43:08 | [diff] [blame] | 69 | case UserScript::BROWSER_DRIVEN: |
[email protected] | c11e659 | 2014-06-27 17:07:34 | [diff] [blame] | 70 | // TODO(rdevlin.cronin): Add histograms. |
| 71 | break; |
| 72 | case UserScript::UNDEFINED: |
| 73 | case UserScript::RUN_LOCATION_LAST: |
| 74 | NOTREACHED(); |
| 75 | } |
| 76 | } |
| 77 | |
[email protected] | c11e659 | 2014-06-27 17:07:34 | [diff] [blame] | 78 | } // namespace extensions |