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..5ab92b654259cbbfc02b536fdf28271962d045e1 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 HandleReadError(PersistentPrefStore::PrefReadError error) {} |
Kevin M
2016/05/02 21:50:52
IgnoreReadError()?
Jess
2016/05/02 23:00:24
Done.
|
+} // namespace |
+ |
namespace blimp { |
namespace engine { |
@@ -68,6 +81,14 @@ BlimpBrowserContext::~BlimpBrowserContext() { |
} |
} |
+void BlimpBrowserContext::Initialize() { |
Kevin M
2016/05/02 21:50:52
Any reason why we can't do this in the constructor
Jess
2016/05/02 23:00:24
None that's apparent to me. Done.
|
+ InitializeBlimpMetrics(GetPrefService(), GetSystemRequestContextGetter()); |
+} |
+ |
+void BlimpBrowserContext::Finalize() { |
+ FinalizeBlimpMetrics(); |
+} |
+ |
void BlimpBrowserContext::InitWhileIOAllowed() { |
// Ensures ~/.config/blimp_engine directory exists. |
std::unique_ptr<base::Environment> env(base::Environment::Create()); |
@@ -79,6 +100,20 @@ void BlimpBrowserContext::InitWhileIOAllowed() { |
BrowserContext::Initialize(this, path_); |
} |
+std::unique_ptr<PrefService> BlimpBrowserContext::GetPrefService() { |
+ // 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. |
Kevin M
2016/05/02 21:50:52
Add newlines before comments
Jess
2016/05/02 23:00:24
Done.
|
+ pref_service_factory.set_user_prefs(new InMemoryPrefStore()); |
+ pref_service_factory.set_read_error_callback(base::Bind(&HandleReadError)); |
+ // Create a PrefService binding the PrefRegistry to the InMemoryPrefStore. |
Kevin M
2016/05/02 21:50:52
Newline beforehand
Jess
2016/05/02 23:00:24
Done.
|
+ // The PrefService ends up owning the PrefRegistry and the InMemoryPrefStore. |
+ return pref_service_factory.Create(pref_registry.get()); |
+} |
+ |
std::unique_ptr<content::ZoomLevelDelegate> |
BlimpBrowserContext::CreateZoomLevelDelegate(const base::FilePath&) { |
return nullptr; |