summaryrefslogtreecommitdiffstats
path: root/ios
diff options
context:
space:
mode:
authorblundell <blundell@chromium.org>2015-10-26 00:08:44 -0700
committerCommit bot <commit-bot@chromium.org>2015-10-26 07:09:30 +0000
commit498aca68b275fb880d9b32e7109c63bd2968fcaa (patch)
treebb29b993cb8a5ebc53d86ca89c56c0273d0f1151 /ios
parent641847a603e69022bb65d5a466c0836269c63e9b (diff)
downloadchromium_src-498aca68b275fb880d9b32e7109c63bd2968fcaa.zip
chromium_src-498aca68b275fb880d9b32e7109c63bd2968fcaa.tar.gz
chromium_src-498aca68b275fb880d9b32e7109c63bd2968fcaa.tar.bz2
Introduce IOSChromeMetricsServicesManagerClient
This CL introduces the //ios/chrome analogue to //chrome's ChromeMetricsServicesManagerClient. BUG=545991 Review URL: https://codereview.chromium.org/1421733002 Cr-Commit-Position: refs/heads/master@{#356015}
Diffstat (limited to 'ios')
-rw-r--r--ios/chrome/browser/DEPS1
-rw-r--r--ios/chrome/browser/chrome_switches.cc7
-rw-r--r--ios/chrome/browser/chrome_switches.h1
-rw-r--r--ios/chrome/browser/metrics/ios_chrome_metrics_service_accessor.h3
-rw-r--r--ios/chrome/browser/metrics/ios_chrome_metrics_services_manager_client.cc101
-rw-r--r--ios/chrome/browser/metrics/ios_chrome_metrics_services_manager_client.h54
-rw-r--r--ios/chrome/ios_chrome.gyp2
-rw-r--r--ios/public/provider/chrome/browser/chrome_browser_provider.cc8
-rw-r--r--ios/public/provider/chrome/browser/chrome_browser_provider.h9
9 files changed, 185 insertions, 1 deletions
diff --git a/ios/chrome/browser/DEPS b/ios/chrome/browser/DEPS
index 0f3d585..00ec944 100644
--- a/ios/chrome/browser/DEPS
+++ b/ios/chrome/browser/DEPS
@@ -27,6 +27,7 @@ include_rules = [
"+components/keyed_service/ios",
"+components/leveldb_proto",
"+components/metrics",
+ "+components/metrics_services_manager",
"+components/net_log",
"+components/network_time",
"+components/omnibox/browser",
diff --git a/ios/chrome/browser/chrome_switches.cc b/ios/chrome/browser/chrome_switches.cc
index 705afcd..9105c70 100644
--- a/ios/chrome/browser/chrome_switches.cc
+++ b/ios/chrome/browser/chrome_switches.cc
@@ -34,4 +34,11 @@ const char kEnableReaderModeToolbarIcon[] = "enable-reader-mode-toolbar-icon";
// Disables support for keyboard commands.
const char kDisableKeyboardCommands[] = "disable-keyboard-commands";
+// Enables the recording of metrics reports but disables reporting. In contrast
+// to kDisableMetrics, this executes all the code that a normal client would
+// use for reporting, except the report is dropped rather than sent to the
+// server. This is useful for finding issues in the metrics code during UI and
+// performance tests.
+const char kIOSMetricsRecordingOnly[] = "metrics-recording-only";
+
} // namespace switches
diff --git a/ios/chrome/browser/chrome_switches.h b/ios/chrome/browser/chrome_switches.h
index 02d302b..0e30032 100644
--- a/ios/chrome/browser/chrome_switches.h
+++ b/ios/chrome/browser/chrome_switches.h
@@ -15,6 +15,7 @@ extern const char kEnableIOSBlockUnpromptedExternalURLs[];
extern const char kEnableIOSWKWebView[];
extern const char kEnableReaderModeToolbarIcon[];
extern const char kDisableKeyboardCommands[];
+extern const char kIOSMetricsRecordingOnly[];
} // namespace switches
diff --git a/ios/chrome/browser/metrics/ios_chrome_metrics_service_accessor.h b/ios/chrome/browser/metrics/ios_chrome_metrics_service_accessor.h
index 02e1b3c..467612a 100644
--- a/ios/chrome/browser/metrics/ios_chrome_metrics_service_accessor.h
+++ b/ios/chrome/browser/metrics/ios_chrome_metrics_service_accessor.h
@@ -21,11 +21,12 @@ class CrashesDOMHandler;
// as a 'friend' below.
class IOSChromeMetricsServiceAccessor : public metrics::MetricsServiceAccessor {
private:
+ friend class IOSChromeMetricsServicesManagerClient;
+
// TODO(blundell): Remove these //chrome classes as friends once they're no
// longer used by the iOS port.
friend class ::CrashesDOMHandler;
friend class DataReductionProxyChromeSettings;
- friend class MetricsServicesManager;
FRIEND_TEST_ALL_PREFIXES(IOSChromeMetricsServiceAccessorTest,
MetricsReportingEnabled);
diff --git a/ios/chrome/browser/metrics/ios_chrome_metrics_services_manager_client.cc b/ios/chrome/browser/metrics/ios_chrome_metrics_services_manager_client.cc
new file mode 100644
index 0000000..d854b10
--- /dev/null
+++ b/ios/chrome/browser/metrics/ios_chrome_metrics_services_manager_client.cc
@@ -0,0 +1,101 @@
+// Copyright 2015 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/metrics/ios_chrome_metrics_services_manager_client.h"
+
+#include "base/command_line.h"
+#include "base/logging.h"
+#include "base/prefs/pref_service.h"
+#include "components/metrics/metrics_state_manager.h"
+#include "components/rappor/rappor_service.h"
+#include "components/variations/service/variations_service.h"
+#include "ios/chrome/browser/application_context.h"
+#include "ios/chrome/browser/chrome_switches.h"
+#include "ios/chrome/browser/metrics/ios_chrome_metrics_service_accessor.h"
+#include "ios/chrome/browser/metrics/ios_chrome_metrics_service_client.h"
+#include "ios/chrome/browser/ui/browser_otr_state.h"
+#include "ios/chrome/browser/variations/ios_chrome_variations_service_client.h"
+#include "ios/chrome/browser/variations/ios_ui_string_overrider_factory.h"
+#include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
+
+namespace {
+
+void PostStoreMetricsClientInfo(const metrics::ClientInfo& client_info) {}
+
+scoped_ptr<metrics::ClientInfo> LoadMetricsClientInfo() {
+ return scoped_ptr<metrics::ClientInfo>();
+}
+
+} // namespace
+
+IOSChromeMetricsServicesManagerClient::IOSChromeMetricsServicesManagerClient(
+ PrefService* local_state)
+ : local_state_(local_state) {
+ DCHECK(local_state);
+}
+
+IOSChromeMetricsServicesManagerClient::
+ ~IOSChromeMetricsServicesManagerClient() {
+ ios::GetChromeBrowserProvider()->OnMetricsServicesManagerClientDestroyed();
+}
+
+scoped_ptr<rappor::RapporService>
+IOSChromeMetricsServicesManagerClient::CreateRapporService() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ return make_scoped_ptr(new rappor::RapporService(
+ local_state_, base::Bind(&::IsOffTheRecordSessionActive)));
+}
+
+scoped_ptr<variations::VariationsService>
+IOSChromeMetricsServicesManagerClient::CreateVariationsService() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ // NOTE: On iOS, disabling background networking is not supported, so pass in
+ // a dummy value for the name of the switch that disables background
+ // networking.
+ return variations::VariationsService::Create(
+ make_scoped_ptr(new IOSChromeVariationsServiceClient), local_state_,
+ GetMetricsStateManager(), "dummyDisableBackgroundSwitch",
+ ::CreateUIStringOverrider());
+}
+
+scoped_ptr<metrics::MetricsServiceClient>
+IOSChromeMetricsServicesManagerClient::CreateMetricsServiceClient() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ return IOSChromeMetricsServiceClient::Create(GetMetricsStateManager(),
+ local_state_);
+}
+
+net::URLRequestContextGetter*
+IOSChromeMetricsServicesManagerClient::GetURLRequestContext() {
+ return GetApplicationContext()->GetSystemURLRequestContext();
+}
+
+bool IOSChromeMetricsServicesManagerClient::IsSafeBrowsingEnabled(
+ const base::Closure& on_update_callback) {
+ return ios::GetChromeBrowserProvider()->IsSafeBrowsingEnabled(
+ on_update_callback);
+}
+
+bool IOSChromeMetricsServicesManagerClient::IsMetricsReportingEnabled() {
+ return IOSChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled();
+}
+
+bool IOSChromeMetricsServicesManagerClient::OnlyDoMetricsRecording() {
+ const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
+ return cmdline->HasSwitch(switches::kIOSMetricsRecordingOnly);
+}
+
+metrics::MetricsStateManager*
+IOSChromeMetricsServicesManagerClient::GetMetricsStateManager() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ if (!metrics_state_manager_) {
+ metrics_state_manager_ = metrics::MetricsStateManager::Create(
+ local_state_, base::Bind(&IOSChromeMetricsServiceAccessor::
+ IsMetricsAndCrashReportingEnabled),
+ base::Bind(&PostStoreMetricsClientInfo),
+ base::Bind(&LoadMetricsClientInfo));
+ }
+ return metrics_state_manager_.get();
+}
diff --git a/ios/chrome/browser/metrics/ios_chrome_metrics_services_manager_client.h b/ios/chrome/browser/metrics/ios_chrome_metrics_services_manager_client.h
new file mode 100644
index 0000000..0e16a97
--- /dev/null
+++ b/ios/chrome/browser/metrics/ios_chrome_metrics_services_manager_client.h
@@ -0,0 +1,54 @@
+// Copyright 2015 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_METRICS_IOS_CHROME_METRICS_SERVICES_MANAGER_CLIENT_H_
+#define IOS_CHROME_BROWSER_METRICS_IOS_CHROME_METRICS_SERVICES_MANAGER_CLIENT_H_
+
+#include "base/basictypes.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/threading/thread_checker.h"
+#include "components/metrics_services_manager/metrics_services_manager_client.h"
+
+class PrefService;
+
+namespace metrics {
+class MetricsStateManager;
+}
+
+// Provides an //ios/chrome-specific implementation of
+// MetricsServicesManagerClient.
+class IOSChromeMetricsServicesManagerClient
+ : public metrics_services_manager::MetricsServicesManagerClient {
+ public:
+ explicit IOSChromeMetricsServicesManagerClient(PrefService* local_state);
+ ~IOSChromeMetricsServicesManagerClient() override;
+
+ private:
+ // metrics_services_manager::MetricsServicesManagerClient:
+ scoped_ptr<rappor::RapporService> CreateRapporService() override;
+ scoped_ptr<variations::VariationsService> CreateVariationsService() override;
+ scoped_ptr<metrics::MetricsServiceClient> CreateMetricsServiceClient()
+ override;
+ net::URLRequestContextGetter* GetURLRequestContext() override;
+ bool IsSafeBrowsingEnabled(const base::Closure& on_update_callback) override;
+ bool IsMetricsReportingEnabled() override;
+ bool OnlyDoMetricsRecording() override;
+
+ // Gets the MetricsStateManager, creating it if it has not already been
+ // created.
+ metrics::MetricsStateManager* GetMetricsStateManager();
+
+ // MetricsStateManager which is passed as a parameter to service constructors.
+ scoped_ptr<metrics::MetricsStateManager> metrics_state_manager_;
+
+ // Ensures that all functions are called from the same thread.
+ base::ThreadChecker thread_checker_;
+
+ // Weak pointer to the local state prefs store.
+ PrefService* local_state_;
+
+ DISALLOW_COPY_AND_ASSIGN(IOSChromeMetricsServicesManagerClient);
+};
+
+#endif // IOS_CHROME_BROWSER_METRICS_IOS_CHROME_METRICS_SERVICES_MANAGER_CLIENT_H_
diff --git a/ios/chrome/ios_chrome.gyp b/ios/chrome/ios_chrome.gyp
index 9a63991..b123d70 100644
--- a/ios/chrome/ios_chrome.gyp
+++ b/ios/chrome/ios_chrome.gyp
@@ -290,6 +290,8 @@
'browser/metrics/ios_chrome_metrics_service_accessor.h',
'browser/metrics/ios_chrome_metrics_service_client.cc',
'browser/metrics/ios_chrome_metrics_service_client.h',
+ 'browser/metrics/ios_chrome_metrics_services_manager_client.cc',
+ 'browser/metrics/ios_chrome_metrics_services_manager_client.h',
'browser/metrics/ios_chrome_stability_metrics_provider.cc',
'browser/metrics/ios_chrome_stability_metrics_provider.h',
'browser/metrics/ios_stability_metrics_provider.h',
diff --git a/ios/public/provider/chrome/browser/chrome_browser_provider.cc b/ios/public/provider/chrome/browser/chrome_browser_provider.cc
index 49b917a..f08e0f5 100644
--- a/ios/public/provider/chrome/browser/chrome_browser_provider.cc
+++ b/ios/public/provider/chrome/browser/chrome_browser_provider.cc
@@ -127,4 +127,12 @@ void ChromeBrowserProvider::GetFaviconForURL(
const std::vector<int>& desired_sizes_in_pixel,
const favicon_base::FaviconResultsCallback& callback) const {}
+
+bool ChromeBrowserProvider::IsSafeBrowsingEnabled(
+ const base::Closure& on_update_callback) {
+ return false;
+}
+
+void ChromeBrowserProvider::OnMetricsServicesManagerClientDestroyed() {}
+
} // namespace ios
diff --git a/ios/public/provider/chrome/browser/chrome_browser_provider.h b/ios/public/provider/chrome/browser/chrome_browser_provider.h
index 83f31fc..e171939 100644
--- a/ios/public/provider/chrome/browser/chrome_browser_provider.h
+++ b/ios/public/provider/chrome/browser/chrome_browser_provider.h
@@ -10,6 +10,7 @@
#include <string>
#include <vector>
+#include "base/callback_forward.h"
#include "components/favicon_base/favicon_callback.h"
class GURL;
@@ -138,6 +139,14 @@ class ChromeBrowserProvider {
const GURL& page_url,
const std::vector<int>& desired_sizes_in_pixel,
const favicon_base::FaviconResultsCallback& callback) const;
+
+ // Returns whether safe browsing is enabled. See the comment on
+ // metrics_services_manager_client.h for details on |on_update_callback|.
+ virtual bool IsSafeBrowsingEnabled(const base::Closure& on_update_callback);
+
+ // Called when the IOSChromeMetricsServiceClientManager instance is
+ // destroyed.
+ virtual void OnMetricsServicesManagerClientDestroyed();
};
} // namespace ios