| 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 "ios/chrome/browser/browser_state/chrome_browser_state_impl_io_data.h" | 5 #include "ios/chrome/browser/browser_state/chrome_browser_state_impl_io_data.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "ios/chrome/browser/chrome_constants.h" | 24 #include "ios/chrome/browser/chrome_constants.h" |
| 25 #include "ios/chrome/browser/ios_chrome_io_thread.h" | 25 #include "ios/chrome/browser/ios_chrome_io_thread.h" |
| 26 #include "ios/chrome/browser/net/cookie_util.h" | 26 #include "ios/chrome/browser/net/cookie_util.h" |
| 27 #include "ios/chrome/browser/net/http_server_properties_manager_factory.h" | 27 #include "ios/chrome/browser/net/http_server_properties_manager_factory.h" |
| 28 #include "ios/chrome/browser/net/ios_chrome_network_delegate.h" | 28 #include "ios/chrome/browser/net/ios_chrome_network_delegate.h" |
| 29 #include "ios/chrome/browser/net/ios_chrome_url_request_context_getter.h" | 29 #include "ios/chrome/browser/net/ios_chrome_url_request_context_getter.h" |
| 30 #include "ios/chrome/browser/pref_names.h" | 30 #include "ios/chrome/browser/pref_names.h" |
| 31 #include "ios/net/cookies/cookie_store_ios.h" | 31 #include "ios/net/cookies/cookie_store_ios.h" |
| 32 #include "ios/web/public/web_thread.h" | 32 #include "ios/web/public/web_thread.h" |
| 33 #include "net/base/cache_type.h" | 33 #include "net/base/cache_type.h" |
| 34 #include "net/base/sdch_manager.h" | |
| 35 #include "net/cookies/cookie_store.h" | 34 #include "net/cookies/cookie_store.h" |
| 36 #include "net/extras/sqlite/sqlite_channel_id_store.h" | 35 #include "net/extras/sqlite/sqlite_channel_id_store.h" |
| 37 #include "net/http/http_cache.h" | 36 #include "net/http/http_cache.h" |
| 38 #include "net/http/http_network_session.h" | 37 #include "net/http/http_network_session.h" |
| 39 #include "net/http/http_server_properties_manager.h" | 38 #include "net/http/http_server_properties_manager.h" |
| 40 #include "net/sdch/sdch_owner.h" | |
| 41 #include "net/ssl/channel_id_service.h" | 39 #include "net/ssl/channel_id_service.h" |
| 42 #include "net/ssl/default_channel_id_store.h" | 40 #include "net/ssl/default_channel_id_store.h" |
| 43 #include "net/url_request/url_request_intercepting_job_factory.h" | 41 #include "net/url_request/url_request_intercepting_job_factory.h" |
| 44 #include "net/url_request/url_request_job_factory_impl.h" | 42 #include "net/url_request/url_request_job_factory_impl.h" |
| 45 | 43 |
| 46 #if !defined(__has_feature) || !__has_feature(objc_arc) | 44 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 47 #error "This file requires ARC support." | 45 #error "This file requires ARC support." |
| 48 #endif | 46 #endif |
| 49 | 47 |
| 50 namespace { | |
| 51 | |
| 52 // Connects the SdchOwner's storage to the prefs. | |
| 53 class SdchOwnerPrefStorage : public net::SdchOwner::PrefStorage, | |
| 54 public PrefStore::Observer { | |
| 55 public: | |
| 56 explicit SdchOwnerPrefStorage(PersistentPrefStore* storage) | |
| 57 : storage_(storage), storage_key_("SDCH"), init_observer_(nullptr) {} | |
| 58 ~SdchOwnerPrefStorage() override { | |
| 59 if (init_observer_) | |
| 60 storage_->RemoveObserver(this); | |
| 61 } | |
| 62 | |
| 63 ReadError GetReadError() const override { | |
| 64 PersistentPrefStore::PrefReadError error = storage_->GetReadError(); | |
| 65 | |
| 66 DCHECK_NE( | |
| 67 error, | |
| 68 PersistentPrefStore::PREF_READ_ERROR_ASYNCHRONOUS_TASK_INCOMPLETE); | |
| 69 DCHECK_NE(error, PersistentPrefStore::PREF_READ_ERROR_MAX_ENUM); | |
| 70 | |
| 71 switch (error) { | |
| 72 case PersistentPrefStore::PREF_READ_ERROR_NONE: | |
| 73 return PERSISTENCE_FAILURE_NONE; | |
| 74 | |
| 75 case PersistentPrefStore::PREF_READ_ERROR_NO_FILE: | |
| 76 return PERSISTENCE_FAILURE_REASON_NO_FILE; | |
| 77 | |
| 78 case PersistentPrefStore::PREF_READ_ERROR_JSON_PARSE: | |
| 79 case PersistentPrefStore::PREF_READ_ERROR_JSON_TYPE: | |
| 80 case PersistentPrefStore::PREF_READ_ERROR_FILE_OTHER: | |
| 81 case PersistentPrefStore::PREF_READ_ERROR_FILE_LOCKED: | |
| 82 case PersistentPrefStore::PREF_READ_ERROR_JSON_REPEAT: | |
| 83 return PERSISTENCE_FAILURE_REASON_READ_FAILED; | |
| 84 | |
| 85 case PersistentPrefStore::PREF_READ_ERROR_ACCESS_DENIED: | |
| 86 case PersistentPrefStore::PREF_READ_ERROR_FILE_NOT_SPECIFIED: | |
| 87 case PersistentPrefStore::PREF_READ_ERROR_ASYNCHRONOUS_TASK_INCOMPLETE: | |
| 88 case PersistentPrefStore::PREF_READ_ERROR_MAX_ENUM: | |
| 89 default: | |
| 90 // We don't expect these other failures given our usage of prefs. | |
| 91 NOTREACHED(); | |
| 92 return PERSISTENCE_FAILURE_REASON_OTHER; | |
| 93 } | |
| 94 } | |
| 95 | |
| 96 bool GetValue(const base::DictionaryValue** result) const override { | |
| 97 const base::Value* result_value = nullptr; | |
| 98 if (!storage_->GetValue(storage_key_, &result_value)) | |
| 99 return false; | |
| 100 return result_value->GetAsDictionary(result); | |
| 101 } | |
| 102 | |
| 103 bool GetMutableValue(base::DictionaryValue** result) override { | |
| 104 base::Value* result_value = nullptr; | |
| 105 if (!storage_->GetMutableValue(storage_key_, &result_value)) | |
| 106 return false; | |
| 107 return result_value->GetAsDictionary(result); | |
| 108 } | |
| 109 | |
| 110 void SetValue(std::unique_ptr<base::DictionaryValue> value) override { | |
| 111 storage_->SetValue(storage_key_, std::move(value), | |
| 112 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | |
| 113 } | |
| 114 | |
| 115 void ReportValueChanged() override { | |
| 116 storage_->ReportValueChanged(storage_key_, | |
| 117 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | |
| 118 } | |
| 119 | |
| 120 bool IsInitializationComplete() override { | |
| 121 return storage_->IsInitializationComplete(); | |
| 122 } | |
| 123 | |
| 124 void StartObservingInit(net::SdchOwner* observer) override { | |
| 125 DCHECK(!init_observer_); | |
| 126 init_observer_ = observer; | |
| 127 storage_->AddObserver(this); | |
| 128 } | |
| 129 | |
| 130 void StopObservingInit() override { | |
| 131 DCHECK(init_observer_); | |
| 132 init_observer_ = nullptr; | |
| 133 storage_->RemoveObserver(this); | |
| 134 } | |
| 135 | |
| 136 private: | |
| 137 // PrefStore::Observer implementation. | |
| 138 void OnPrefValueChanged(const std::string& key) override {} | |
| 139 void OnInitializationCompleted(bool succeeded) override { | |
| 140 init_observer_->OnPrefStorageInitializationComplete(succeeded); | |
| 141 } | |
| 142 | |
| 143 PersistentPrefStore* storage_; // Non-owning. | |
| 144 const std::string storage_key_; | |
| 145 | |
| 146 net::SdchOwner* init_observer_; // Non-owning. | |
| 147 | |
| 148 DISALLOW_COPY_AND_ASSIGN(SdchOwnerPrefStorage); | |
| 149 }; | |
| 150 | |
| 151 } // namespace | |
| 152 | |
| 153 ChromeBrowserStateImplIOData::Handle::Handle( | 48 ChromeBrowserStateImplIOData::Handle::Handle( |
| 154 ios::ChromeBrowserState* browser_state) | 49 ios::ChromeBrowserState* browser_state) |
| 155 : io_data_(new ChromeBrowserStateImplIOData), | 50 : io_data_(new ChromeBrowserStateImplIOData), |
| 156 browser_state_(browser_state), | 51 browser_state_(browser_state), |
| 157 initialized_(false) { | 52 initialized_(false) { |
| 158 DCHECK_CURRENTLY_ON(web::WebThread::UI); | 53 DCHECK_CURRENTLY_ON(web::WebThread::UI); |
| 159 DCHECK(browser_state); | 54 DCHECK(browser_state); |
| 160 } | 55 } |
| 161 | 56 |
| 162 ChromeBrowserStateImplIOData::Handle::~Handle() { | 57 ChromeBrowserStateImplIOData::Handle::~Handle() { |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 std::unique_ptr<net::URLRequestJobFactoryImpl> main_job_factory( | 283 std::unique_ptr<net::URLRequestJobFactoryImpl> main_job_factory( |
| 389 new net::URLRequestJobFactoryImpl()); | 284 new net::URLRequestJobFactoryImpl()); |
| 390 InstallProtocolHandlers(main_job_factory.get(), protocol_handlers); | 285 InstallProtocolHandlers(main_job_factory.get(), protocol_handlers); |
| 391 | 286 |
| 392 main_job_factory_ = SetUpJobFactoryDefaults(std::move(main_job_factory), | 287 main_job_factory_ = SetUpJobFactoryDefaults(std::move(main_job_factory), |
| 393 main_context->network_delegate()); | 288 main_context->network_delegate()); |
| 394 main_context->set_job_factory(main_job_factory_.get()); | 289 main_context->set_job_factory(main_job_factory_.get()); |
| 395 main_context->set_network_quality_estimator( | 290 main_context->set_network_quality_estimator( |
| 396 io_thread_globals->network_quality_estimator.get()); | 291 io_thread_globals->network_quality_estimator.get()); |
| 397 | 292 |
| 398 // Setup SDCH for this profile. | |
| 399 sdch_manager_.reset(new net::SdchManager); | |
| 400 sdch_policy_.reset(new net::SdchOwner(sdch_manager_.get(), main_context)); | |
| 401 main_context->set_sdch_manager(sdch_manager_.get()); | |
| 402 sdch_policy_->EnablePersistentStorage( | |
| 403 base::MakeUnique<SdchOwnerPrefStorage>(network_json_store_.get())); | |
| 404 | |
| 405 lazy_params_.reset(); | 293 lazy_params_.reset(); |
| 406 } | 294 } |
| 407 | 295 |
| 408 ChromeBrowserStateIOData::AppRequestContext* | 296 ChromeBrowserStateIOData::AppRequestContext* |
| 409 ChromeBrowserStateImplIOData::InitializeAppRequestContext( | 297 ChromeBrowserStateImplIOData::InitializeAppRequestContext( |
| 410 net::URLRequestContext* main_context) const { | 298 net::URLRequestContext* main_context) const { |
| 411 // Copy most state from the main context. | 299 // Copy most state from the main context. |
| 412 AppRequestContext* context = new AppRequestContext(); | 300 AppRequestContext* context = new AppRequestContext(); |
| 413 context->CopyFrom(main_context); | 301 context->CopyFrom(main_context); |
| 414 | 302 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 const base::Closure& completion) { | 356 const base::Closure& completion) { |
| 469 DCHECK_CURRENTLY_ON(web::WebThread::IO); | 357 DCHECK_CURRENTLY_ON(web::WebThread::IO); |
| 470 DCHECK(initialized()); | 358 DCHECK(initialized()); |
| 471 | 359 |
| 472 DCHECK(transport_security_state()); | 360 DCHECK(transport_security_state()); |
| 473 // Completes synchronously. | 361 // Completes synchronously. |
| 474 transport_security_state()->DeleteAllDynamicDataSince(time); | 362 transport_security_state()->DeleteAllDynamicDataSince(time); |
| 475 DCHECK(http_server_properties_manager_); | 363 DCHECK(http_server_properties_manager_); |
| 476 http_server_properties_manager_->Clear(completion); | 364 http_server_properties_manager_->Clear(completion); |
| 477 } | 365 } |
| OLD | NEW |