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 <set> | 7 #include <set> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 #include "net/extras/sqlite/sqlite_channel_id_store.h" | 42 #include "net/extras/sqlite/sqlite_channel_id_store.h" |
43 #include "net/http/http_cache.h" | 43 #include "net/http/http_cache.h" |
44 #include "net/http/http_network_session.h" | 44 #include "net/http/http_network_session.h" |
45 #include "net/http/http_server_properties_manager.h" | 45 #include "net/http/http_server_properties_manager.h" |
46 #include "net/sdch/sdch_owner.h" | 46 #include "net/sdch/sdch_owner.h" |
47 #include "net/ssl/channel_id_service.h" | 47 #include "net/ssl/channel_id_service.h" |
48 #include "net/ssl/default_channel_id_store.h" | 48 #include "net/ssl/default_channel_id_store.h" |
49 #include "net/url_request/url_request_intercepting_job_factory.h" | 49 #include "net/url_request/url_request_intercepting_job_factory.h" |
50 #include "net/url_request/url_request_job_factory_impl.h" | 50 #include "net/url_request/url_request_job_factory_impl.h" |
51 | 51 |
| 52 namespace { |
| 53 |
| 54 // Connects the SdchOwner's storage to the prefs. |
| 55 class SdchOwnerPrefStorage : public net::SdchOwner::PrefStorage, |
| 56 public PrefStore::Observer { |
| 57 public: |
| 58 explicit SdchOwnerPrefStorage(PersistentPrefStore* storage) |
| 59 : storage_(storage), storage_key_("SDCH"), init_observer_(nullptr) {} |
| 60 ~SdchOwnerPrefStorage() override { |
| 61 if (init_observer_) |
| 62 storage_->RemoveObserver(this); |
| 63 } |
| 64 |
| 65 ReadError GetReadError() const override { |
| 66 PersistentPrefStore::PrefReadError error = storage_->GetReadError(); |
| 67 |
| 68 DCHECK_NE( |
| 69 error, |
| 70 PersistentPrefStore::PREF_READ_ERROR_ASYNCHRONOUS_TASK_INCOMPLETE); |
| 71 DCHECK_NE(error, PersistentPrefStore::PREF_READ_ERROR_MAX_ENUM); |
| 72 |
| 73 switch (error) { |
| 74 case PersistentPrefStore::PREF_READ_ERROR_NONE: |
| 75 return PERSISTENCE_FAILURE_NONE; |
| 76 |
| 77 case PersistentPrefStore::PREF_READ_ERROR_NO_FILE: |
| 78 return PERSISTENCE_FAILURE_REASON_NO_FILE; |
| 79 |
| 80 case PersistentPrefStore::PREF_READ_ERROR_JSON_PARSE: |
| 81 case PersistentPrefStore::PREF_READ_ERROR_JSON_TYPE: |
| 82 case PersistentPrefStore::PREF_READ_ERROR_FILE_OTHER: |
| 83 case PersistentPrefStore::PREF_READ_ERROR_FILE_LOCKED: |
| 84 case PersistentPrefStore::PREF_READ_ERROR_JSON_REPEAT: |
| 85 return PERSISTENCE_FAILURE_REASON_READ_FAILED; |
| 86 |
| 87 case PersistentPrefStore::PREF_READ_ERROR_ACCESS_DENIED: |
| 88 case PersistentPrefStore::PREF_READ_ERROR_FILE_NOT_SPECIFIED: |
| 89 case PersistentPrefStore::PREF_READ_ERROR_ASYNCHRONOUS_TASK_INCOMPLETE: |
| 90 case PersistentPrefStore::PREF_READ_ERROR_MAX_ENUM: |
| 91 default: |
| 92 // We don't expect these other failures given our usage of prefs. |
| 93 NOTREACHED(); |
| 94 return PERSISTENCE_FAILURE_REASON_OTHER; |
| 95 } |
| 96 } |
| 97 |
| 98 bool GetValue(const base::DictionaryValue** result) const override { |
| 99 const base::Value* result_value = nullptr; |
| 100 if (!storage_->GetValue(storage_key_, &result_value)) |
| 101 return false; |
| 102 return result_value->GetAsDictionary(result); |
| 103 } |
| 104 |
| 105 bool GetMutableValue(base::DictionaryValue** result) override { |
| 106 base::Value* result_value = nullptr; |
| 107 if (!storage_->GetMutableValue(storage_key_, &result_value)) |
| 108 return false; |
| 109 return result_value->GetAsDictionary(result); |
| 110 } |
| 111 |
| 112 void SetValue(scoped_ptr<base::DictionaryValue> value) override { |
| 113 storage_->SetValue(storage_key_, std::move(value), |
| 114 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
| 115 } |
| 116 |
| 117 void ReportValueChanged() override { |
| 118 storage_->ReportValueChanged(storage_key_, |
| 119 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
| 120 } |
| 121 |
| 122 bool IsInitializationComplete() override { |
| 123 return storage_->IsInitializationComplete(); |
| 124 } |
| 125 |
| 126 void StartObservingInit(net::SdchOwner* observer) override { |
| 127 DCHECK(!init_observer_); |
| 128 init_observer_ = observer; |
| 129 storage_->AddObserver(this); |
| 130 } |
| 131 |
| 132 void StopObservingInit() override { |
| 133 DCHECK(init_observer_); |
| 134 init_observer_ = nullptr; |
| 135 storage_->RemoveObserver(this); |
| 136 } |
| 137 |
| 138 private: |
| 139 // PrefStore::Observer implementation. |
| 140 void OnPrefValueChanged(const std::string& key) override {} |
| 141 void OnInitializationCompleted(bool succeeded) override { |
| 142 init_observer_->OnPrefStorageInitializationComplete(succeeded); |
| 143 } |
| 144 |
| 145 PersistentPrefStore* storage_; // Non-owning. |
| 146 const std::string storage_key_; |
| 147 |
| 148 net::SdchOwner* init_observer_; // Non-owning. |
| 149 |
| 150 DISALLOW_COPY_AND_ASSIGN(SdchOwnerPrefStorage); |
| 151 }; |
| 152 |
| 153 } // namespace |
| 154 |
52 ChromeBrowserStateImplIOData::Handle::Handle( | 155 ChromeBrowserStateImplIOData::Handle::Handle( |
53 ios::ChromeBrowserState* browser_state) | 156 ios::ChromeBrowserState* browser_state) |
54 : io_data_(new ChromeBrowserStateImplIOData), | 157 : io_data_(new ChromeBrowserStateImplIOData), |
55 browser_state_(browser_state), | 158 browser_state_(browser_state), |
56 initialized_(false) { | 159 initialized_(false) { |
57 DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI); | 160 DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI); |
58 DCHECK(browser_state); | 161 DCHECK(browser_state); |
59 } | 162 } |
60 | 163 |
61 ChromeBrowserStateImplIOData::Handle::~Handle() { | 164 ChromeBrowserStateImplIOData::Handle::~Handle() { |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 std::move(request_interceptors), | 437 std::move(request_interceptors), |
335 main_context->network_delegate()); | 438 main_context->network_delegate()); |
336 main_context->set_job_factory(main_job_factory_.get()); | 439 main_context->set_job_factory(main_job_factory_.get()); |
337 main_context->set_network_quality_estimator( | 440 main_context->set_network_quality_estimator( |
338 io_thread_globals->network_quality_estimator.get()); | 441 io_thread_globals->network_quality_estimator.get()); |
339 | 442 |
340 // Setup SDCH for this profile. | 443 // Setup SDCH for this profile. |
341 sdch_manager_.reset(new net::SdchManager); | 444 sdch_manager_.reset(new net::SdchManager); |
342 sdch_policy_.reset(new net::SdchOwner(sdch_manager_.get(), main_context)); | 445 sdch_policy_.reset(new net::SdchOwner(sdch_manager_.get(), main_context)); |
343 main_context->set_sdch_manager(sdch_manager_.get()); | 446 main_context->set_sdch_manager(sdch_manager_.get()); |
344 sdch_policy_->EnablePersistentStorage(network_json_store_.get()); | 447 sdch_policy_->EnablePersistentStorage( |
| 448 make_scoped_ptr(new SdchOwnerPrefStorage(network_json_store_.get()))); |
345 | 449 |
346 lazy_params_.reset(); | 450 lazy_params_.reset(); |
347 } | 451 } |
348 | 452 |
349 net::URLRequestContext* | 453 net::URLRequestContext* |
350 ChromeBrowserStateImplIOData::InitializeAppRequestContext( | 454 ChromeBrowserStateImplIOData::InitializeAppRequestContext( |
351 net::URLRequestContext* main_context) const { | 455 net::URLRequestContext* main_context) const { |
352 // Copy most state from the main context. | 456 // Copy most state from the main context. |
353 AppRequestContext* context = new AppRequestContext(); | 457 AppRequestContext* context = new AppRequestContext(); |
354 context->CopyFrom(main_context); | 458 context->CopyFrom(main_context); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 const base::Closure& completion) { | 505 const base::Closure& completion) { |
402 DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::IO); | 506 DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::IO); |
403 DCHECK(initialized()); | 507 DCHECK(initialized()); |
404 | 508 |
405 DCHECK(transport_security_state()); | 509 DCHECK(transport_security_state()); |
406 // Completes synchronously. | 510 // Completes synchronously. |
407 transport_security_state()->DeleteAllDynamicDataSince(time); | 511 transport_security_state()->DeleteAllDynamicDataSince(time); |
408 DCHECK(http_server_properties_manager_); | 512 DCHECK(http_server_properties_manager_); |
409 http_server_properties_manager_->Clear(completion); | 513 http_server_properties_manager_->Clear(completion); |
410 } | 514 } |
OLD | NEW |