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

Side by Side Diff: components/cronet/ios/cronet_environment.h

Issue 1858483002: Cronet for iOS with C API for GRPC support. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@small
Patch Set: Use LazyInitializer, wait for stopLogOnNetworkThread. Created 4 years, 8 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_CRONET_IOS_CRONET_ENVIRONMENT_H_
6 #define COMPONENTS_CRONET_IOS_CRONET_ENVIRONMENT_H_
7
8 #include <list>
9
10 #include "base/files/file_path.h"
11 #include "base/macros.h"
12 #include "base/message_loop/message_loop.h"
13 #include "base/synchronization/waitable_event.h"
14 #include "base/threading/thread.h"
15 #include "components/cronet/url_request_context_config.h"
16 #include "net/cert/cert_verifier.h"
17 #include "net/url_request/url_request.h"
18 #include "net/url_request/url_request_context.h"
19
20 class JsonPrefStore;
21
22 namespace base {
23 class WaitableEvent;
24 } // namespace base
25
26 namespace net {
27 class HttpCache;
28 class NetworkChangeNotifier;
29 class NetLog;
30 class ProxyConfigService;
31 class WriteToFileNetLogObserver;
32 } // namespace net
33
34 namespace cronet {
35 // CronetEnvironment contains all the network stack configuration
36 // and initialization.
37 class CronetEnvironment {
38 public:
39 // Must be called on the main thread.
40 static void Initialize();
xunjieli 2016/04/13 15:28:24 Why is this method static? Why do we have both Ini
mef 2016/04/14 21:17:35 Done.
41
42 // |user_agent_product_name| will be used to generate the user-agent.
43 CronetEnvironment(const std::string& user_agent_product_name);
44 ~CronetEnvironment();
45
46 // Installs this Cronet environment. Can only be called once.
xunjieli 2016/04/13 15:28:24 Can install() be called on any thread? Maybe docum
mef 2016/04/14 21:17:35 Done.
47 void Install();
48
49 // The full user-agent.
50 std::string user_agent();
51
52 // Creates a new net log (overwrites existing file with this name). If
53 // actively logging, this call is ignored.
54 void StartNetLog(base::FilePath::StringType file_name, bool log_bytes);
55 // Stops logging and flushes file. If not currently logging this call is
56 // ignored.
57 void StopNetLog();
58
59 void AddQuicHint(const std::string& host, int port, int alternate_port);
60
61 // Setters and getters for |http2_enabled_|, |quic_enabled_|, and
62 // |forced_quic_origin_|. These only have any effect before Install() is
63 // called.
64 void set_http2_enabled(bool enabled) { http2_enabled_ = enabled; }
65 void set_quic_enabled(bool enabled) { quic_enabled_ = enabled; }
66
67 bool http2_enabled() const { return http2_enabled_; }
68 bool quic_enabled() const { return quic_enabled_; }
69
70 void set_cert_verifier(scoped_ptr<net::CertVerifier> cert_verifier) {
71 cert_verifier_ = std::move(cert_verifier);
72 }
73
74 void set_host_resolver_rules(const std::string& host_resolver_rules) {
75 host_resolver_rules_ = host_resolver_rules;
76 }
77
78 void set_ssl_key_log_file_name(const std::string& ssl_key_log_file_name) {
79 ssl_key_log_file_name_ = ssl_key_log_file_name;
80 }
81
82 net::URLRequestContext* GetURLRequestContext() const;
83
84 bool IsOnNetworkThread();
85
86 // Runs a closure on the network thread.
87 void PostToNetworkThread(const tracked_objects::Location& from_here,
88 const base::Closure& task);
89
90 private:
91 // Performs initialization tasks that must happen on the network thread.
92 void InitializeOnNetworkThread();
93
94 // Runs a closure on the file user blocking thread.
95 void PostToFileUserBlockingThread(const tracked_objects::Location& from_here,
96 const base::Closure& task);
97
98 // Helper methods that start/stop net logging on the network thread.
99 void StartNetLogOnNetworkThread(const base::FilePath::StringType& file_name,
100 bool log_bytes);
101 void StopNetLogOnNetworkThread(base::WaitableEvent* log_stopped_event);
102
103 // Returns the HttpNetworkSession object from the passed in
104 // URLRequestContext or NULL if none exists.
105 net::HttpNetworkSession* GetHttpNetworkSession(
106 net::URLRequestContext* context);
107
108 bool http2_enabled_;
109 bool quic_enabled_;
110 std::string host_resolver_rules_;
111 std::string ssl_key_log_file_name_;
112
113 std::list<net::HostPortPair> quic_hints_;
114
115 static CronetEnvironment* chrome_net_;
xunjieli 2016/04/13 15:28:24 Why is this "static"?
mef 2016/04/14 21:17:35 Done.
116 scoped_ptr<base::Thread> network_io_thread_;
117 scoped_ptr<base::Thread> network_cache_thread_;
118 scoped_ptr<base::Thread> file_thread_;
119 scoped_ptr<base::Thread> file_user_blocking_thread_;
120 scoped_refptr<base::SequencedTaskRunner> pref_store_worker_pool_;
121 scoped_refptr<JsonPrefStore> net_pref_store_;
122 scoped_ptr<net::CertVerifier> cert_verifier_;
123 scoped_ptr<net::ProxyConfigService> proxy_config_service_;
124 scoped_ptr<net::HttpServerProperties> http_server_properties_;
125 scoped_ptr<net::URLRequestContext> main_context_;
126 std::string user_agent_product_name_;
127 scoped_ptr<net::NetLog> net_log_;
128 scoped_ptr<net::WriteToFileNetLogObserver> net_log_observer_;
129
130 DISALLOW_COPY_AND_ASSIGN(CronetEnvironment);
131 };
132
133 } // namespace cronet
134
135 #endif // COMPONENTS_CRONET_IOS_CRONET_ENVIRONMENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698