OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "blimp/engine/common/blimp_browser_context.h" | 5 #include "blimp/engine/common/blimp_browser_context.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/environment.h" | 8 #include "base/environment.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/nix/xdg_util.h" | 10 #include "base/nix/xdg_util.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "blimp/engine/app/blimp_permission_manager.h" | 12 #include "blimp/engine/app/blimp_permission_manager.h" |
13 #include "components/metrics/metrics_service.h" | |
14 #include "components/pref_registry/pref_registry_syncable.h" | |
15 #include "components/prefs/in_memory_pref_store.h" | |
16 #include "components/prefs/pref_service.h" | |
17 #include "components/prefs/pref_service_factory.h" | |
13 #include "content/public/browser/background_sync_controller.h" | 18 #include "content/public/browser/background_sync_controller.h" |
14 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
15 #include "content/public/browser/storage_partition.h" | 20 #include "content/public/browser/storage_partition.h" |
16 #include "content/public/common/content_switches.h" | 21 #include "content/public/common/content_switches.h" |
17 | 22 |
23 namespace { | |
24 // Shows notifications which correspond to PersistentPrefStore's reading errors. | |
25 void HandleReadError(PersistentPrefStore::PrefReadError error) { | |
26 } | |
27 } // namespace | |
28 | |
18 namespace blimp { | 29 namespace blimp { |
19 namespace engine { | 30 namespace engine { |
20 | 31 |
21 // Contains URLRequestContextGetter required for resource loading. | 32 // Contains URLRequestContextGetter required for resource loading. |
22 class BlimpResourceContext : public content::ResourceContext { | 33 class BlimpResourceContext : public content::ResourceContext { |
23 public: | 34 public: |
24 BlimpResourceContext() {} | 35 BlimpResourceContext() {} |
25 ~BlimpResourceContext() override {} | 36 ~BlimpResourceContext() override {} |
26 | 37 |
27 void set_url_request_context_getter( | 38 void set_url_request_context_getter( |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 InitWhileIOAllowed(); | 72 InitWhileIOAllowed(); |
62 } | 73 } |
63 | 74 |
64 BlimpBrowserContext::~BlimpBrowserContext() { | 75 BlimpBrowserContext::~BlimpBrowserContext() { |
65 if (resource_context_) { | 76 if (resource_context_) { |
66 content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE, | 77 content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE, |
67 resource_context_.release()); | 78 resource_context_.release()); |
68 } | 79 } |
69 } | 80 } |
70 | 81 |
82 void BlimpBrowserContext::Initialize() { | |
83 InitPrefService(); | |
84 BlimpMetricsServiceClient::GetInstance()->Initialize( | |
85 pref_service_.get(), | |
86 GetSystemRequestContextGetter()); | |
87 } | |
88 | |
89 void BlimpBrowserContext::Finalize() { | |
90 BlimpMetricsServiceClient::GetInstance()->Finalize(); | |
91 } | |
92 | |
71 void BlimpBrowserContext::InitWhileIOAllowed() { | 93 void BlimpBrowserContext::InitWhileIOAllowed() { |
72 // Ensures ~/.config/blimp_engine directory exists. | 94 // Ensures ~/.config/blimp_engine directory exists. |
73 std::unique_ptr<base::Environment> env(base::Environment::Create()); | 95 std::unique_ptr<base::Environment> env(base::Environment::Create()); |
74 base::FilePath config_dir(base::nix::GetXDGDirectory( | 96 base::FilePath config_dir(base::nix::GetXDGDirectory( |
75 env.get(), base::nix::kXdgConfigHomeEnvVar, base::nix::kDotConfigDir)); | 97 env.get(), base::nix::kXdgConfigHomeEnvVar, base::nix::kDotConfigDir)); |
76 path_ = config_dir.Append("blimp_engine"); | 98 path_ = config_dir.Append("blimp_engine"); |
77 if (!base::PathExists(path_)) | 99 if (!base::PathExists(path_)) |
78 base::CreateDirectory(path_); | 100 base::CreateDirectory(path_); |
79 BrowserContext::Initialize(this, path_); | 101 BrowserContext::Initialize(this, path_); |
80 } | 102 } |
81 | 103 |
104 void BlimpBrowserContext::InitPrefService() { | |
105 user_prefs::PrefRegistrySyncable* pref_registry = | |
Alexei Svitkine (slow)
2016/04/25 20:44:25
Nit: unique_ptr
Jess
2016/04/26 00:01:25
Unique ptr is not usable in this case since user_p
| |
106 new user_prefs::PrefRegistrySyncable(); | |
107 metrics::MetricsService::RegisterPrefs(pref_registry); | |
108 PrefServiceFactory pref_service_factory; | |
109 // The pref storage for metrics logs. | |
110 pref_service_factory.set_user_prefs(new InMemoryPrefStore()); | |
111 pref_service_factory.set_read_error_callback(base::Bind(&HandleReadError)); | |
112 pref_service_ = pref_service_factory.Create(pref_registry); | |
113 } | |
114 | |
82 std::unique_ptr<content::ZoomLevelDelegate> | 115 std::unique_ptr<content::ZoomLevelDelegate> |
83 BlimpBrowserContext::CreateZoomLevelDelegate(const base::FilePath&) { | 116 BlimpBrowserContext::CreateZoomLevelDelegate(const base::FilePath&) { |
84 return nullptr; | 117 return nullptr; |
85 } | 118 } |
86 | 119 |
87 base::FilePath BlimpBrowserContext::GetPath() const { | 120 base::FilePath BlimpBrowserContext::GetPath() const { |
88 return path_; | 121 return path_; |
89 } | 122 } |
90 | 123 |
91 bool BlimpBrowserContext::IsOffTheRecord() const { | 124 bool BlimpBrowserContext::IsOffTheRecord() const { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 | 200 |
168 net::URLRequestContextGetter* | 201 net::URLRequestContextGetter* |
169 BlimpBrowserContext::CreateMediaRequestContextForStoragePartition( | 202 BlimpBrowserContext::CreateMediaRequestContextForStoragePartition( |
170 const base::FilePath& partition_path, | 203 const base::FilePath& partition_path, |
171 bool in_memory) { | 204 bool in_memory) { |
172 return nullptr; | 205 return nullptr; |
173 } | 206 } |
174 | 207 |
175 } // namespace engine | 208 } // namespace engine |
176 } // namespace blimp | 209 } // namespace blimp |
OLD | NEW |