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

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

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: . 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 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 #ifndef COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_CONTEXT_ADAPTER_H_ 5 #ifndef COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_CONTEXT_ADAPTER_H_
6 #define COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_CONTEXT_ADAPTER_H_ 6 #define COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_CONTEXT_ADAPTER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/threading/thread.h" 14 #include "base/threading/thread.h"
15 #include "net/base/net_log.h" 15 #include "net/base/net_log.h"
16 #include "net/base/network_change_notifier.h" 16 #include "net/base/network_change_notifier.h"
17 17
18 namespace base { 18 namespace base {
19 class SingleThreadTaskRunner; 19 class SingleThreadTaskRunner;
20 } // namespace base 20 } // namespace base
21 21
22 namespace net { 22 namespace net {
23 class NetLogLogger; 23 class NetLogLogger;
24 class URLRequestContext; 24 class URLRequestContext;
25 class ProxyConfigService;
25 } // namespace net 26 } // namespace net
26 27
27 namespace cronet { 28 namespace cronet {
28 29
29 struct URLRequestContextConfig; 30 struct URLRequestContextConfig;
31 typedef base::Callback<void(void)> RunAfterContextInitTask;
30 32
31 // Adapter between Java CronetUrlRequestContext and net::URLRequestContext. 33 // Adapter between Java CronetUrlRequestContext and net::URLRequestContext.
32 class CronetURLRequestContextAdapter { 34 class CronetURLRequestContextAdapter {
33 public: 35 public:
34 CronetURLRequestContextAdapter(); 36 CronetURLRequestContextAdapter();
35 37
36 ~CronetURLRequestContextAdapter(); 38 ~CronetURLRequestContextAdapter();
37 39
38 void Initialize(scoped_ptr<URLRequestContextConfig> config, 40 // Called on main Java thread to initialize URLRequestContext.
39 const base::Closure& java_init_network_thread); 41 void InitRequestContextOnMainThread(
42 scoped_ptr<URLRequestContextConfig> config,
43 const base::Closure& java_init_network_thread);
40 44
41 // Releases all resources for the request context and deletes the object. 45 // Releases all resources for the request context and deletes the object.
42 // Blocks until network thread is destroyed after running all pending tasks. 46 // Blocks until network thread is destroyed after running all pending tasks.
43 void Destroy(); 47 void Destroy();
44 48
49 // Posts a task that might depend on the context being initialized
50 // to the network thread.
51 void PostTaskToNetworkThread(const tracked_objects::Location& posted_from,
52 const RunAfterContextInitTask& callback);
53
45 net::URLRequestContext* GetURLRequestContext(); 54 net::URLRequestContext* GetURLRequestContext();
46 55
47 scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() const; 56 scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() const;
48 57
49 void StartNetLogToFile(const std::string& file_name); 58 void StartNetLogToFile(const std::string& file_name);
50 59
51 void StopNetLog(); 60 void StopNetLog();
52 61
62
mmenke 2015/01/08 19:06:16 nit: Remove blank line.
mef 2015/01/08 21:17:02 Done.
53 private: 63 private:
54 // Network thread is owned by |this|, but is destroyed from java thread. 64 // Network thread is owned by |this|, but is destroyed from java thread.
55 base::Thread* network_thread_; 65 base::Thread* network_thread_;
56 // |net_log_logger_| and |context_| should only be accessed on network thread. 66 // |net_log_logger_| and |context_| should only be accessed on network thread.
57 scoped_ptr<net::NetLogLogger> net_log_logger_; 67 scoped_ptr<net::NetLogLogger> net_log_logger_;
58 scoped_ptr<net::URLRequestContext> context_; 68 scoped_ptr<net::URLRequestContext> context_;
69 scoped_ptr<net::ProxyConfigService> proxy_config_service_;
70
71 // A queue of tasks that need to be run after context has been initialized.
72 std::queue<RunAfterContextInitTask> tasks_waiting_for_context_;
73 bool is_context_initialized_ = false;
mmenke 2015/01/08 19:06:16 Member variables should go after methods (Hrm...Di
mmenke 2015/01/08 19:06:16 Don't inline initialization like this is a C++0x11
mef 2015/01/08 21:17:02 Done.
mef 2015/01/08 21:17:02 Done.
59 74
60 // Initializes |context_| on the Network thread. 75 // Initializes |context_| on the Network thread.
61 void InitializeOnNetworkThread( 76 void InitializeOnNetworkThread(
62 scoped_ptr<URLRequestContextConfig> config, 77 scoped_ptr<URLRequestContextConfig> config,
63 const base::Closure& java_init_network_thread); 78 const base::Closure& java_init_network_thread);
64 void StartNetLogToFileOnNetworkThread(const std::string& file_name); 79 void StartNetLogToFileOnNetworkThread(const std::string& file_name);
65 void StopNetLogOnNetworkThread(); 80 void StopNetLogOnNetworkThread();
66 81
82 // Runs a task that might depend on the context being initialized.
83 // This method should only be run on the network thread.
84 void RunTaskAfterContextInitOnNetworkThread(
85 const RunAfterContextInitTask& callback);
86
67 DISALLOW_COPY_AND_ASSIGN(CronetURLRequestContextAdapter); 87 DISALLOW_COPY_AND_ASSIGN(CronetURLRequestContextAdapter);
68 }; 88 };
69 89
70 } // namespace cronet 90 } // namespace cronet
71 91
72 #endif // COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_CONTEXT_ADAPTER_H_ 92 #endif // COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_CONTEXT_ADAPTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698