Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2430)

Unified Diff: blimp/engine/common/blimp_browser_context.cc

Issue 1945393002: Create and integrate a metrics service client into Blimp engine. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Follow up on comments. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « blimp/engine/common/blimp_browser_context.h ('k') | blimp/engine/common/blimp_browser_context_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: blimp/engine/common/blimp_browser_context.cc
diff --git a/blimp/engine/common/blimp_browser_context.cc b/blimp/engine/common/blimp_browser_context.cc
index 6a2a7ec04ad9ba83d257b766bf9ef850515804b0..9c86399cb577949889bed1405a2e8c68edd37ecc 100644
--- a/blimp/engine/common/blimp_browser_context.cc
+++ b/blimp/engine/common/blimp_browser_context.cc
@@ -7,14 +7,27 @@
#include "base/bind.h"
#include "base/environment.h"
#include "base/files/file_util.h"
+#include "base/memory/ptr_util.h"
#include "base/nix/xdg_util.h"
#include "base/path_service.h"
#include "blimp/engine/app/blimp_permission_manager.h"
+#include "components/metrics/metrics_service.h"
+#include "components/pref_registry/pref_registry_syncable.h"
+#include "components/prefs/in_memory_pref_store.h"
+#include "components/prefs/pref_service.h"
+#include "components/prefs/pref_service_factory.h"
#include "content/public/browser/background_sync_controller.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/common/content_switches.h"
+namespace {
+// Function for optionally handling read errors. Is a no-op for Blimp.
+// While the PersistentPrefStore's interface is supported, it is an in-memory
+// store only.
+void IgnoreReadError(PersistentPrefStore::PrefReadError error) {}
+} // namespace
+
namespace blimp {
namespace engine {
@@ -59,6 +72,10 @@ BlimpBrowserContext::BlimpBrowserContext(bool off_the_record,
off_the_record_(off_the_record),
net_log_(net_log) {
InitWhileIOAllowed();
+ InitPrefService();
+ metrics_service_client_.reset(
+ new BlimpMetricsServiceClient(pref_service_.get(),
+ GetSystemRequestContextGetter()));
}
BlimpBrowserContext::~BlimpBrowserContext() {
@@ -79,6 +96,23 @@ void BlimpBrowserContext::InitWhileIOAllowed() {
BrowserContext::Initialize(this, path_);
}
+void BlimpBrowserContext::InitPrefService() {
+ // Create PrefRegistry and register metrics services preferences with it.
+ scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry(
+ new user_prefs::PrefRegistrySyncable());
+ metrics::MetricsService::RegisterPrefs(pref_registry.get());
+ PrefServiceFactory pref_service_factory;
+
+ // Create an in memory preferences store to hold metrics logs.
+ pref_service_factory.set_user_prefs(new InMemoryPrefStore());
+ pref_service_factory.set_read_error_callback(base::Bind(&IgnoreReadError));
+
+ // Create a PrefService binding the PrefRegistry to the InMemoryPrefStore.
+ // The PrefService ends up owning the PrefRegistry and the InMemoryPrefStore.
+ pref_service_ = pref_service_factory.Create(pref_registry.get());
+ DCHECK(pref_service_.get());
+}
+
std::unique_ptr<content::ZoomLevelDelegate>
BlimpBrowserContext::CreateZoomLevelDelegate(const base::FilePath&) {
return nullptr;
« no previous file with comments | « blimp/engine/common/blimp_browser_context.h ('k') | blimp/engine/common/blimp_browser_context_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698