summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-13 21:33:25 +0000
committerjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-13 21:33:25 +0000
commita79712f58336183c24820a56159ae665511cb8f3 (patch)
treea5a8e44562d313e3b66813a8e43b83b7bf974f71
parenta2d0f8377cdd83ed844ac243b28ca5b688066587 (diff)
downloadchromium_src-a79712f58336183c24820a56159ae665511cb8f3.zip
chromium_src-a79712f58336183c24820a56159ae665511cb8f3.tar.gz
chromium_src-a79712f58336183c24820a56159ae665511cb8f3.tar.bz2
Move StatsCollectionController from CppBoundClass to gin::Wrappable
BUG=297480 R=aa@chromium.org,abarth@chromium.org Review URL: https://codereview.chromium.org/113933002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@240754 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/content_renderer.gypi1
-rw-r--r--content/renderer/DEPS5
-rw-r--r--content/renderer/render_view_impl.cc10
-rw-r--r--content/renderer/render_view_impl.h5
-rw-r--r--content/renderer/stats_collection_controller.cc111
-rw-r--r--content/renderer/stats_collection_controller.h34
6 files changed, 82 insertions, 84 deletions
diff --git a/content/content_renderer.gypi b/content/content_renderer.gypi
index 3b06a08..d8870cc 100644
--- a/content/content_renderer.gypi
+++ b/content/content_renderer.gypi
@@ -4,6 +4,7 @@
{
'dependencies': [
+ '../gin/gin.gyp:gin',
'../jingle/jingle.gyp:jingle_glue',
'../media/media.gyp:media',
'../net/net.gyp:net',
diff --git a/content/renderer/DEPS b/content/renderer/DEPS
index e0fbea0..10db772 100644
--- a/content/renderer/DEPS
+++ b/content/renderer/DEPS
@@ -1,6 +1,7 @@
include_rules = [
"+content/public/renderer",
"+content/child",
+ "+gin",
"+jingle/glue",
"+media", # For audio input/output and audio/video decoding.
"+third_party/hyphen/hyphen.h",
@@ -17,8 +18,4 @@ specific_include_rules = {
"+content/public/browser",
"+content/shell",
],
- # gin usage in blink is currently experimental. Don't use outside of tests.
- 'gin_browsertest.cc': [
- "+gin",
- ],
}
diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc
index 869bac2..07cad53 100644
--- a/content/renderer/render_view_impl.cc
+++ b/content/renderer/render_view_impl.cc
@@ -3771,14 +3771,8 @@ void RenderViewImpl::didClearWindowObject(WebFrame* frame) {
"domAutomationController");
}
- if (enabled_bindings_ & BINDINGS_POLICY_STATS_COLLECTION) {
- if (!stats_collection_controller_.get())
- stats_collection_controller_.reset(new StatsCollectionController());
- stats_collection_controller_->set_message_sender(
- static_cast<RenderView*>(this));
- stats_collection_controller_->BindToJavascript(frame,
- "statsCollectionController");
- }
+ if (enabled_bindings_ & BINDINGS_POLICY_STATS_COLLECTION)
+ StatsCollectionController::Install(frame);
}
void RenderViewImpl::didCreateDocumentElement(WebFrame* frame) {
diff --git a/content/renderer/render_view_impl.h b/content/renderer/render_view_impl.h
index 37c8ec0..d74c89c 100644
--- a/content/renderer/render_view_impl.h
+++ b/content/renderer/render_view_impl.h
@@ -155,7 +155,6 @@ class RendererAccessibility;
class RendererDateTimePicker;
class RendererWebColorChooserImpl;
class SpeechRecognitionDispatcher;
-class StatsCollectionController;
class WebPluginDelegateProxy;
struct CustomContextMenuContext;
struct DropData;
@@ -1511,10 +1510,6 @@ class CONTENT_EXPORT RenderViewImpl
// DOM automation bindings are enabled.
scoped_ptr<DomAutomationController> dom_automation_controller_;
- // Allows JS to read out a variety of internal various metrics. The JS object
- // is only exposed when the stats collection bindings are enabled.
- scoped_ptr<StatsCollectionController> stats_collection_controller_;
-
// This field stores drag/drop related info for the event that is currently
// being handled. If the current event results in starting a drag/drop
// session, this info is sent to the browser along with other drag/drop info.
diff --git a/content/renderer/stats_collection_controller.cc b/content/renderer/stats_collection_controller.cc
index 93734ab..af86c9e 100644
--- a/content/renderer/stats_collection_controller.cc
+++ b/content/renderer/stats_collection_controller.cc
@@ -4,20 +4,19 @@
#include "content/renderer/stats_collection_controller.h"
-#include "base/bind.h"
-#include "base/bind_helpers.h"
#include "base/json/json_writer.h"
#include "base/metrics/histogram.h"
#include "base/metrics/statistics_recorder.h"
#include "base/strings/string_util.h"
#include "content/common/child_process_messages.h"
#include "content/renderer/render_view_impl.h"
+#include "gin/handle.h"
+#include "gin/object_template_builder.h"
+#include "gin/per_isolate_data.h"
#include "third_party/WebKit/public/web/WebFrame.h"
+#include "third_party/WebKit/public/web/WebKit.h"
#include "third_party/WebKit/public/web/WebView.h"
-using webkit_glue::CppArgumentList;
-using webkit_glue::CppVariant;
-
namespace content {
namespace {
@@ -71,85 +70,93 @@ void ConvertLoadTimeToJSON(
} // namespace
-StatsCollectionController::StatsCollectionController()
- : sender_(NULL) {
- BindCallback("getHistogram",
- base::Bind(&StatsCollectionController::GetHistogram,
- base::Unretained(this)));
- BindCallback("getBrowserHistogram",
- base::Bind(&StatsCollectionController::GetBrowserHistogram,
- base::Unretained(this)));
- BindCallback("tabLoadTiming",
- base::Bind(
- &StatsCollectionController::GetTabLoadTiming,
- base::Unretained(this)));
-}
-
-void StatsCollectionController::GetHistogram(const CppArgumentList& args,
- CppVariant* result) {
- if (args.size() != 1) {
- result->SetNull();
+// static
+gin::WrapperInfo StatsCollectionController::kWrapperInfo = {
+ gin::kEmbedderNativeGin
+};
+
+// static
+void StatsCollectionController::Install(blink::WebFrame* frame) {
+ v8::Isolate* isolate = blink::mainThreadIsolate();
+ v8::HandleScope handle_scope(isolate);
+ v8::Handle<v8::Context> context = frame->mainWorldScriptContext();
+ if (context.IsEmpty())
return;
+
+ v8::Context::Scope context_scope(context);
+
+ gin::PerIsolateData* data = gin::PerIsolateData::From(isolate);
+ if (data->GetObjectTemplate(&StatsCollectionController::kWrapperInfo)
+ .IsEmpty()) {
+ v8::Handle<v8::ObjectTemplate> templ =
+ gin::ObjectTemplateBuilder(isolate)
+ .SetMethod("getHistogram", &StatsCollectionController::GetHistogram)
+ .SetMethod("getBrowserHistogram",
+ &StatsCollectionController::GetBrowserHistogram)
+ .SetMethod("tabLoadTiming",
+ &StatsCollectionController::GetTabLoadTiming)
+ .Build();
+ templ->SetInternalFieldCount(gin::kNumberOfInternalFields);
+ data->SetObjectTemplate(&StatsCollectionController::kWrapperInfo, templ);
}
+
+ gin::Handle<StatsCollectionController> controller =
+ gin::CreateHandle(isolate, new StatsCollectionController());
+ v8::Handle<v8::Object> global = context->Global();
+ global->Set(gin::StringToV8(isolate, "statsCollectionController"),
+ controller.ToV8());
+}
+
+StatsCollectionController::StatsCollectionController() {}
+
+StatsCollectionController::~StatsCollectionController() {}
+
+std::string StatsCollectionController::GetHistogram(
+ const std::string& histogram_name) {
base::HistogramBase* histogram =
- base::StatisticsRecorder::FindHistogram(args[0].ToString());
+ base::StatisticsRecorder::FindHistogram(histogram_name);
std::string output;
if (!histogram) {
output = "{}";
} else {
histogram->WriteJSON(&output);
}
- result->Set(output);
+ return output;
}
-void StatsCollectionController::GetBrowserHistogram(const CppArgumentList& args,
- CppVariant* result) {
- if (args.size() != 1) {
- result->SetNull();
- return;
- }
-
- if (!sender_) {
+std::string StatsCollectionController::GetBrowserHistogram(
+ const std::string& histogram_name) {
+ RenderViewImpl *render_view_impl = NULL;
+ if (!CurrentRenderViewImpl(&render_view_impl)) {
NOTREACHED();
- result->SetNull();
- return;
+ return std::string();
}
std::string histogram_json;
- sender_->Send(new ChildProcessHostMsg_GetBrowserHistogram(
- args[0].ToString(), &histogram_json));
- result->Set(histogram_json);
+ render_view_impl->Send(new ChildProcessHostMsg_GetBrowserHistogram(
+ histogram_name, &histogram_json));
+ return histogram_json;
}
-void StatsCollectionController::GetTabLoadTiming(
- const CppArgumentList& args,
- CppVariant* result) {
- if (!sender_) {
- NOTREACHED();
- result->SetNull();
- return;
- }
-
+std::string StatsCollectionController::GetTabLoadTiming() {
RenderViewImpl *render_view_impl = NULL;
if (!CurrentRenderViewImpl(&render_view_impl)) {
NOTREACHED();
- result->SetNull();
- return;
+ return std::string();
}
StatsCollectionObserver* observer =
render_view_impl->GetStatsCollectionObserver();
if (!observer) {
NOTREACHED();
- result->SetNull();
- return;
+ return std::string();
}
std::string tab_timing_json;
ConvertLoadTimeToJSON(
observer->load_start_time(), observer->load_stop_time(),
&tab_timing_json);
- result->Set(tab_timing_json);
+ return tab_timing_json;
}
} // namespace content
diff --git a/content/renderer/stats_collection_controller.h b/content/renderer/stats_collection_controller.h
index 63175d8..c122972 100644
--- a/content/renderer/stats_collection_controller.h
+++ b/content/renderer/stats_collection_controller.h
@@ -5,8 +5,12 @@
#ifndef CONTENT_RENDERER_STATS_COLLECTION_CONTROLLER_H_
#define CONTENT_RENDERER_STATS_COLLECTION_CONTROLLER_H_
-#include "ipc/ipc_sender.h"
-#include "webkit/renderer/cpp_bound_class.h"
+#include "base/basictypes.h"
+#include "gin/wrappable.h"
+
+namespace blink {
+class WebFrame;
+}
namespace content {
@@ -14,28 +18,28 @@ namespace content {
// functionality to read out statistics from the browser.
// Its use must be enabled specifically via the
// --enable-stats-collection-bindings command line flag.
-class StatsCollectionController : public webkit_glue::CppBoundClass {
+class StatsCollectionController
+ : public gin::Wrappable<StatsCollectionController> {
public:
- StatsCollectionController();
+ static gin::WrapperInfo kWrapperInfo;
- void set_message_sender(IPC::Sender* sender) {
- sender_ = sender;
- }
+ static void Install(blink::WebFrame* frame);
+
+ private:
+ StatsCollectionController();
+ virtual ~StatsCollectionController();
// Retrieves a histogram and returns a JSON representation of it.
- void GetHistogram(const webkit_glue::CppArgumentList& args,
- webkit_glue::CppVariant* result);
+ std::string GetHistogram(const std::string& histogram_name);
// Retrieves a histogram from the browser process and returns a JSON
// representation of it.
- void GetBrowserHistogram(const webkit_glue::CppArgumentList& args,
- webkit_glue::CppVariant* result);
+ std::string GetBrowserHistogram(const std::string& histogram_name);
// Returns JSON representation of tab timing information for the current tab.
- void GetTabLoadTiming(const webkit_glue::CppArgumentList& args,
- webkit_glue::CppVariant* result);
- private:
- IPC::Sender* sender_;
+ std::string GetTabLoadTiming();
+
+ DISALLOW_COPY_AND_ASSIGN(StatsCollectionController);
};
} // namespace content