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

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: Self review, cl format Created 5 years, 12 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..c6a4a51602e3eed46b1b6c2ff336d5e521c6b68b 100644
--- a/components/cronet/android/cronet_url_request_context_adapter.cc
+++ b/components/cronet/android/cronet_url_request_context_adapter.cc
@@ -107,7 +107,8 @@ class BasicNetworkDelegate : public net::NetworkDelegateImpl {
namespace cronet {
-CronetURLRequestContextAdapter::CronetURLRequestContextAdapter() {
+CronetURLRequestContextAdapter::CronetURLRequestContextAdapter()
+ : is_context_initialized_(false) {
}
CronetURLRequestContextAdapter::~CronetURLRequestContextAdapter() {
@@ -131,6 +132,11 @@ void CronetURLRequestContextAdapter::Initialize(
java_init_network_thread));
}
+void CronetURLRequestContextAdapter::InitRequestContextOnMainThread() {
+ proxy_config_service_.reset(net::ProxyService::CreateSystemProxyConfigService(
xunjieli 2015/01/05 14:48:03 I wonder whether it makes a difference for each co
mef 2015/01/05 16:59:21 CreateSystemProxyConfigService takes io_task_runne
mmenke 2015/01/05 18:20:39 I'm not really a big fan of globals, unless they'r
+ GetNetworkTaskRunner(), NULL));
xunjieli 2015/01/05 14:48:03 I think we moved the task of InitializeOnNetworkTh
mef 2015/01/05 16:59:21 Definitely, thanks for spotting that. Done.
+}
+
void CronetURLRequestContextAdapter::InitializeOnNetworkThread(
scoped_ptr<URLRequestContextConfig> config,
const base::Closure& java_init_network_thread) {
@@ -189,6 +195,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 +220,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