Commit b825a421 authored by Mohamad Ahmadi's avatar Mohamad Ahmadi Committed by Commit Bot

Enables chrome://ukm in iOS

Bug: 809507
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I584f0412c197f24236b5402f97d9000a9bf92d66
Reviewed-on: https://chromium-review.googlesource.com/916707Reviewed-by: default avatarRobert Kaplow <rkaplow@chromium.org>
Reviewed-by: default avatarPeter Lee <pkl@chromium.org>
Commit-Queue: Moe Ahmadi <mahmadi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#537112}
parent 8e5f0d8f
...@@ -1735,7 +1735,7 @@ split_static_library("browser") { ...@@ -1735,7 +1735,7 @@ split_static_library("browser") {
"//components/translate/core/browser", "//components/translate/core/browser",
"//components/translate/core/common", "//components/translate/core/common",
"//components/ukm:observers", "//components/ukm:observers",
"//components/ukm/debug_page", "//components/ukm/content/debug_page",
"//components/undo", "//components/undo",
"//components/update_client", "//components/update_client",
"//components/upload_list", "//components/upload_list",
......
...@@ -82,7 +82,7 @@ ...@@ -82,7 +82,7 @@
#include "components/prefs/pref_registry_simple.h" #include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/sync/device_info/device_count_metrics_provider.h" #include "components/sync/device_info/device_count_metrics_provider.h"
#include "components/ukm/debug_page/debug_page.h" #include "components/ukm/content/debug_page/debug_page.h"
#include "components/ukm/ukm_service.h" #include "components/ukm/ukm_service.h"
#include "components/version_info/version_info.h" #include "components/version_info/version_info.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
......
# Copyright 2017 The Chromium Authors. All rights reserved. # Copyright 2018 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
...@@ -11,8 +11,8 @@ static_library("debug_page") { ...@@ -11,8 +11,8 @@ static_library("debug_page") {
deps = [ deps = [
"//base", "//base",
"//components/ukm", "//components/ukm",
"//components/ukm/debug:util",
"//content/public/browser", "//content/public/browser",
"//services/metrics/public/cpp:ukm_builders",
"//url", "//url",
] ]
} }
// Copyright 2018 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/content/debug_page/debug_page.h"
#include "base/memory/ref_counted_memory.h"
#include "components/ukm/debug/ukm_debug_data_extractor.h"
namespace ukm {
namespace debug {
DebugPage::DebugPage(ServiceGetter service_getter)
: service_getter_(service_getter) {}
DebugPage::~DebugPage() {}
std::string DebugPage::GetSource() const {
return "ukm";
}
std::string DebugPage::GetMimeType(const std::string& path) const {
return "text/html";
}
void DebugPage::StartDataRequest(
const std::string& path,
const content::ResourceRequestInfo::WebContentsGetter& wc_getter,
const content::URLDataSource::GotDataCallback& callback) {
std::string data = UkmDebugDataExtractor::GetHTMLData(service_getter_.Run());
callback.Run(base::RefCountedString::TakeString(&data));
}
bool DebugPage::AllowCaching() const {
return false;
}
} // namespace debug
} // namespace ukm
// Copyright (c) 2017 The Chromium Authors. All rights reserved. // Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -20,7 +20,7 @@ namespace debug { ...@@ -20,7 +20,7 @@ namespace debug {
// Implements the chrome://ukm page for debugging UKM state. // Implements the chrome://ukm page for debugging UKM state.
class DebugPage : public content::URLDataSource { class DebugPage : public content::URLDataSource {
public: public:
typedef base::Callback<UkmService*()> ServiceGetter; typedef base::RepeatingCallback<UkmService*()> ServiceGetter;
explicit DebugPage(ServiceGetter service_getter); explicit DebugPage(ServiceGetter service_getter);
......
# Copyright 2018 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.
source_set("util") {
sources = [
"ukm_debug_data_extractor.cc",
"ukm_debug_data_extractor.h",
]
deps = [
"//base",
"//components/ukm",
"//services/metrics/public/cpp:ukm_builders",
]
}
// Copyright (c) 2017 The Chromium Authors. All rights reserved. // Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "components/ukm/debug_page/debug_page.h" #include "components/ukm/debug/ukm_debug_data_extractor.h"
#include <inttypes.h> #include <inttypes.h>
#include "base/memory/ref_counted_memory.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "components/ukm/ukm_service.h" #include "components/ukm/ukm_service.h"
#include "components/ukm/ukm_source.h" #include "components/ukm/ukm_source.h"
...@@ -31,25 +30,14 @@ std::string GetName(ukm::builders::DecodeMap& decode_map, uint64_t hash) { ...@@ -31,25 +30,14 @@ std::string GetName(ukm::builders::DecodeMap& decode_map, uint64_t hash) {
} // namespace } // namespace
DebugPage::DebugPage(ServiceGetter service_getter) UkmDebugDataExtractor::UkmDebugDataExtractor() = default;
: service_getter_(service_getter) {}
DebugPage::~DebugPage() {} UkmDebugDataExtractor::~UkmDebugDataExtractor() = default;
std::string DebugPage::GetSource() const { // static
return "ukm"; std::string UkmDebugDataExtractor::GetHTMLData(UkmService* ukm_service) {
} std::string output;
output.append(R"""(<!DOCTYPE html>
std::string DebugPage::GetMimeType(const std::string& path) const {
return "text/html";
}
void DebugPage::StartDataRequest(
const std::string& path,
const content::ResourceRequestInfo::WebContentsGetter& wc_getter,
const content::URLDataSource::GotDataCallback& callback) {
std::string data;
data.append(R"""(<!DOCTYPE html>
<html> <html>
<head> <head>
<meta http-equiv="Content-Security-Policy" <meta http-equiv="Content-Security-Policy"
...@@ -59,15 +47,15 @@ void DebugPage::StartDataRequest( ...@@ -59,15 +47,15 @@ void DebugPage::StartDataRequest(
<body> <body>
<h1>UKM Debug page</h1> <h1>UKM Debug page</h1>
)"""); )""");
UkmService* ukm_service = service_getter_.Run();
if (ukm_service) { if (ukm_service) {
data.append( output.append(
// 'id' attribute set so tests can extract this element. // 'id' attribute set so tests can extract this element.
base::StringPrintf("<p>IsEnabled:<span id='state'>%s</span></p>", base::StringPrintf("<p>IsEnabled:<span id='state'>%s</span></p>",
ukm_service->recording_enabled_ ? "True" : "False")); ukm_service->recording_enabled_ ? "True" : "False"));
data.append(base::StringPrintf("<p>ClientId:%" PRIu64 "</p>", output.append(base::StringPrintf("<p>ClientId:%" PRIu64 "</p>",
ukm_service->client_id_)); ukm_service->client_id_));
data.append( output.append(
base::StringPrintf("<p>SessionId:%d</p>", ukm_service->session_id_)); base::StringPrintf("<p>SessionId:%d</p>", ukm_service->session_id_));
auto decode_map = ::ukm::builders::CreateDecodeMap(); auto decode_map = ::ukm::builders::CreateDecodeMap();
...@@ -80,21 +68,21 @@ void DebugPage::StartDataRequest( ...@@ -80,21 +68,21 @@ void DebugPage::StartDataRequest(
source_data[v.get()->source_id].entries.push_back(v.get()); source_data[v.get()->source_id].entries.push_back(v.get());
} }
data.append("<h2>Sources</h2>"); output.append("<h2>Sources</h2>");
for (const auto& kv : source_data) { for (const auto& kv : source_data) {
const auto* src = kv.second.source; const auto* src = kv.second.source;
if (src) { if (src) {
data.append(base::StringPrintf("<h3>Id:%" PRId64 " Url:%s</h3>", output.append(base::StringPrintf("<h3>Id:%" PRId64 " Url:%s</h3>",
src->id(), src->url().spec().c_str())); src->id(), src->url().spec().c_str()));
} else { } else {
data.append(base::StringPrintf("<h3>Id:%" PRId64 "</h3>", kv.first)); output.append(base::StringPrintf("<h3>Id:%" PRId64 "</h3>", kv.first));
} }
for (auto* entry : kv.second.entries) { for (auto* entry : kv.second.entries) {
data.append( output.append(
base::StringPrintf("<h4>Entry:%s</h4>", base::StringPrintf("<h4>Entry:%s</h4>",
GetName(decode_map, entry->event_hash).c_str())); GetName(decode_map, entry->event_hash).c_str()));
for (const auto& metric : entry->metrics) { for (const auto& metric : entry->metrics) {
data.append(base::StringPrintf( output.append(base::StringPrintf(
"<h5>Metric:%s Value:%" PRId64 "</h5>", "<h5>Metric:%s Value:%" PRId64 "</h5>",
GetName(decode_map, metric->metric_hash).c_str(), metric->value)); GetName(decode_map, metric->metric_hash).c_str(), metric->value));
} }
...@@ -102,16 +90,12 @@ void DebugPage::StartDataRequest( ...@@ -102,16 +90,12 @@ void DebugPage::StartDataRequest(
} }
} }
data.append(R"""( output.append(R"""(
</body> </body>
</html> </html>
)"""); )""");
callback.Run(base::RefCountedString::TakeString(&data)); return output;
}
bool DebugPage::AllowCaching() const {
return false;
} }
} // namespace debug } // namespace debug
......
// Copyright 2018 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_DEBUG_UKM_DEBUG_DATA_EXTRACTOR_H_
#define COMPONENTS_UKM_DEBUG_UKM_DEBUG_DATA_EXTRACTOR_H_
#include <string>
#include "base/macros.h"
namespace ukm {
class UkmService;
namespace debug {
// Extracts UKM data as an HTML page for debugging purposes.
class UkmDebugDataExtractor {
public:
UkmDebugDataExtractor();
~UkmDebugDataExtractor();
// Returns UKM data as an HTML page.
static std::string GetHTMLData(UkmService* ukm_service);
private:
DISALLOW_COPY_AND_ASSIGN(UkmDebugDataExtractor);
};
} // namespace debug
} // namespace ukm
#endif // COMPONENTS_UKM_DEBUG_UKM_DEBUG_DATA_EXTRACTOR_H_
include_rules = [
"+content/public",
]
...@@ -25,7 +25,7 @@ class UkmSource; ...@@ -25,7 +25,7 @@ class UkmSource;
class Report; class Report;
namespace debug { namespace debug {
class DebugPage; class UkmDebugDataExtractor;
} }
class UkmRecorderImpl : public UkmRecorder { class UkmRecorderImpl : public UkmRecorder {
...@@ -61,7 +61,7 @@ class UkmRecorderImpl : public UkmRecorder { ...@@ -61,7 +61,7 @@ class UkmRecorderImpl : public UkmRecorder {
private: private:
friend ::metrics::UkmBrowserTest; friend ::metrics::UkmBrowserTest;
friend ::metrics::UkmEGTestHelper; friend ::metrics::UkmEGTestHelper;
friend ::ukm::debug::DebugPage; friend ::ukm::debug::UkmDebugDataExtractor;
struct MetricAggregate { struct MetricAggregate {
uint64_t total_count = 0; uint64_t total_count = 0;
......
...@@ -31,7 +31,7 @@ class UkmEGTestHelper; ...@@ -31,7 +31,7 @@ class UkmEGTestHelper;
namespace ukm { namespace ukm {
namespace debug { namespace debug {
class DebugPage; class UkmDebugDataExtractor;
} }
// The URL-Keyed Metrics (UKM) service is responsible for gathering and // The URL-Keyed Metrics (UKM) service is responsible for gathering and
...@@ -79,7 +79,7 @@ class UkmService : public UkmRecorderImpl { ...@@ -79,7 +79,7 @@ class UkmService : public UkmRecorderImpl {
private: private:
friend ::metrics::UkmBrowserTest; friend ::metrics::UkmBrowserTest;
friend ::metrics::UkmEGTestHelper; friend ::metrics::UkmEGTestHelper;
friend ::ukm::debug::DebugPage; friend ::ukm::debug::UkmDebugDataExtractor;
FRIEND_TEST_ALL_PREFIXES(UkmServiceTest, AddEntryWithEmptyMetrics); FRIEND_TEST_ALL_PREFIXES(UkmServiceTest, AddEntryWithEmptyMetrics);
FRIEND_TEST_ALL_PREFIXES(UkmServiceTest, EntryBuilderAndSerialization); FRIEND_TEST_ALL_PREFIXES(UkmServiceTest, EntryBuilderAndSerialization);
......
...@@ -45,6 +45,7 @@ const char kChromeUISuggestionsHost[] = "suggestions"; ...@@ -45,6 +45,7 @@ const char kChromeUISuggestionsHost[] = "suggestions";
const char kChromeUISyncInternalsHost[] = "sync-internals"; const char kChromeUISyncInternalsHost[] = "sync-internals";
const char kChromeUITermsHost[] = "terms"; const char kChromeUITermsHost[] = "terms";
const char kChromeUIVersionHost[] = "version"; const char kChromeUIVersionHost[] = "version";
const char kChromeUIURLKeyedMetricsHost[] = "ukm";
// Add hosts here to be included in chrome://chrome-urls (about:about). // Add hosts here to be included in chrome://chrome-urls (about:about).
// These hosts will also be suggested by BuiltinProvider. // These hosts will also be suggested by BuiltinProvider.
......
...@@ -57,6 +57,7 @@ extern const char kChromeUISuggestionsHost[]; ...@@ -57,6 +57,7 @@ extern const char kChromeUISuggestionsHost[];
extern const char kChromeUISyncInternalsHost[]; extern const char kChromeUISyncInternalsHost[];
extern const char kChromeUITermsHost[]; extern const char kChromeUITermsHost[];
extern const char kChromeUIVersionHost[]; extern const char kChromeUIVersionHost[];
extern const char kChromeUIURLKeyedMetricsHost[];
// Gets the hosts/domains that are shown in chrome://chrome-urls. // Gets the hosts/domains that are shown in chrome://chrome-urls.
extern const char* const kChromeHostURLs[]; extern const char* const kChromeHostURLs[];
......
...@@ -20,6 +20,8 @@ source_set("webui") { ...@@ -20,6 +20,8 @@ source_set("webui") {
"suggestions_ui.h", "suggestions_ui.h",
"terms_ui.h", "terms_ui.h",
"terms_ui.mm", "terms_ui.mm",
"url_keyed_metrics_ui.cc",
"url_keyed_metrics_ui.h",
"version_handler.cc", "version_handler.cc",
"version_handler.h", "version_handler.h",
"version_ui.h", "version_ui.h",
...@@ -32,6 +34,7 @@ source_set("webui") { ...@@ -32,6 +34,7 @@ source_set("webui") {
"//components/crash/core/browser", "//components/crash/core/browser",
"//components/flags_ui", "//components/flags_ui",
"//components/keyed_service/core", "//components/keyed_service/core",
"//components/metrics_services_manager",
"//components/ntp_tiles", "//components/ntp_tiles",
"//components/password_manager/core/browser", "//components/password_manager/core/browser",
"//components/physical_web/data_source", "//components/physical_web/data_source",
...@@ -40,6 +43,8 @@ source_set("webui") { ...@@ -40,6 +43,8 @@ source_set("webui") {
"//components/resources", "//components/resources",
"//components/strings", "//components/strings",
"//components/suggestions", "//components/suggestions",
"//components/ukm",
"//components/ukm/debug:util",
"//components/version_info", "//components/version_info",
"//components/version_ui", "//components/version_ui",
"//google_apis", "//google_apis",
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "ios/chrome/browser/ui/webui/suggestions_ui.h" #include "ios/chrome/browser/ui/webui/suggestions_ui.h"
#include "ios/chrome/browser/ui/webui/sync_internals/sync_internals_ui.h" #include "ios/chrome/browser/ui/webui/sync_internals/sync_internals_ui.h"
#include "ios/chrome/browser/ui/webui/terms_ui.h" #include "ios/chrome/browser/ui/webui/terms_ui.h"
#include "ios/chrome/browser/ui/webui/url_keyed_metrics_ui.h"
#include "ios/chrome/browser/ui/webui/version_ui.h" #include "ios/chrome/browser/ui/webui/version_ui.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -89,6 +90,8 @@ WebUIIOSFactoryFunction GetWebUIIOSFactoryFunction(WebUIIOS* web_ui, ...@@ -89,6 +90,8 @@ WebUIIOSFactoryFunction GetWebUIIOSFactoryFunction(WebUIIOS* web_ui,
return &NewWebUIIOS<VersionUI>; return &NewWebUIIOS<VersionUI>;
if (url_host == kChromeUIFlagsHost) if (url_host == kChromeUIFlagsHost)
return &NewWebUIIOS<FlagsUI>; return &NewWebUIIOS<FlagsUI>;
if (url_host == kChromeUIURLKeyedMetricsHost)
return &NewWebUIIOSWithHost<URLKeyedMetricsUI>;
return nullptr; return nullptr;
} }
......
// Copyright 2018 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 "ios/chrome/browser/ui/webui/url_keyed_metrics_ui.h"
#include <string>
#include "base/memory/ref_counted_memory.h"
#include "components/metrics_services_manager/metrics_services_manager.h"
#include "components/ukm/debug/ukm_debug_data_extractor.h"
#include "components/ukm/ukm_service.h"
#include "ios/chrome/browser/application_context.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/web/public/url_data_source_ios.h"
namespace {
class URLKeyedMetricsUIHTMLSource : public web::URLDataSourceIOS {
public:
// Construct a data source for the specified |source_name|.
explicit URLKeyedMetricsUIHTMLSource(const std::string& source_name);
// web::URLDataSourceIOS implementation.
std::string GetSource() const override;
void StartDataRequest(
const std::string& path,
const web::URLDataSourceIOS::GotDataCallback& callback) override;
std::string GetMimeType(const std::string& path) const override;
bool ShouldDenyXFrameOptions() const override;
private:
~URLKeyedMetricsUIHTMLSource() override;
ukm::UkmService* GetUkmService();
std::string source_name_;
DISALLOW_IMPLICIT_CONSTRUCTORS(URLKeyedMetricsUIHTMLSource);
};
} // namespace
// URLKeyedMetricsUIHTMLSource -------------------------------------------------
URLKeyedMetricsUIHTMLSource::URLKeyedMetricsUIHTMLSource(
const std::string& source_name)
: source_name_(source_name) {}
URLKeyedMetricsUIHTMLSource::~URLKeyedMetricsUIHTMLSource() {}
std::string URLKeyedMetricsUIHTMLSource::GetSource() const {
return source_name_;
}
void URLKeyedMetricsUIHTMLSource::StartDataRequest(
const std::string& path,
const web::URLDataSourceIOS::GotDataCallback& callback) {
std::string data =
ukm::debug::UkmDebugDataExtractor::GetHTMLData(GetUkmService());
callback.Run(base::RefCountedString::TakeString(&data));
}
std::string URLKeyedMetricsUIHTMLSource::GetMimeType(
const std::string& path) const {
return "text/html";
}
bool URLKeyedMetricsUIHTMLSource::ShouldDenyXFrameOptions() const {
return web::URLDataSourceIOS::ShouldDenyXFrameOptions();
}
ukm::UkmService* URLKeyedMetricsUIHTMLSource::GetUkmService() {
return GetApplicationContext()->GetMetricsServicesManager()->GetUkmService();
}
// URLKeyedMetricsUI -----------------------------------------------------------
URLKeyedMetricsUI::URLKeyedMetricsUI(web::WebUIIOS* web_ui,
const std::string& name)
: web::WebUIIOSController(web_ui) {
web::URLDataSourceIOS::Add(ios::ChromeBrowserState::FromWebUIIOS(web_ui),
new URLKeyedMetricsUIHTMLSource(name));
}
URLKeyedMetricsUI::~URLKeyedMetricsUI() {}
// Copyright 2018 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 IOS_CHROME_BROWSER_UI_WEBUI_URL_KEYED_METRICS_UI_H_
#define IOS_CHROME_BROWSER_UI_WEBUI_URL_KEYED_METRICS_UI_H_
#include "base/macros.h"
#include "ios/web/public/webui/web_ui_ios_controller.h"
namespace web {
class WebUIIOS;
}
// The WebUI controller for chrome://ukm.
class URLKeyedMetricsUI : public web::WebUIIOSController {
public:
URLKeyedMetricsUI(web::WebUIIOS* web_ui, const std::string& name);
~URLKeyedMetricsUI() override;
private:
DISALLOW_COPY_AND_ASSIGN(URLKeyedMetricsUI);
};
#endif // IOS_CHROME_BROWSER_UI_WEBUI_URL_KEYED_METRICS_UI_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment