| 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/memory/ptr_util.h" | |
| 11 #include "base/nix/xdg_util.h" | 10 #include "base/nix/xdg_util.h" |
| 12 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 13 #include "blimp/engine/app/blimp_permission_manager.h" | 12 #include "blimp/engine/app/blimp_permission_manager.h" |
| 14 #include "components/metrics/metrics_service.h" | |
| 15 #include "components/pref_registry/pref_registry_syncable.h" | |
| 16 #include "components/prefs/in_memory_pref_store.h" | |
| 17 #include "components/prefs/pref_service.h" | |
| 18 #include "components/prefs/pref_service_factory.h" | |
| 19 #include "content/public/browser/background_sync_controller.h" | 13 #include "content/public/browser/background_sync_controller.h" |
| 20 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/browser/storage_partition.h" | 15 #include "content/public/browser/storage_partition.h" |
| 22 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
| 23 | 17 |
| 24 namespace { | |
| 25 // Function for optionally handling read errors. Is a no-op for Blimp. | |
| 26 // While the PersistentPrefStore's interface is supported, it is an in-memory | |
| 27 // store only. | |
| 28 void IgnoreReadError(PersistentPrefStore::PrefReadError error) {} | |
| 29 } // namespace | |
| 30 | |
| 31 namespace blimp { | 18 namespace blimp { |
| 32 namespace engine { | 19 namespace engine { |
| 33 | 20 |
| 34 // Contains URLRequestContextGetter required for resource loading. | 21 // Contains URLRequestContextGetter required for resource loading. |
| 35 class BlimpResourceContext : public content::ResourceContext { | 22 class BlimpResourceContext : public content::ResourceContext { |
| 36 public: | 23 public: |
| 37 BlimpResourceContext() {} | 24 BlimpResourceContext() {} |
| 38 ~BlimpResourceContext() override {} | 25 ~BlimpResourceContext() override {} |
| 39 | 26 |
| 40 void set_url_request_context_getter( | 27 void set_url_request_context_getter( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 65 return getter_->GetURLRequestContext(); | 52 return getter_->GetURLRequestContext(); |
| 66 } | 53 } |
| 67 | 54 |
| 68 BlimpBrowserContext::BlimpBrowserContext(bool off_the_record, | 55 BlimpBrowserContext::BlimpBrowserContext(bool off_the_record, |
| 69 net::NetLog* net_log) | 56 net::NetLog* net_log) |
| 70 : resource_context_(new BlimpResourceContext), | 57 : resource_context_(new BlimpResourceContext), |
| 71 ignore_certificate_errors_(false), | 58 ignore_certificate_errors_(false), |
| 72 off_the_record_(off_the_record), | 59 off_the_record_(off_the_record), |
| 73 net_log_(net_log) { | 60 net_log_(net_log) { |
| 74 InitWhileIOAllowed(); | 61 InitWhileIOAllowed(); |
| 75 InitializeBlimpMetrics(GetPrefService(), GetSystemRequestContextGetter()); | |
| 76 } | 62 } |
| 77 | 63 |
| 78 BlimpBrowserContext::~BlimpBrowserContext() { | 64 BlimpBrowserContext::~BlimpBrowserContext() { |
| 79 FinalizeBlimpMetrics(); | |
| 80 if (resource_context_) { | 65 if (resource_context_) { |
| 81 content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE, | 66 content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE, |
| 82 resource_context_.release()); | 67 resource_context_.release()); |
| 83 } | 68 } |
| 84 } | 69 } |
| 85 | 70 |
| 86 void BlimpBrowserContext::InitWhileIOAllowed() { | 71 void BlimpBrowserContext::InitWhileIOAllowed() { |
| 87 // Ensures ~/.config/blimp_engine directory exists. | 72 // Ensures ~/.config/blimp_engine directory exists. |
| 88 std::unique_ptr<base::Environment> env(base::Environment::Create()); | 73 std::unique_ptr<base::Environment> env(base::Environment::Create()); |
| 89 base::FilePath config_dir(base::nix::GetXDGDirectory( | 74 base::FilePath config_dir(base::nix::GetXDGDirectory( |
| 90 env.get(), base::nix::kXdgConfigHomeEnvVar, base::nix::kDotConfigDir)); | 75 env.get(), base::nix::kXdgConfigHomeEnvVar, base::nix::kDotConfigDir)); |
| 91 path_ = config_dir.Append("blimp_engine"); | 76 path_ = config_dir.Append("blimp_engine"); |
| 92 if (!base::PathExists(path_)) | 77 if (!base::PathExists(path_)) |
| 93 base::CreateDirectory(path_); | 78 base::CreateDirectory(path_); |
| 94 BrowserContext::Initialize(this, path_); | 79 BrowserContext::Initialize(this, path_); |
| 95 } | 80 } |
| 96 | 81 |
| 97 std::unique_ptr<PrefService> BlimpBrowserContext::GetPrefService() { | |
| 98 // Create PrefRegistry and register metrics services preferences with it. | |
| 99 scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry( | |
| 100 new user_prefs::PrefRegistrySyncable()); | |
| 101 metrics::MetricsService::RegisterPrefs(pref_registry.get()); | |
| 102 PrefServiceFactory pref_service_factory; | |
| 103 | |
| 104 // Create an in memory preferences store to hold metrics logs. | |
| 105 pref_service_factory.set_user_prefs(new InMemoryPrefStore()); | |
| 106 pref_service_factory.set_read_error_callback(base::Bind(&IgnoreReadError)); | |
| 107 | |
| 108 // Create a PrefService binding the PrefRegistry to the InMemoryPrefStore. | |
| 109 // The PrefService ends up owning the PrefRegistry and the InMemoryPrefStore. | |
| 110 return pref_service_factory.Create(pref_registry.get()); | |
| 111 } | |
| 112 | |
| 113 std::unique_ptr<content::ZoomLevelDelegate> | 82 std::unique_ptr<content::ZoomLevelDelegate> |
| 114 BlimpBrowserContext::CreateZoomLevelDelegate(const base::FilePath&) { | 83 BlimpBrowserContext::CreateZoomLevelDelegate(const base::FilePath&) { |
| 115 return nullptr; | 84 return nullptr; |
| 116 } | 85 } |
| 117 | 86 |
| 118 base::FilePath BlimpBrowserContext::GetPath() const { | 87 base::FilePath BlimpBrowserContext::GetPath() const { |
| 119 return path_; | 88 return path_; |
| 120 } | 89 } |
| 121 | 90 |
| 122 bool BlimpBrowserContext::IsOffTheRecord() const { | 91 bool BlimpBrowserContext::IsOffTheRecord() const { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 | 167 |
| 199 net::URLRequestContextGetter* | 168 net::URLRequestContextGetter* |
| 200 BlimpBrowserContext::CreateMediaRequestContextForStoragePartition( | 169 BlimpBrowserContext::CreateMediaRequestContextForStoragePartition( |
| 201 const base::FilePath& partition_path, | 170 const base::FilePath& partition_path, |
| 202 bool in_memory) { | 171 bool in_memory) { |
| 203 return nullptr; | 172 return nullptr; |
| 204 } | 173 } |
| 205 | 174 |
| 206 } // namespace engine | 175 } // namespace engine |
| 207 } // namespace blimp | 176 } // namespace blimp |
| OLD | NEW |