| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/html_viewer/stats_collection_controller.h" | 5 #include "components/html_viewer/stats_collection_controller.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/metrics/statistics_recorder.h" | 12 #include "base/metrics/statistics_recorder.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "components/startup_metric_utils/browser/startup_metric_utils.h" | 14 #include "components/startup_metric_utils/browser/startup_metric_utils.h" |
| 15 #include "gin/handle.h" | 15 #include "gin/handle.h" |
| 16 #include "gin/object_template_builder.h" | 16 #include "gin/object_template_builder.h" |
| 17 #include "mojo/services/tracing/public/cpp/switches.h" | 17 #include "mojo/services/tracing/public/cpp/switches.h" |
| 18 #include "mojo/shell/public/cpp/application_impl.h" | 18 #include "mojo/shell/public/cpp/shell.h" |
| 19 #include "third_party/WebKit/public/web/WebKit.h" | 19 #include "third_party/WebKit/public/web/WebKit.h" |
| 20 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 20 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 21 | 21 |
| 22 namespace html_viewer { | 22 namespace html_viewer { |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 // Initialize the histogram data using the given startup performance times. | 26 // Initialize the histogram data using the given startup performance times. |
| 27 void GetStartupPerformanceTimesCallbackImpl( | 27 void GetStartupPerformanceTimesCallbackImpl( |
| 28 tracing::StartupPerformanceTimesPtr times) { | 28 tracing::StartupPerformanceTimesPtr times) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 59 | 59 |
| 60 } // namespace | 60 } // namespace |
| 61 | 61 |
| 62 // static | 62 // static |
| 63 gin::WrapperInfo StatsCollectionController::kWrapperInfo = { | 63 gin::WrapperInfo StatsCollectionController::kWrapperInfo = { |
| 64 gin::kEmbedderNativeGin}; | 64 gin::kEmbedderNativeGin}; |
| 65 | 65 |
| 66 // static | 66 // static |
| 67 tracing::StartupPerformanceDataCollectorPtr StatsCollectionController::Install( | 67 tracing::StartupPerformanceDataCollectorPtr StatsCollectionController::Install( |
| 68 blink::WebFrame* frame, | 68 blink::WebFrame* frame, |
| 69 mojo::ApplicationImpl* app) { | 69 mojo::Shell* shell) { |
| 70 // Only make startup tracing available when running in the context of a test. | 70 // Only make startup tracing available when running in the context of a test. |
| 71 if (!app || | 71 if (!shell || |
| 72 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 72 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 73 tracing::kEnableStatsCollectionBindings)) { | 73 tracing::kEnableStatsCollectionBindings)) { |
| 74 return nullptr; | 74 return nullptr; |
| 75 } | 75 } |
| 76 | 76 |
| 77 v8::Isolate* isolate = blink::mainThreadIsolate(); | 77 v8::Isolate* isolate = blink::mainThreadIsolate(); |
| 78 v8::HandleScope handle_scope(isolate); | 78 v8::HandleScope handle_scope(isolate); |
| 79 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); | 79 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); |
| 80 if (context.IsEmpty()) | 80 if (context.IsEmpty()) |
| 81 return nullptr; | 81 return nullptr; |
| 82 | 82 |
| 83 v8::Context::Scope context_scope(context); | 83 v8::Context::Scope context_scope(context); |
| 84 | 84 |
| 85 scoped_ptr<mojo::ApplicationConnection> connection = | 85 scoped_ptr<mojo::ApplicationConnection> connection = |
| 86 app->ConnectToApplication("mojo:tracing"); | 86 shell->ConnectToApplication("mojo:tracing"); |
| 87 if (!connection) | 87 if (!connection) |
| 88 return nullptr; | 88 return nullptr; |
| 89 tracing::StartupPerformanceDataCollectorPtr collector_for_controller; | 89 tracing::StartupPerformanceDataCollectorPtr collector_for_controller; |
| 90 tracing::StartupPerformanceDataCollectorPtr collector_for_caller; | 90 tracing::StartupPerformanceDataCollectorPtr collector_for_caller; |
| 91 connection->ConnectToService(&collector_for_controller); | 91 connection->ConnectToService(&collector_for_controller); |
| 92 connection->ConnectToService(&collector_for_caller); | 92 connection->ConnectToService(&collector_for_caller); |
| 93 | 93 |
| 94 gin::Handle<StatsCollectionController> controller = gin::CreateHandle( | 94 gin::Handle<StatsCollectionController> controller = gin::CreateHandle( |
| 95 isolate, | 95 isolate, |
| 96 new StatsCollectionController(std::move(collector_for_controller))); | 96 new StatsCollectionController(std::move(collector_for_controller))); |
| 97 DCHECK(!controller.IsEmpty()); | 97 DCHECK(!controller.IsEmpty()); |
| 98 v8::Local<v8::Object> global = context->Global(); | 98 v8::Local<v8::Object> global = context->Global(); |
| 99 global->Set(gin::StringToV8(isolate, "statsCollectionController"), | 99 global->Set(gin::StringToV8(isolate, "statsCollectionController"), |
| 100 controller.ToV8()); | 100 controller.ToV8()); |
| 101 return collector_for_caller; | 101 return collector_for_caller; |
| 102 } | 102 } |
| 103 | 103 |
| 104 // static | 104 // static |
| 105 tracing::StartupPerformanceDataCollectorPtr | 105 tracing::StartupPerformanceDataCollectorPtr |
| 106 StatsCollectionController::ConnectToDataCollector(mojo::ApplicationImpl* app) { | 106 StatsCollectionController::ConnectToDataCollector(mojo::Shell* shell) { |
| 107 // Only make startup tracing available when running in the context of a test. | 107 // Only make startup tracing available when running in the context of a test. |
| 108 if (!app || | 108 if (!shell || |
| 109 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 109 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 110 tracing::kEnableStatsCollectionBindings)) { | 110 tracing::kEnableStatsCollectionBindings)) { |
| 111 return nullptr; | 111 return nullptr; |
| 112 } | 112 } |
| 113 | 113 |
| 114 tracing::StartupPerformanceDataCollectorPtr collector; | 114 tracing::StartupPerformanceDataCollectorPtr collector; |
| 115 app->ConnectToService("mojo:tracing", &collector); | 115 shell->ConnectToService("mojo:tracing", &collector); |
| 116 return collector; | 116 return collector; |
| 117 } | 117 } |
| 118 | 118 |
| 119 StatsCollectionController::StatsCollectionController( | 119 StatsCollectionController::StatsCollectionController( |
| 120 tracing::StartupPerformanceDataCollectorPtr collector) | 120 tracing::StartupPerformanceDataCollectorPtr collector) |
| 121 : startup_performance_data_collector_(std::move(collector)) {} | 121 : startup_performance_data_collector_(std::move(collector)) {} |
| 122 | 122 |
| 123 StatsCollectionController::~StatsCollectionController() {} | 123 StatsCollectionController::~StatsCollectionController() {} |
| 124 | 124 |
| 125 gin::ObjectTemplateBuilder StatsCollectionController::GetObjectTemplateBuilder( | 125 gin::ObjectTemplateBuilder StatsCollectionController::GetObjectTemplateBuilder( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 153 histogram->WriteJSON(&histogram_json); | 153 histogram->WriteJSON(&histogram_json); |
| 154 return histogram_json; | 154 return histogram_json; |
| 155 } | 155 } |
| 156 | 156 |
| 157 std::string StatsCollectionController::GetBrowserHistogram( | 157 std::string StatsCollectionController::GetBrowserHistogram( |
| 158 const std::string& histogram_name) { | 158 const std::string& histogram_name) { |
| 159 return GetHistogram(histogram_name); | 159 return GetHistogram(histogram_name); |
| 160 } | 160 } |
| 161 | 161 |
| 162 } // namespace html_viewer | 162 } // namespace html_viewer |
| OLD | NEW |