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

Side by Side Diff: blimp/engine/common/blimp_browser_context.cc

Issue 2629743003: Remove all blimp engine code (Closed)
Patch Set: Use consistent comment style in //chrome Created 3 years, 11 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "blimp/engine/common/blimp_browser_context.h"
6
7 #include "base/bind.h"
8 #include "base/environment.h"
9 #include "base/files/file_util.h"
10 #include "base/memory/ptr_util.h"
11 #include "base/nix/xdg_util.h"
12 #include "base/path_service.h"
13 #include "blimp/engine/app/blimp_permission_manager.h"
14 #include "components/metrics/metrics_service.h"
15 #include "components/metrics/stability_metrics_helper.h"
16 #include "components/pref_registry/pref_registry_syncable.h"
17 #include "components/prefs/in_memory_pref_store.h"
18 #include "components/prefs/pref_service.h"
19 #include "components/prefs/pref_service_factory.h"
20 #include "content/public/browser/background_sync_controller.h"
21 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/storage_partition.h"
23 #include "content/public/common/content_switches.h"
24
25 namespace {
26 // Function for optionally handling read errors. Is a no-op for Blimp.
27 // While the PersistentPrefStore's interface is supported, it is an in-memory
28 // store only.
29 void IgnoreReadError(PersistentPrefStore::PrefReadError error) {}
30 } // namespace
31
32 namespace blimp {
33 namespace engine {
34
35 // Contains URLRequestContextGetter required for resource loading.
36 class BlimpResourceContext : public content::ResourceContext {
37 public:
38 BlimpResourceContext() {}
39 ~BlimpResourceContext() override {}
40
41 void set_url_request_context_getter(
42 const scoped_refptr<BlimpURLRequestContextGetter>& getter) {
43 getter_ = getter;
44 }
45
46 const scoped_refptr<BlimpURLRequestContextGetter>&
47 url_request_context_getter() {
48 return getter_;
49 }
50
51 // content::ResourceContext implementation.
52 net::HostResolver* GetHostResolver() override;
53 net::URLRequestContext* GetRequestContext() override;
54
55 private:
56 scoped_refptr<BlimpURLRequestContextGetter> getter_;
57
58 DISALLOW_COPY_AND_ASSIGN(BlimpResourceContext);
59 };
60
61 net::HostResolver* BlimpResourceContext::GetHostResolver() {
62 return getter_->host_resolver();
63 }
64
65 net::URLRequestContext* BlimpResourceContext::GetRequestContext() {
66 return getter_->GetURLRequestContext();
67 }
68
69 BlimpBrowserContext::BlimpBrowserContext(bool off_the_record,
70 net::NetLog* net_log)
71 : resource_context_(new BlimpResourceContext),
72 ignore_certificate_errors_(false),
73 off_the_record_(off_the_record),
74 net_log_(net_log) {
75 InitWhileIOAllowed();
76 InitPrefService();
77 metrics_service_client_.reset(
78 new BlimpMetricsServiceClient(pref_service_.get(),
79 GetSystemRequestContextGetter()));
80 }
81
82 BlimpBrowserContext::~BlimpBrowserContext() {
83 ShutdownStoragePartitions();
84 if (resource_context_) {
85 content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE,
86 resource_context_.release());
87 }
88 }
89
90 void BlimpBrowserContext::InitWhileIOAllowed() {
91 // Ensures ~/.config/blimp_engine directory exists.
92 std::unique_ptr<base::Environment> env(base::Environment::Create());
93 base::FilePath config_dir(base::nix::GetXDGDirectory(
94 env.get(), base::nix::kXdgConfigHomeEnvVar, base::nix::kDotConfigDir));
95 path_ = config_dir.Append("blimp_engine");
96 if (!base::PathExists(path_))
97 base::CreateDirectory(path_);
98 BrowserContext::Initialize(this, path_);
99 }
100
101 void BlimpBrowserContext::InitPrefService() {
102 // Create PrefRegistry and register metrics services preferences with it.
103 scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry(
104 new user_prefs::PrefRegistrySyncable());
105 metrics::MetricsService::RegisterPrefs(pref_registry.get());
106 metrics::StabilityMetricsHelper::RegisterPrefs(pref_registry.get());
107
108 PrefServiceFactory pref_service_factory;
109
110 // Create an in memory preferences store to hold metrics logs.
111 pref_service_factory.set_user_prefs(new InMemoryPrefStore());
112 pref_service_factory.set_read_error_callback(base::Bind(&IgnoreReadError));
113
114 // Create a PrefService binding the PrefRegistry to the InMemoryPrefStore.
115 // The PrefService ends up owning the PrefRegistry and the InMemoryPrefStore.
116 pref_service_ = pref_service_factory.Create(pref_registry.get());
117 DCHECK(pref_service_.get());
118 }
119
120 std::unique_ptr<content::ZoomLevelDelegate>
121 BlimpBrowserContext::CreateZoomLevelDelegate(const base::FilePath&) {
122 return nullptr;
123 }
124
125 base::FilePath BlimpBrowserContext::GetPath() const {
126 return path_;
127 }
128
129 bool BlimpBrowserContext::IsOffTheRecord() const {
130 return off_the_record_;
131 }
132
133 content::DownloadManagerDelegate*
134 BlimpBrowserContext::GetDownloadManagerDelegate() {
135 return nullptr;
136 }
137
138 net::URLRequestContextGetter*
139 BlimpBrowserContext::GetSystemRequestContextGetter() {
140 if (!system_context_getter_) {
141 system_context_getter_ = new BlimpSystemURLRequestContextGetter();
142 }
143 return system_context_getter_.get();
144 }
145
146 content::ResourceContext* BlimpBrowserContext::GetResourceContext() {
147 return resource_context_.get();
148 }
149
150 content::BrowserPluginGuestManager* BlimpBrowserContext::GetGuestManager() {
151 return nullptr;
152 }
153
154 storage::SpecialStoragePolicy* BlimpBrowserContext::GetSpecialStoragePolicy() {
155 return nullptr;
156 }
157
158 content::PushMessagingService* BlimpBrowserContext::GetPushMessagingService() {
159 return nullptr;
160 }
161
162 content::SSLHostStateDelegate* BlimpBrowserContext::GetSSLHostStateDelegate() {
163 return nullptr;
164 }
165
166 content::PermissionManager* BlimpBrowserContext::GetPermissionManager() {
167 if (!permission_manager_)
168 permission_manager_.reset(new BlimpPermissionManager());
169 return permission_manager_.get();
170 }
171
172 content::BackgroundSyncController*
173 BlimpBrowserContext::GetBackgroundSyncController() {
174 return nullptr;
175 }
176
177 net::URLRequestContextGetter* BlimpBrowserContext::CreateRequestContext(
178 content::ProtocolHandlerMap* protocol_handlers,
179 content::URLRequestInterceptorScopedVector request_interceptors) {
180 DCHECK(!resource_context_->url_request_context_getter());
181 // net_log_ is owned by BrowserMainParts.
182 resource_context_->set_url_request_context_getter(
183 new BlimpURLRequestContextGetter(
184 ignore_certificate_errors_, GetPath(),
185 content::BrowserThread::GetTaskRunnerForThread(
186 content::BrowserThread::IO),
187 content::BrowserThread::GetTaskRunnerForThread(
188 content::BrowserThread::FILE),
189 protocol_handlers, std::move(request_interceptors), net_log_));
190 return resource_context_->url_request_context_getter().get();
191 }
192
193 net::URLRequestContextGetter*
194 BlimpBrowserContext::CreateRequestContextForStoragePartition(
195 const base::FilePath& partition_path,
196 bool in_memory,
197 content::ProtocolHandlerMap* protocol_handlers,
198 content::URLRequestInterceptorScopedVector request_interceptors) {
199 return nullptr;
200 }
201
202 net::URLRequestContextGetter* BlimpBrowserContext::CreateMediaRequestContext() {
203 return resource_context_->url_request_context_getter().get();
204 }
205
206 net::URLRequestContextGetter*
207 BlimpBrowserContext::CreateMediaRequestContextForStoragePartition(
208 const base::FilePath& partition_path,
209 bool in_memory) {
210 return nullptr;
211 }
212
213 } // namespace engine
214 } // namespace blimp
OLDNEW
« 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