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

Unified Diff: components/cronet/android/cronet_url_request_context_adapter.cc

Issue 726013002: [Cronet] Hook up library loader, system proxy and network change notifier to async api. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Matt's comments. Created 5 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 side-by-side diff with in-line comments
Download patch
Index: components/cronet/android/cronet_url_request_context_adapter.cc
diff --git a/components/cronet/android/cronet_url_request_context_adapter.cc b/components/cronet/android/cronet_url_request_context_adapter.cc
index eac1ea4f0c35d17b4e7719c70d6e212ab0357a31..e8e97bc99c51e00846cc782f004c1561b2d411b3 100644
--- a/components/cronet/android/cronet_url_request_context_adapter.cc
+++ b/components/cronet/android/cronet_url_request_context_adapter.cc
@@ -107,7 +107,15 @@ class BasicNetworkDelegate : public net::NetworkDelegateImpl {
namespace cronet {
-CronetURLRequestContextAdapter::CronetURLRequestContextAdapter() {
+CronetURLRequestContextAdapter::CronetURLRequestContextAdapter(
+ scoped_ptr<URLRequestContextConfig> context_config)
+ : network_thread_(new base::Thread("network")),
+ is_context_initialized_(false) {
+ context_config_.reset(context_config.release());
+
+ base::Thread::Options options;
+ options.message_loop_type = base::MessageLoop::TYPE_IO;
+ network_thread_->StartWithOptions(options);
}
CronetURLRequestContextAdapter::~CronetURLRequestContextAdapter() {
@@ -115,19 +123,15 @@ CronetURLRequestContextAdapter::~CronetURLRequestContextAdapter() {
StopNetLogOnNetworkThread();
}
-void CronetURLRequestContextAdapter::Initialize(
- scoped_ptr<URLRequestContextConfig> config,
+void CronetURLRequestContextAdapter::InitRequestContextOnMainThread(
const base::Closure& java_init_network_thread) {
- network_thread_ = new base::Thread("network");
- base::Thread::Options options;
- options.message_loop_type = base::MessageLoop::TYPE_IO;
- network_thread_->StartWithOptions(options);
-
+ proxy_config_service_.reset(net::ProxyService::CreateSystemProxyConfigService(
+ GetNetworkTaskRunner(), NULL));
GetNetworkTaskRunner()->PostTask(
FROM_HERE,
base::Bind(&CronetURLRequestContextAdapter::InitializeOnNetworkThread,
base::Unretained(this),
- Passed(&config),
+ Passed(&context_config_),
java_init_network_thread));
}
@@ -189,6 +193,12 @@ void CronetURLRequestContextAdapter::InitializeOnNetworkThread(
}
java_init_network_thread.Run();
+
+ is_context_initialized_ = true;
+ while (!tasks_waiting_for_context_.empty()) {
+ tasks_waiting_for_context_.front().Run();
+ tasks_waiting_for_context_.pop();
+ }
}
void CronetURLRequestContextAdapter::Destroy() {
@@ -208,6 +218,25 @@ net::URLRequestContext* CronetURLRequestContextAdapter::GetURLRequestContext() {
return context_.get();
}
+void CronetURLRequestContextAdapter::PostTaskToNetworkThread(
+ const tracked_objects::Location& posted_from,
+ const RunAfterContextInitTask& callback) {
+ GetNetworkTaskRunner()->PostTask(
+ posted_from, base::Bind(&CronetURLRequestContextAdapter::
+ RunTaskAfterContextInitOnNetworkThread,
+ base::Unretained(this), callback));
+}
+
+void CronetURLRequestContextAdapter::RunTaskAfterContextInitOnNetworkThread(
+ const RunAfterContextInitTask& callback) {
+ DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
+ if (is_context_initialized_) {
+ callback.Run();
+ return;
+ }
+ tasks_waiting_for_context_.push(callback);
+}
+
scoped_refptr<base::SingleThreadTaskRunner>
CronetURLRequestContextAdapter::GetNetworkTaskRunner() const {
return network_thread_->task_runner();

Powered by Google App Engine
This is Rietveld 408576698