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

Side by Side Diff: components/cronet/android/cronet_url_request_context_adapter.cc

Issue 1626673002: Separate prefs from HttpServerPropertiesManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: includes Created 4 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
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>
11 11
12 #include "base/android/jni_android.h" 12 #include "base/android/jni_android.h"
13 #include "base/android/jni_array.h" 13 #include "base/android/jni_array.h"
14 #include "base/android/jni_string.h" 14 #include "base/android/jni_string.h"
15 #include "base/bind.h" 15 #include "base/bind.h"
16 #include "base/files/file_path.h" 16 #include "base/files/file_path.h"
17 #include "base/files/file_util.h" 17 #include "base/files/file_util.h"
18 #include "base/files/scoped_file.h" 18 #include "base/files/scoped_file.h"
19 #include "base/logging.h" 19 #include "base/logging.h"
20 #include "base/macros.h" 20 #include "base/macros.h"
21 #include "base/memory/scoped_vector.h" 21 #include "base/memory/scoped_vector.h"
22 #include "base/message_loop/message_loop.h" 22 #include "base/message_loop/message_loop.h"
23 #include "base/metrics/statistics_recorder.h" 23 #include "base/metrics/statistics_recorder.h"
24 #include "base/prefs/pref_change_registrar.h"
24 #include "base/prefs/pref_filter.h" 25 #include "base/prefs/pref_filter.h"
25 #include "base/prefs/pref_registry_simple.h" 26 #include "base/prefs/pref_registry_simple.h"
26 #include "base/prefs/pref_service.h" 27 #include "base/prefs/pref_service.h"
27 #include "base/prefs/pref_service_factory.h" 28 #include "base/prefs/pref_service_factory.h"
28 #include "base/single_thread_task_runner.h" 29 #include "base/single_thread_task_runner.h"
29 #include "base/time/time.h" 30 #include "base/time/time.h"
30 #include "base/values.h" 31 #include "base/values.h"
31 #include "components/cronet/histogram_manager.h" 32 #include "components/cronet/histogram_manager.h"
32 #include "components/cronet/url_request_context_config.h" 33 #include "components/cronet/url_request_context_config.h"
33 #include "jni/CronetUrlRequestContext_jni.h" 34 #include "jni/CronetUrlRequestContext_jni.h"
(...skipping 14 matching lines...) Expand all
48 #include "net/url_request/url_request_interceptor.h" 49 #include "net/url_request/url_request_interceptor.h"
49 50
50 #if defined(DATA_REDUCTION_PROXY_SUPPORT) 51 #if defined(DATA_REDUCTION_PROXY_SUPPORT)
51 #include "components/cronet/android/cronet_data_reduction_proxy.h" 52 #include "components/cronet/android/cronet_data_reduction_proxy.h"
52 #endif 53 #endif
53 54
54 namespace { 55 namespace {
55 56
56 const char kHttpServerProperties[] = "net.http_server_properties"; 57 const char kHttpServerProperties[] = "net.http_server_properties";
57 58
59 // Connects the HttpServerPropertiesManager's storage to the prefs.
60 class PrefServiceAdapter
61 : public net::HttpServerPropertiesManager::PrefDelegate {
62 public:
63 explicit PrefServiceAdapter(PrefService* pref_service)
64 : pref_service_(pref_service), path_(kHttpServerProperties) {
65 pref_change_registrar_.Init(pref_service_);
66 }
67
68 ~PrefServiceAdapter() override {}
69
70 // PrefDelegate implementation.
71 bool HasServerProperties() override {
72 return pref_service_->HasPrefPath(path_);
73 }
74 const base::DictionaryValue& GetServerProperties() const override {
75 // Guaranteed not to return null when the pref is registered
76 // (RegisterProfilePrefs was called).
77 return *pref_service_->GetDictionary(path_);
78 }
79 void SetServerProperties(const base::Value& value) override {
mef 2016/01/23 18:19:00 Why is SetServerProperties taking base::Value, but
brettw 2016/01/25 20:47:09 Good idea, done.
80 return pref_service_->Set(path_, value);
81 }
82 void StartListeningForUpdates(const base::Closure& callback) override {
83 pref_change_registrar_.Add(path_, callback);
84 }
85 void StopListeningForUpdates() override {
86 pref_change_registrar_.RemoveAll();
87 }
88
89 private:
90 PrefService* pref_service_;
91 std::string path_;
mef 2016/01/23 18:19:00 const?
92 PrefChangeRegistrar pref_change_registrar_;
93
94 DISALLOW_COPY_AND_ASSIGN(PrefServiceAdapter);
95 };
96
58 class BasicNetworkDelegate : public net::NetworkDelegateImpl { 97 class BasicNetworkDelegate : public net::NetworkDelegateImpl {
59 public: 98 public:
60 BasicNetworkDelegate() {} 99 BasicNetworkDelegate() {}
61 ~BasicNetworkDelegate() override {} 100 ~BasicNetworkDelegate() override {}
62 101
63 private: 102 private:
64 // net::NetworkDelegate implementation. 103 // net::NetworkDelegate implementation.
65 int OnBeforeURLRequest(net::URLRequest* request, 104 int OnBeforeURLRequest(net::URLRequest* request,
66 const net::CompletionCallback& callback, 105 const net::CompletionCallback& callback,
67 GURL* new_url) override { 106 GURL* new_url) override {
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 345
307 // Set up HttpServerPropertiesManager. 346 // Set up HttpServerPropertiesManager.
308 base::PrefServiceFactory factory; 347 base::PrefServiceFactory factory;
309 factory.set_user_prefs(json_pref_store_); 348 factory.set_user_prefs(json_pref_store_);
310 scoped_refptr<PrefRegistrySimple> registry(new PrefRegistrySimple()); 349 scoped_refptr<PrefRegistrySimple> registry(new PrefRegistrySimple());
311 registry->RegisterDictionaryPref(kHttpServerProperties, 350 registry->RegisterDictionaryPref(kHttpServerProperties,
312 new base::DictionaryValue()); 351 new base::DictionaryValue());
313 pref_service_ = factory.Create(registry.get()); 352 pref_service_ = factory.Create(registry.get());
314 353
315 scoped_ptr<net::HttpServerPropertiesManager> http_server_properties_manager( 354 scoped_ptr<net::HttpServerPropertiesManager> http_server_properties_manager(
316 new net::HttpServerPropertiesManager(pref_service_.get(), 355 new net::HttpServerPropertiesManager(
317 kHttpServerProperties, 356 new PrefServiceAdapter(pref_service_.get()),
318 GetNetworkTaskRunner())); 357 GetNetworkTaskRunner()));
319 http_server_properties_manager->InitializeOnNetworkThread(); 358 http_server_properties_manager->InitializeOnNetworkThread();
320 http_server_properties_manager_ = http_server_properties_manager.get(); 359 http_server_properties_manager_ = http_server_properties_manager.get();
321 context_builder.SetHttpServerProperties( 360 context_builder.SetHttpServerProperties(
322 std::move(http_server_properties_manager)); 361 std::move(http_server_properties_manager));
323 } 362 }
324 363
325 // Explicitly disable the persister for Cronet to avoid persistence of dynamic 364 // Explicitly disable the persister for Cronet to avoid persistence of dynamic
326 // HPKP. This is a safety measure ensuring that nobody enables the persistence 365 // HPKP. This is a safety measure ensuring that nobody enables the persistence
327 // of HPKP by specifying transport_security_persister_path in the future. 366 // of HPKP by specifying transport_security_persister_path in the future.
328 context_builder.set_transport_security_persister_path(base::FilePath()); 367 context_builder.set_transport_security_persister_path(base::FilePath());
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 JNIEnv* env, 697 JNIEnv* env,
659 const JavaParamRef<jclass>& jcaller) { 698 const JavaParamRef<jclass>& jcaller) {
660 base::StatisticsRecorder::Initialize(); 699 base::StatisticsRecorder::Initialize();
661 std::vector<uint8_t> data; 700 std::vector<uint8_t> data;
662 if (!HistogramManager::GetInstance()->GetDeltas(&data)) 701 if (!HistogramManager::GetInstance()->GetDeltas(&data))
663 return ScopedJavaLocalRef<jbyteArray>(); 702 return ScopedJavaLocalRef<jbyteArray>();
664 return base::android::ToJavaByteArray(env, &data[0], data.size()); 703 return base::android::ToJavaByteArray(env, &data[0], data.size());
665 } 704 }
666 705
667 } // namespace cronet 706 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698