[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 | |
| 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" |
| 12 | |
| 13 | namespace extensions { |
| 14 | |
| 15 | ScriptsRunInfo::ScriptsRunInfo() : num_css(0u), num_js(0u) { |
| 16 | } |
| 17 | |
| 18 | ScriptsRunInfo::~ScriptsRunInfo() { |
| 19 | } |
| 20 | |
| 21 | void ScriptsRunInfo::LogRun(blink::WebFrame* frame, |
| 22 | UserScript::RunLocation location) { |
| 23 | // Notify the browser if any extensions are now executing scripts. |
| 24 | if (!executing_scripts.empty()) { |
| 25 | content::RenderView* render_view = |
| 26 | content::RenderView::FromWebView(frame->view()); |
| 27 | render_view->Send(new ExtensionHostMsg_ContentScriptsExecuting( |
| 28 | render_view->GetRoutingID(), |
| 29 | executing_scripts, |
[email protected] | c11e659 | 2014-06-27 17:07:34 | [diff] [blame] | 30 | ScriptContext::GetDataSourceURLForFrame(frame))); |
| 31 | } |
| 32 | |
| 33 | switch (location) { |
| 34 | case UserScript::DOCUMENT_START: |
| 35 | UMA_HISTOGRAM_COUNTS_100("Extensions.InjectStart_CssCount", num_css); |
| 36 | UMA_HISTOGRAM_COUNTS_100("Extensions.InjectStart_ScriptCount", num_js); |
| 37 | if (num_css || num_js) |
| 38 | UMA_HISTOGRAM_TIMES("Extensions.InjectStart_Time", timer.Elapsed()); |
| 39 | break; |
| 40 | case UserScript::DOCUMENT_END: |
| 41 | UMA_HISTOGRAM_COUNTS_100("Extensions.InjectEnd_ScriptCount", num_js); |
| 42 | if (num_js) |
| 43 | UMA_HISTOGRAM_TIMES("Extensions.InjectEnd_Time", timer.Elapsed()); |
| 44 | break; |
| 45 | case UserScript::DOCUMENT_IDLE: |
| 46 | UMA_HISTOGRAM_COUNTS_100("Extensions.InjectIdle_ScriptCount", num_js); |
| 47 | if (num_js) |
| 48 | UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer.Elapsed()); |
| 49 | break; |
| 50 | case UserScript::RUN_DEFERRED: |
markdittmer | 3ac20004 | 2014-08-28 23:43:08 | [diff] [blame] | 51 | case UserScript::BROWSER_DRIVEN: |
[email protected] | c11e659 | 2014-06-27 17:07:34 | [diff] [blame] | 52 | // TODO(rdevlin.cronin): Add histograms. |
| 53 | break; |
| 54 | case UserScript::UNDEFINED: |
| 55 | case UserScript::RUN_LOCATION_LAST: |
| 56 | NOTREACHED(); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | } // namespace extensions |