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

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

Issue 2954753002: Add Cronet experimental option for host cache persistence (Closed)
Patch Set: Created 3 years, 5 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 <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 20 matching lines...) Expand all
31 #include "base/metrics/histogram_macros.h" 31 #include "base/metrics/histogram_macros.h"
32 #include "base/metrics/statistics_recorder.h" 32 #include "base/metrics/statistics_recorder.h"
33 #include "base/single_thread_task_runner.h" 33 #include "base/single_thread_task_runner.h"
34 #include "base/threading/thread_task_runner_handle.h" 34 #include "base/threading/thread_task_runner_handle.h"
35 #include "base/time/time.h" 35 #include "base/time/time.h"
36 #include "base/values.h" 36 #include "base/values.h"
37 #include "components/cronet/android/cert/cert_verifier_cache_serializer.h" 37 #include "components/cronet/android/cert/cert_verifier_cache_serializer.h"
38 #include "components/cronet/android/cert/proto/cert_verification.pb.h" 38 #include "components/cronet/android/cert/proto/cert_verification.pb.h"
39 #include "components/cronet/android/cronet_library_loader.h" 39 #include "components/cronet/android/cronet_library_loader.h"
40 #include "components/cronet/histogram_manager.h" 40 #include "components/cronet/histogram_manager.h"
41 #include "components/cronet/host_cache_persistence_manager.h"
41 #include "components/cronet/url_request_context_config.h" 42 #include "components/cronet/url_request_context_config.h"
42 #include "components/prefs/pref_change_registrar.h" 43 #include "components/prefs/pref_change_registrar.h"
43 #include "components/prefs/pref_filter.h" 44 #include "components/prefs/pref_filter.h"
44 #include "components/prefs/pref_registry.h" 45 #include "components/prefs/pref_registry.h"
45 #include "components/prefs/pref_registry_simple.h" 46 #include "components/prefs/pref_registry_simple.h"
46 #include "components/prefs/pref_service.h" 47 #include "components/prefs/pref_service.h"
47 #include "components/prefs/pref_service_factory.h" 48 #include "components/prefs/pref_service_factory.h"
48 #include "jni/CronetUrlRequestContext_jni.h" 49 #include "jni/CronetUrlRequestContext_jni.h"
49 #include "net/base/load_flags.h" 50 #include "net/base/load_flags.h"
50 #include "net/base/logging_network_change_observer.h" 51 #include "net/base/logging_network_change_observer.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 // so network change event are logged just once in the NetLog. 108 // so network change event are logged just once in the NetLog.
108 std::unique_ptr<net::LoggingNetworkChangeObserver> net_change_logger_; 109 std::unique_ptr<net::LoggingNetworkChangeObserver> net_change_logger_;
109 110
110 DISALLOW_COPY_AND_ASSIGN(NetLogWithNetworkChangeEvents); 111 DISALLOW_COPY_AND_ASSIGN(NetLogWithNetworkChangeEvents);
111 }; 112 };
112 113
113 // Use a global NetLog instance. See crbug.com/486120. 114 // Use a global NetLog instance. See crbug.com/486120.
114 static base::LazyInstance<NetLogWithNetworkChangeEvents>::Leaky g_net_log = 115 static base::LazyInstance<NetLogWithNetworkChangeEvents>::Leaky g_net_log =
115 LAZY_INSTANCE_INITIALIZER; 116 LAZY_INSTANCE_INITIALIZER;
116 117
118 const char kHostCache[] = "net.host_cache";
pauljensen 2017/06/26 16:37:17 Can we add a comment? and can we change name to in
mgersh 2017/06/26 23:21:44 Done, but the inconsistency bothered me so I chang
117 const char kHttpServerProperties[] = "net.http_server_properties"; 119 const char kHttpServerProperties[] = "net.http_server_properties";
118 const char kNetworkQualities[] = "net.network_qualities"; 120 const char kNetworkQualities[] = "net.network_qualities";
119 // Current version of disk storage. 121 // Current version of disk storage.
120 const int32_t kStorageVersion = 1; 122 const int32_t kStorageVersion = 1;
121 // Version number used when the version of disk storage is unknown. 123 // Version number used when the version of disk storage is unknown.
122 const uint32_t kStorageVersionUnknown = 0; 124 const uint32_t kStorageVersionUnknown = 0;
123 // Name of preference directory. 125 // Name of preference directory.
124 const char kPrefsDirectoryName[] = "prefs"; 126 const char kPrefsDirectoryName[] = "prefs";
125 // Name of preference file. 127 // Name of preference file.
126 const char kPrefsFileName[] = "local_prefs.json"; 128 const char kPrefsFileName[] = "local_prefs.json";
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 // Make sure storage directory has correct version. 638 // Make sure storage directory has correct version.
637 InitializeStorageDirectory(storage_path); 639 InitializeStorageDirectory(storage_path);
638 base::FilePath filepath = 640 base::FilePath filepath =
639 storage_path.Append(FILE_PATH_LITERAL(kPrefsDirectoryName)) 641 storage_path.Append(FILE_PATH_LITERAL(kPrefsDirectoryName))
640 .Append(FILE_PATH_LITERAL(kPrefsFileName)); 642 .Append(FILE_PATH_LITERAL(kPrefsFileName));
641 json_pref_store_ = 643 json_pref_store_ =
642 new JsonPrefStore(filepath, GetFileThread()->task_runner(), 644 new JsonPrefStore(filepath, GetFileThread()->task_runner(),
643 std::unique_ptr<PrefFilter>()); 645 std::unique_ptr<PrefFilter>());
644 context_builder.SetFileTaskRunner(GetFileThread()->task_runner()); 646 context_builder.SetFileTaskRunner(GetFileThread()->task_runner());
645 647
646 // Set up HttpServerPropertiesManager. 648 // Register prefs and set up the PrefService.
647 PrefServiceFactory factory; 649 PrefServiceFactory factory;
648 factory.set_user_prefs(json_pref_store_); 650 factory.set_user_prefs(json_pref_store_);
649 scoped_refptr<PrefRegistrySimple> registry(new PrefRegistrySimple()); 651 scoped_refptr<PrefRegistrySimple> registry(new PrefRegistrySimple());
650 registry->RegisterDictionaryPref(kHttpServerProperties, 652 registry->RegisterDictionaryPref(kHttpServerProperties,
651 base::MakeUnique<base::DictionaryValue>()); 653 base::MakeUnique<base::DictionaryValue>());
652 if (config->enable_network_quality_estimator) { 654 if (config->enable_network_quality_estimator) {
653 // Use lossy prefs to limit the overhead of reading/writing the prefs. 655 // Use lossy prefs to limit the overhead of reading/writing the prefs.
654 registry->RegisterDictionaryPref(kNetworkQualities, 656 registry->RegisterDictionaryPref(kNetworkQualities,
655 PrefRegistry::LOSSY_PREF); 657 PrefRegistry::LOSSY_PREF);
656 } 658 }
659 if (config->enable_host_cache_persistence) {
660 registry->RegisterListPref(kHostCache);
661 }
657 pref_service_ = factory.Create(registry.get()); 662 pref_service_ = factory.Create(registry.get());
658 663
664 // Set up the HttpServerPropertiesManager.
659 std::unique_ptr<net::HttpServerPropertiesManager> 665 std::unique_ptr<net::HttpServerPropertiesManager>
660 http_server_properties_manager(new net::HttpServerPropertiesManager( 666 http_server_properties_manager(new net::HttpServerPropertiesManager(
661 new PrefServiceAdapter(pref_service_.get()), 667 new PrefServiceAdapter(pref_service_.get()),
662 base::ThreadTaskRunnerHandle::Get(), GetNetworkTaskRunner(), 668 base::ThreadTaskRunnerHandle::Get(), GetNetworkTaskRunner(),
663 g_net_log.Get().net_log())); 669 g_net_log.Get().net_log()));
664 http_server_properties_manager->InitializeOnNetworkSequence(); 670 http_server_properties_manager->InitializeOnNetworkSequence();
665 http_server_properties_manager_ = http_server_properties_manager.get(); 671 http_server_properties_manager_ = http_server_properties_manager.get();
666 context_builder.SetHttpServerProperties( 672 context_builder.SetHttpServerProperties(
667 std::move(http_server_properties_manager)); 673 std::move(http_server_properties_manager));
668 } 674 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 pref_service_.get())); 708 pref_service_.get()));
703 network_qualities_prefs_manager_->InitializeOnNetworkThread( 709 network_qualities_prefs_manager_->InitializeOnNetworkThread(
704 network_quality_estimator_.get()); 710 network_quality_estimator_.get());
705 } 711 }
706 context_builder.set_network_quality_estimator( 712 context_builder.set_network_quality_estimator(
707 network_quality_estimator_.get()); 713 network_quality_estimator_.get());
708 } 714 }
709 715
710 context_ = context_builder.Build(); 716 context_ = context_builder.Build();
711 717
718 // Set up host cache persistence if it's enabled. Done after building the
pauljensen 2017/06/26 16:37:17 nit: Done->Performed? "Done" can be confused with
mgersh 2017/06/26 23:21:44 Done. (And also performed.)
719 // URLRequestContext to get access to the HostCache.
720 if (!config->storage_path.empty() && config->enable_host_cache_persistence) {
pauljensen 2017/06/26 16:37:17 Can we change the storage_path check to a check fo
mgersh 2017/06/26 23:21:44 Done.
721 net::HostCache* host_cache = context_->host_resolver()->GetHostCache();
722 host_cache_persistence_manager_ =
723 base::MakeUnique<HostCachePersistenceManager>(
724 host_cache, pref_service_.get(), kHostCache,
725 base::TimeDelta::FromMilliseconds(
726 config->host_cache_persistence_timer));
727 }
728
712 context_->set_check_cleartext_permitted(true); 729 context_->set_check_cleartext_permitted(true);
713 context_->set_enable_brotli(config->enable_brotli); 730 context_->set_enable_brotli(config->enable_brotli);
714 731
715 if (config->load_disable_cache) 732 if (config->load_disable_cache)
716 default_load_flags_ |= net::LOAD_DISABLE_CACHE; 733 default_load_flags_ |= net::LOAD_DISABLE_CACHE;
717 734
718 if (config->enable_sdch) { 735 if (config->enable_sdch) {
719 DCHECK(context_->sdch_manager()); 736 DCHECK(context_->sdch_manager());
720 sdch_owner_.reset( 737 sdch_owner_.reset(
721 new net::SdchOwner(context_->sdch_manager(), context_.get())); 738 new net::SdchOwner(context_->sdch_manager(), context_.get()));
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
1171 JNIEnv* env, 1188 JNIEnv* env,
1172 const JavaParamRef<jclass>& jcaller) { 1189 const JavaParamRef<jclass>& jcaller) {
1173 DCHECK(base::StatisticsRecorder::IsActive()); 1190 DCHECK(base::StatisticsRecorder::IsActive());
1174 std::vector<uint8_t> data; 1191 std::vector<uint8_t> data;
1175 if (!HistogramManager::GetInstance()->GetDeltas(&data)) 1192 if (!HistogramManager::GetInstance()->GetDeltas(&data))
1176 return ScopedJavaLocalRef<jbyteArray>(); 1193 return ScopedJavaLocalRef<jbyteArray>();
1177 return base::android::ToJavaByteArray(env, &data[0], data.size()); 1194 return base::android::ToJavaByteArray(env, &data[0], data.size());
1178 } 1195 }
1179 1196
1180 } // namespace cronet 1197 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698