Skip to content

Commit

Permalink
Implement Ukm Mojo interface and make it available to content/renderer
Browse files Browse the repository at this point in the history
Depends on https://codereview.chromium.org/2883563002/

TBR=holte

Review-Url: https://codereview.chromium.org/2882353002
Cr-Commit-Position: refs/heads/master@{#475658}
  • Loading branch information
holte authored and Commit Bot committed May 30, 2017
1 parent 5828a72 commit c093440
Show file tree
Hide file tree
Showing 12 changed files with 166 additions and 1 deletion.
1 change: 1 addition & 0 deletions chrome/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1604,6 +1604,7 @@ split_static_library("browser") {
"//components/translate/core/browser",
"//components/translate/core/common",
"//components/ukm:observers",
"//components/ukm:ukm_interface",
"//components/ukm/debug_page",
"//components/undo",
"//components/update_client",
Expand Down
4 changes: 4 additions & 0 deletions chrome/browser/chrome_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
#include "components/task_scheduler_util/browser/initialization.h"
#include "components/task_scheduler_util/common/variations_util.h"
#include "components/translate/core/common/translate_switches.h"
#include "components/ukm/ukm_interface.h"
#include "components/url_formatter/url_fixer.h"
#include "components/variations/variations_associated_data.h"
#include "components/version_info/version_info.h"
Expand Down Expand Up @@ -3077,6 +3078,9 @@ void ChromeContentBrowserClient::ExposeInterfacesToRenderer(
base::Bind(&rappor::RapporRecorderImpl::Create,
g_browser_process->rappor_service()),
ui_task_runner);
registry->AddInterface(
base::Bind(&ukm::UkmInterface::Create, g_browser_process->ukm_recorder()),
ui_task_runner);
if (NetBenchmarking::CheckBenchmarkingEnabled()) {
Profile* profile =
Profile::FromBrowserContext(render_process_host->GetBrowserContext());
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/chrome_content_browser_manifest_overlay.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"rappor::mojom::RapporRecorder",
"spellcheck::mojom::SpellCheckHost",
"startup_metric_utils::mojom::StartupMetricHost",
"translate::mojom::ContentTranslateDriver"
"translate::mojom::ContentTranslateDriver",
"ukm::mojom::UkmRecorderInterface"
],
"gpu": [
"metrics::mojom::CallStackProfileCollector"
Expand Down
2 changes: 2 additions & 0 deletions chrome/renderer/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ static_library("renderer") {
"//components/translate/content/renderer",
"//components/translate/core/common",
"//components/translate/core/language_detection",
"//components/ukm/public",
"//components/ukm/public/interfaces",
"//components/visitedlink/renderer",
"//components/web_cache/renderer",
"//content/app/resources",
Expand Down
17 changes: 17 additions & 0 deletions components/ukm/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ static_library("ukm") {
]
}

static_library("ukm_interface") {
sources = [
"ukm_interface.cc",
"ukm_interface.h",
]

public_deps = [
"//base",
"//components/ukm/public/interfaces",
]

deps = [
":ukm",
"//mojo/public/cpp/bindings",
]
}

# Helper library for observing signals that we need to clear any local data.
static_library("observers") {
sources = [
Expand Down
2 changes: 2 additions & 0 deletions components/ukm/public/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import("//mojo/public/tools/bindings/mojom.gni")

component("public") {
sources = [
"mojo_ukm_recorder.cc",
"mojo_ukm_recorder.h",
"ukm_entry_builder.cc",
"ukm_entry_builder.h",
"ukm_export.h",
Expand Down
24 changes: 24 additions & 0 deletions components/ukm/public/mojo_ukm_recorder.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2017 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 "components/ukm/public/mojo_ukm_recorder.h"

#include "base/memory/ptr_util.h"

namespace ukm {

MojoUkmRecorder::MojoUkmRecorder(mojom::UkmRecorderInterfacePtr interface)
: interface_(std::move(interface)) {}
MojoUkmRecorder::~MojoUkmRecorder() = default;

void MojoUkmRecorder::UpdateSourceURL(SourceId source_id, const GURL& url) {
DCHECK(false);
// Not implemented yet, currently a no-op.
}

void MojoUkmRecorder::AddEntry(mojom::UkmEntryPtr entry) {
interface_->AddEntry(std::move(entry));
}

} // namespace ukm
44 changes: 44 additions & 0 deletions components/ukm/public/mojo_ukm_recorder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2017 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.

#ifndef COMPONENTS_UKM_PUBLIC_MOJO_UKM_RECORDER_H_
#define COMPONENTS_UKM_PUBLIC_MOJO_UKM_RECORDER_H_

#include "components/ukm/public/interfaces/ukm_interface.mojom.h"
#include "components/ukm/public/ukm_recorder.h"

namespace ukm {

/**
* A helper wrapper that lets UKM data be recorded on other processes with the
* same interface that is used in the browser process.
*
* Usage Example:
*
* ukm::mojom::UkmRecorderInterfacePtr interface;
* content::RenderThread::Get()->GetConnector()->BindInterface(
* content::mojom::kBrowserServiceName, mojo::MakeRequest(&interface));
* ukm::MojoUkmRecorder recorder(std::move(interface));
* std::unique_ptr<ukm::UkmEntryBuilder> builder =
* recorder.GetEntryBuilder(coordination_unit_id, "MyEvent");
* builder->AddMetric("MyMetric", metric_value);
*/
class MojoUkmRecorder : public UkmRecorder {
public:
MojoUkmRecorder(mojom::UkmRecorderInterfacePtr interface);
~MojoUkmRecorder() override;

private:
// UkmRecorder:
void UpdateSourceURL(SourceId source_id, const GURL& url) override;
void AddEntry(mojom::UkmEntryPtr entry) override;

mojom::UkmRecorderInterfacePtr interface_;

DISALLOW_COPY_AND_ASSIGN(MojoUkmRecorder);
};

} // namespace ukm

#endif // COMPONENTS_UKM_PUBLIC_MOJO_UKM_RECORDER_H_
30 changes: 30 additions & 0 deletions components/ukm/ukm_interface.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2017 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 "components/ukm/ukm_interface.h"

#include "base/memory/ptr_util.h"
#include "components/ukm/public/ukm_recorder.h"
#include "mojo/public/cpp/bindings/strong_binding.h"

namespace ukm {

UkmInterface::UkmInterface(UkmRecorder* ukm_recorder)
: ukm_recorder_(ukm_recorder) {}

UkmInterface::~UkmInterface() = default;

// static
void UkmInterface::Create(UkmRecorder* ukm_recorder,
const service_manager::BindSourceInfo& source_info,
mojom::UkmRecorderInterfaceRequest request) {
mojo::MakeStrongBinding(base::MakeUnique<UkmInterface>(ukm_recorder),
std::move(request));
}

void UkmInterface::AddEntry(mojom::UkmEntryPtr ukm_entry) {
ukm_recorder_->AddEntry(std::move(ukm_entry));
}

} // namespace ukm
38 changes: 38 additions & 0 deletions components/ukm/ukm_interface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2017 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.

#ifndef COMPONENTS_UKM_UKM_INTERFACE_H_
#define COMPONENTS_UKM_UKM_INTERFACE_H_

#include "components/ukm/public/interfaces/ukm_interface.mojom.h"

namespace service_manager {
struct BindSourceInfo;
}

namespace ukm {

class UkmRecorder;

class UkmInterface : public mojom::UkmRecorderInterface {
public:
explicit UkmInterface(UkmRecorder* ukm_recorder);
~UkmInterface() override;

static void Create(UkmRecorder* ukm_recorder,
const service_manager::BindSourceInfo& source_info,
mojom::UkmRecorderInterfaceRequest request);

private:
// ukm::mojom::UkmRecorderInterface:
void AddEntry(mojom::UkmEntryPtr entry) override;

UkmRecorder* ukm_recorder_;

DISALLOW_COPY_AND_ASSIGN(UkmInterface);
};

} // namespace ukm

#endif // COMPONENTS_UKM_UKM_INTERFACE_H_
1 change: 1 addition & 0 deletions content/renderer/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ target(link_target_type, "renderer") {
"//components/metrics",
"//components/metrics:single_sample_metrics",
"//components/payments/mojom:mojom_payment_app",
"//components/ukm/public",
"//components/url_formatter",
"//components/variations",
"//components/viz/client",
Expand Down
1 change: 1 addition & 0 deletions content/renderer/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ include_rules = [
"+components/metrics:single_sample_metrics",
"+components/payments",
"+components/scheduler",
"+components/ukm/public",
"+components/url_formatter",
"+components/variations",
"+components/viz/client",
Expand Down

0 comments on commit c093440

Please sign in to comment.