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

Unified Diff: components/cronet/android/url_request_context_adapter.h

Issue 617393005: Make URLRequestContextAdapter initialization asynchronous (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Misha's comments Created 6 years, 2 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/url_request_context_adapter.h
diff --git a/components/cronet/android/url_request_context_adapter.h b/components/cronet/android/url_request_context_adapter.h
index 22cc2a14922fef7a6832a5f07d4ec9b9a59fc1e0..b84e036f3cb476e8d70acfa6164c7eef4f94da47 100644
--- a/components/cronet/android/url_request_context_adapter.h
+++ b/components/cronet/android/url_request_context_adapter.h
@@ -5,9 +5,12 @@
#ifndef COMPONENTS_CRONET_ANDROID_URL_REQUEST_CONTEXT_ADAPTER_H_
#define COMPONENTS_CRONET_ANDROID_URL_REQUEST_CONTEXT_ADAPTER_H_
+#include <queue>
#include <string>
+#include "base/callback.h"
#include "base/compiler_specific.h"
+#include "base/location.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
@@ -24,6 +27,7 @@ class NetLogLogger;
namespace cronet {
struct URLRequestContextConfig;
+typedef base::Callback<void(void)> RunAfterContextInitTask;
// Implementation of the Chromium NetLog observer interface.
class NetLogObserver : public net::NetLog::ThreadSafeObserver {
@@ -56,6 +60,16 @@ class URLRequestContextAdapter : public net::URLRequestContextGetter {
std::string user_agent);
void Initialize(scoped_ptr<URLRequestContextConfig> config);
+ // Posts a task that might depend on the context being initialized
+ // to the network thread.
+ void PostTaskToNetworkThread(const tracked_objects::Location& posted_from,
+ const RunAfterContextInitTask& callback);
+
+ // Runs a task that might depend on the context being initialized.
+ // This method should only be run on the network thread.
+ void RunTaskAfterContextInitOnNetworkThread(
+ const RunAfterContextInitTask& callback);
+
const std::string& GetUserAgent(const GURL& url) const;
// net::URLRequestContextGetter implementation:
@@ -75,11 +89,22 @@ class URLRequestContextAdapter : public net::URLRequestContextGetter {
scoped_ptr<NetLogObserver> net_log_observer_;
scoped_ptr<net::NetLogLogger> net_log_logger_;
+ // A queue of tasks that need to be run after context has been initialized.
+ std::queue<RunAfterContextInitTask> tasks_waiting_for_context_;
+ bool is_context_initialized_;
+
virtual ~URLRequestContextAdapter();
// Initializes |context_| on the Network thread.
void InitializeURLRequestContext(scoped_ptr<URLRequestContextConfig> config);
+ // Helper function to start writing NetLog data to file. This should only be
+ // run after context is initialized.
+ void StartNetLogToFileHelper(const std::string& file_name);
+ // Helper function to stop writing NetLog data to file. This should only be
+ // run after context is initialized.
+ void StopNetLogHelper();
+
DISALLOW_COPY_AND_ASSIGN(URLRequestContextAdapter);
};
« no previous file with comments | « components/cronet/android/url_request_adapter.cc ('k') | components/cronet/android/url_request_context_adapter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698