Chromium Code Reviews| Index: components/cronet/ios/cronet_environment.h |
| diff --git a/components/cronet/ios/cronet_environment.h b/components/cronet/ios/cronet_environment.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ec37916e50e444cd8bdd3c0c3476a0da29f87907 |
| --- /dev/null |
| +++ b/components/cronet/ios/cronet_environment.h |
| @@ -0,0 +1,137 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef COMPONENTS_CRONET_IOS_CRONET_ENVIRONMENT_H_ |
| +#define COMPONENTS_CRONET_IOS_CRONET_ENVIRONMENT_H_ |
| + |
| +#include <list> |
| + |
| +#include "base/files/file_path.h" |
| +#include "base/macros.h" |
| +#include "base/message_loop/message_loop.h" |
| +#include "base/synchronization/waitable_event.h" |
| +#include "base/threading/thread.h" |
| +#include "net/cert/cert_verifier.h" |
| +#include "net/url_request/url_request.h" |
| +#include "net/url_request/url_request_context.h" |
| + |
| +class JsonPrefStore; |
| + |
| +namespace net { |
| +class HttpCache; |
| +class NetworkChangeNotifier; |
| +class NetLog; |
| +class ProxyConfigService; |
| +class WriteToFileNetLogObserver; |
| +} |
|
xunjieli
2016/04/08 14:43:16
// namespace net
mef
2016/04/08 16:43:03
Done.
|
| + |
| +namespace cronet { |
| +// CronetEnvironment contains all the network stack configuration |
| +// and initialization. |
| +class CronetEnvironment { |
| + public: |
| + // Must be called on the main thread. |
| + static void Initialize(); |
| + |
| + // |user_agent_product_name| will be used to generate the user-agent. |
| + CronetEnvironment(const std::string& user_agent_product_name); |
| + ~CronetEnvironment(); |
| + |
| + // Installs this CrNet environment so requests are intercepted. |
| + // Can only be called once; to enable/disable CrNet at runtime, use |
| + // SetHTTPProtocolHandlerRegistered. |
| + void Install(); |
| + |
| + // The full user-agent. |
| + std::string user_agent(); |
| + |
| + // Creates a new net log (overwrites existing file with this name). If |
| + // actively logging, this call is ignored. |
| + void StartNetLog(base::FilePath::StringType file_name, bool log_bytes); |
| + // Stops logging and flushes file. If not currently logging this call is |
| + // ignored. |
| + void StopNetLog(); |
| + |
| + void AddQuicHint(const std::string& host, int port, int alternate_port); |
| + |
| + // Setters and getters for |http2_enabled_|, |quic_enabled_|, and |
| + // |forced_quic_origin_|. These only have any effect before Install() is |
| + // called. |
| + void set_http2_enabled(bool enabled) { http2_enabled_ = enabled; } |
| + void set_quic_enabled(bool enabled) { quic_enabled_ = enabled; } |
| + |
| + bool http2_enabled() const { return http2_enabled_; } |
| + bool quic_enabled() const { return quic_enabled_; } |
| + |
| + net::URLRequestContext* GetURLRequestContext() const; |
| + |
| + bool IsOnNetworkThread(); |
| + |
| + // Runs a closure on the network thread. |
| + void PostToNetworkThread(const tracked_objects::Location& from_here, |
| + const base::Closure& task); |
| + |
| + void set_cert_verifier(scoped_ptr<net::CertVerifier> cert_verifier) { |
| + cert_verifier_ = std::move(cert_verifier); |
| + } |
| + |
| + void set_host_resolver_rules(const std::string& host_resolver_rules) { |
| + host_resolver_rules_ = host_resolver_rules; |
| + } |
| + |
| + void set_ssl_key_log_file_name(const std::string& ssl_key_log_file_name) { |
| + ssl_key_log_file_name_ = ssl_key_log_file_name; |
| + } |
| + |
| + private: |
| + // Performs initialization tasks that must happen on the network thread. |
| + void InitializeOnNetworkThread(); |
| + |
| + // Runs a closure on the file user blocking thread. |
| + void PostToFileUserBlockingThread(const tracked_objects::Location& from_here, |
| + const base::Closure& task); |
| + |
| + // Helper methods that start/stop net-internals logging on the file |
| + // user blocking thread. |
| + void StartNetLogInternal(base::FilePath::StringType file_name, |
|
xunjieli
2016/04/08 14:43:15
const base::FilePath::StringType& ?
mef
2016/04/08 16:43:03
Done.
|
| + bool log_bytes); |
| + void StopNetLogInternal(); |
| + |
| + // Returns the HttpNeteworkSession object from the passed in |
|
xunjieli
2016/04/08 14:43:16
typo in HttpNetworkSession
mef
2016/04/08 16:43:03
Done.
|
| + // URLRequestContext or NULL if none exists. |
| + net::HttpNetworkSession* GetHttpNetworkSession( |
| + net::URLRequestContext* context); |
| + |
| + // Helper method that closes all current http2 sessions on the network IO |
|
xunjieli
2016/04/08 14:43:16
HTTP/2
mef
2016/04/08 16:43:03
Done.
|
| + // thread. |
| + void CloseAllhttp2SessionsInternal(); |
| + |
| + bool http2_enabled_; |
| + bool quic_enabled_; |
| + std::string host_resolver_rules_; |
| + std::string ssl_key_log_file_name_; |
| + |
| + std::list<net::HostPortPair> quic_hints_; |
| + |
| + static CronetEnvironment* chrome_net_; |
| + scoped_ptr<base::Thread> network_io_thread_; |
| + scoped_ptr<base::Thread> network_cache_thread_; |
| + scoped_ptr<base::Thread> file_thread_; |
| + scoped_ptr<base::Thread> file_user_blocking_thread_; |
| + scoped_refptr<base::SequencedTaskRunner> pref_store_worker_pool_; |
| + scoped_refptr<JsonPrefStore> net_pref_store_; |
| + scoped_ptr<net::CertVerifier> cert_verifier_; |
| + scoped_ptr<net::ProxyConfigService> proxy_config_service_; |
| + scoped_ptr<net::HttpServerProperties> http_server_properties_; |
| + scoped_ptr<net::URLRequestContext> main_context_; |
| + std::string user_agent_product_name_; |
| + scoped_ptr<net::NetLog> net_log_; |
| + scoped_ptr<net::WriteToFileNetLogObserver> net_log_observer_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(CronetEnvironment); |
| +}; |
| + |
| +} // namespace cronet |
| + |
| +#endif // COMPONENTS_CRONET_IOS_CRONET_ENVIRONMENT_H_ |