OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/cronet/android/cronet_url_request_context_adapter.h" | 5 #include "components/cronet/android/cronet_url_request_context_adapter.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <map> | 9 #include <map> |
10 #include <utility> | 10 #include <utility> |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 } | 87 } |
88 | 88 |
89 private: | 89 private: |
90 PrefService* pref_service_; | 90 PrefService* pref_service_; |
91 std::string path_; | 91 std::string path_; |
92 PrefChangeRegistrar pref_change_registrar_; | 92 PrefChangeRegistrar pref_change_registrar_; |
93 | 93 |
94 DISALLOW_COPY_AND_ASSIGN(PrefServiceAdapter); | 94 DISALLOW_COPY_AND_ASSIGN(PrefServiceAdapter); |
95 }; | 95 }; |
96 | 96 |
| 97 // Connects the SdchOwner's storage to the prefs. |
| 98 class SdchOwnerPrefStorage : public net::SdchOwner::PrefStorage, |
| 99 public PrefStore::Observer { |
| 100 public: |
| 101 explicit SdchOwnerPrefStorage(PersistentPrefStore* storage) |
| 102 : storage_(storage), storage_key_("SDCH"), init_observer_(nullptr) {} |
| 103 ~SdchOwnerPrefStorage() override { |
| 104 if (init_observer_) |
| 105 storage_->RemoveObserver(this); |
| 106 } |
| 107 |
| 108 ReadError GetReadError() const override { |
| 109 PersistentPrefStore::PrefReadError error = storage_->GetReadError(); |
| 110 |
| 111 DCHECK_NE( |
| 112 error, |
| 113 PersistentPrefStore::PREF_READ_ERROR_ASYNCHRONOUS_TASK_INCOMPLETE); |
| 114 DCHECK_NE(error, PersistentPrefStore::PREF_READ_ERROR_MAX_ENUM); |
| 115 |
| 116 switch (error) { |
| 117 case PersistentPrefStore::PREF_READ_ERROR_NONE: |
| 118 return PERSISTENCE_FAILURE_NONE; |
| 119 |
| 120 case PersistentPrefStore::PREF_READ_ERROR_NO_FILE: |
| 121 return PERSISTENCE_FAILURE_REASON_NO_FILE; |
| 122 |
| 123 case PersistentPrefStore::PREF_READ_ERROR_JSON_PARSE: |
| 124 case PersistentPrefStore::PREF_READ_ERROR_JSON_TYPE: |
| 125 case PersistentPrefStore::PREF_READ_ERROR_FILE_OTHER: |
| 126 case PersistentPrefStore::PREF_READ_ERROR_FILE_LOCKED: |
| 127 case PersistentPrefStore::PREF_READ_ERROR_JSON_REPEAT: |
| 128 return PERSISTENCE_FAILURE_REASON_READ_FAILED; |
| 129 |
| 130 case PersistentPrefStore::PREF_READ_ERROR_ACCESS_DENIED: |
| 131 case PersistentPrefStore::PREF_READ_ERROR_FILE_NOT_SPECIFIED: |
| 132 case PersistentPrefStore::PREF_READ_ERROR_ASYNCHRONOUS_TASK_INCOMPLETE: |
| 133 case PersistentPrefStore::PREF_READ_ERROR_MAX_ENUM: |
| 134 default: |
| 135 // We don't expect these other failures given our usage of prefs. |
| 136 NOTREACHED(); |
| 137 return PERSISTENCE_FAILURE_REASON_OTHER; |
| 138 } |
| 139 } |
| 140 |
| 141 bool GetValue(const base::DictionaryValue** result) const override { |
| 142 const base::Value* result_value = nullptr; |
| 143 if (!storage_->GetValue(storage_key_, &result_value)) |
| 144 return false; |
| 145 return result_value->GetAsDictionary(result); |
| 146 } |
| 147 |
| 148 bool GetMutableValue(base::DictionaryValue** result) override { |
| 149 base::Value* result_value = nullptr; |
| 150 if (!storage_->GetMutableValue(storage_key_, &result_value)) |
| 151 return false; |
| 152 return result_value->GetAsDictionary(result); |
| 153 } |
| 154 |
| 155 void SetValue(scoped_ptr<base::DictionaryValue> value) override { |
| 156 storage_->SetValue(storage_key_, std::move(value), |
| 157 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
| 158 } |
| 159 |
| 160 void ReportValueChanged() override { |
| 161 storage_->ReportValueChanged(storage_key_, |
| 162 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
| 163 } |
| 164 |
| 165 bool IsInitializationComplete() override { |
| 166 return storage_->IsInitializationComplete(); |
| 167 } |
| 168 |
| 169 void StartObservingInit(net::SdchOwner* observer) override { |
| 170 DCHECK(!init_observer_); |
| 171 init_observer_ = observer; |
| 172 storage_->AddObserver(this); |
| 173 } |
| 174 |
| 175 void StopObservingInit() override { |
| 176 DCHECK(init_observer_); |
| 177 init_observer_ = nullptr; |
| 178 storage_->RemoveObserver(this); |
| 179 } |
| 180 |
| 181 private: |
| 182 // PrefStore::Observer implementation. |
| 183 void OnPrefValueChanged(const std::string& key) override {} |
| 184 void OnInitializationCompleted(bool succeeded) override { |
| 185 init_observer_->OnPrefStorageInitializationComplete(succeeded); |
| 186 } |
| 187 |
| 188 PersistentPrefStore* storage_; // Non-owning. |
| 189 const std::string storage_key_; |
| 190 |
| 191 net::SdchOwner* init_observer_; // Non-owning. |
| 192 |
| 193 DISALLOW_COPY_AND_ASSIGN(SdchOwnerPrefStorage); |
| 194 }; |
| 195 |
97 class BasicNetworkDelegate : public net::NetworkDelegateImpl { | 196 class BasicNetworkDelegate : public net::NetworkDelegateImpl { |
98 public: | 197 public: |
99 BasicNetworkDelegate() {} | 198 BasicNetworkDelegate() {} |
100 ~BasicNetworkDelegate() override {} | 199 ~BasicNetworkDelegate() override {} |
101 | 200 |
102 private: | 201 private: |
103 // net::NetworkDelegate implementation. | 202 // net::NetworkDelegate implementation. |
104 int OnBeforeURLRequest(net::URLRequest* request, | 203 int OnBeforeURLRequest(net::URLRequest* request, |
105 const net::CompletionCallback& callback, | 204 const net::CompletionCallback& callback, |
106 GURL* new_url) override { | 205 GURL* new_url) override { |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 | 469 |
371 default_load_flags_ = net::LOAD_DO_NOT_SAVE_COOKIES | | 470 default_load_flags_ = net::LOAD_DO_NOT_SAVE_COOKIES | |
372 net::LOAD_DO_NOT_SEND_COOKIES; | 471 net::LOAD_DO_NOT_SEND_COOKIES; |
373 if (config->load_disable_cache) | 472 if (config->load_disable_cache) |
374 default_load_flags_ |= net::LOAD_DISABLE_CACHE; | 473 default_load_flags_ |= net::LOAD_DISABLE_CACHE; |
375 | 474 |
376 if (config->enable_sdch) { | 475 if (config->enable_sdch) { |
377 DCHECK(context_->sdch_manager()); | 476 DCHECK(context_->sdch_manager()); |
378 sdch_owner_.reset( | 477 sdch_owner_.reset( |
379 new net::SdchOwner(context_->sdch_manager(), context_.get())); | 478 new net::SdchOwner(context_->sdch_manager(), context_.get())); |
380 if (json_pref_store_) | 479 if (json_pref_store_) { |
381 sdch_owner_->EnablePersistentStorage(json_pref_store_.get()); | 480 sdch_owner_->EnablePersistentStorage( |
| 481 make_scoped_ptr(new SdchOwnerPrefStorage(json_pref_store_.get()))); |
| 482 } |
382 } | 483 } |
383 | 484 |
384 // Currently (circa M39) enabling QUIC requires setting probability threshold. | 485 // Currently (circa M39) enabling QUIC requires setting probability threshold. |
385 if (config->enable_quic) { | 486 if (config->enable_quic) { |
386 context_->http_server_properties() | 487 context_->http_server_properties() |
387 ->SetAlternativeServiceProbabilityThreshold(0.0f); | 488 ->SetAlternativeServiceProbabilityThreshold(0.0f); |
388 for (auto hint = config->quic_hints.begin(); | 489 for (auto hint = config->quic_hints.begin(); |
389 hint != config->quic_hints.end(); ++hint) { | 490 hint != config->quic_hints.end(); ++hint) { |
390 const URLRequestContextConfig::QuicHint& quic_hint = **hint; | 491 const URLRequestContextConfig::QuicHint& quic_hint = **hint; |
391 if (quic_hint.host.empty()) { | 492 if (quic_hint.host.empty()) { |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 JNIEnv* env, | 798 JNIEnv* env, |
698 const JavaParamRef<jclass>& jcaller) { | 799 const JavaParamRef<jclass>& jcaller) { |
699 base::StatisticsRecorder::Initialize(); | 800 base::StatisticsRecorder::Initialize(); |
700 std::vector<uint8_t> data; | 801 std::vector<uint8_t> data; |
701 if (!HistogramManager::GetInstance()->GetDeltas(&data)) | 802 if (!HistogramManager::GetInstance()->GetDeltas(&data)) |
702 return ScopedJavaLocalRef<jbyteArray>(); | 803 return ScopedJavaLocalRef<jbyteArray>(); |
703 return base::android::ToJavaByteArray(env, &data[0], data.size()); | 804 return base::android::ToJavaByteArray(env, &data[0], data.size()); |
704 } | 805 } |
705 | 806 |
706 } // namespace cronet | 807 } // namespace cronet |
OLD | NEW |