| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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_IOS_CRONET_ENVIRONMENT_H_ | 5 #ifndef COMPONENTS_CRONET_IOS_CRONET_ENVIRONMENT_H_ |
| 6 #define COMPONENTS_CRONET_IOS_CRONET_ENVIRONMENT_H_ | 6 #define COMPONENTS_CRONET_IOS_CRONET_ENVIRONMENT_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 | 9 |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
| 14 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
| 15 #include "components/cronet/url_request_context_config.h" | 15 #include "components/cronet/url_request_context_config.h" |
| 16 #include "components/grpc_support/environment.h" |
| 16 #include "net/cert/cert_verifier.h" | 17 #include "net/cert/cert_verifier.h" |
| 17 #include "net/url_request/url_request.h" | 18 #include "net/url_request/url_request.h" |
| 18 #include "net/url_request/url_request_context.h" | 19 #include "net/url_request/url_request_context.h" |
| 19 | 20 |
| 20 class JsonPrefStore; | 21 class JsonPrefStore; |
| 21 | 22 |
| 22 namespace base { | 23 namespace base { |
| 23 class WaitableEvent; | 24 class WaitableEvent; |
| 24 } // namespace base | 25 } // namespace base |
| 25 | 26 |
| 26 namespace net { | 27 namespace net { |
| 27 class HttpCache; | 28 class HttpCache; |
| 28 class NetworkChangeNotifier; | 29 class NetworkChangeNotifier; |
| 29 class NetLog; | 30 class NetLog; |
| 30 class ProxyConfigService; | 31 class ProxyConfigService; |
| 31 class WriteToFileNetLogObserver; | 32 class WriteToFileNetLogObserver; |
| 32 } // namespace net | 33 } // namespace net |
| 33 | 34 |
| 34 namespace cronet { | 35 namespace cronet { |
| 35 // CronetEnvironment contains all the network stack configuration | 36 // CronetEnvironment contains all the network stack configuration |
| 36 // and initialization. | 37 // and initialization. |
| 37 class CronetEnvironment { | 38 class CronetEnvironment : public grpc_support::Environment { |
| 38 public: | 39 public: |
| 39 // Initialize Cronet environment globals. Must be called only once on the | 40 // Initialize Cronet environment globals. Must be called only once on the |
| 40 // main thread. | 41 // main thread. |
| 41 static void Initialize(); | 42 static void Initialize(); |
| 42 | 43 |
| 43 // |user_agent_product_name| will be used to generate the user-agent. | 44 // |user_agent_product_name| will be used to generate the user-agent. |
| 44 CronetEnvironment(const std::string& user_agent_product_name); | 45 CronetEnvironment(const std::string& user_agent_product_name); |
| 45 ~CronetEnvironment(); | 46 ~CronetEnvironment(); |
| 46 | 47 |
| 47 // Starts this instance of Cronet environment. | 48 // Starts this instance of Cronet environment. |
| 48 void Start(); | 49 void Start(); |
| 49 | 50 |
| 50 // The full user-agent. | |
| 51 std::string user_agent(); | |
| 52 | |
| 53 // Creates a new net log (overwrites existing file with this name). If | 51 // Creates a new net log (overwrites existing file with this name). If |
| 54 // actively logging, this call is ignored. | 52 // actively logging, this call is ignored. |
| 55 void StartNetLog(base::FilePath::StringType file_name, bool log_bytes); | 53 void StartNetLog(base::FilePath::StringType file_name, bool log_bytes); |
| 56 // Stops logging and flushes file. If not currently logging this call is | 54 // Stops logging and flushes file. If not currently logging this call is |
| 57 // ignored. | 55 // ignored. |
| 58 void StopNetLog(); | 56 void StopNetLog(); |
| 59 | 57 |
| 60 void AddQuicHint(const std::string& host, int port, int alternate_port); | 58 void AddQuicHint(const std::string& host, int port, int alternate_port); |
| 61 | 59 |
| 62 // Setters and getters for |http2_enabled_|, |quic_enabled_|, and | 60 // Setters and getters for |http2_enabled_|, |quic_enabled_|, and |
| (...skipping 10 matching lines...) Expand all Loading... |
| 73 } | 71 } |
| 74 | 72 |
| 75 void set_host_resolver_rules(const std::string& host_resolver_rules) { | 73 void set_host_resolver_rules(const std::string& host_resolver_rules) { |
| 76 host_resolver_rules_ = host_resolver_rules; | 74 host_resolver_rules_ = host_resolver_rules; |
| 77 } | 75 } |
| 78 | 76 |
| 79 void set_ssl_key_log_file_name(const std::string& ssl_key_log_file_name) { | 77 void set_ssl_key_log_file_name(const std::string& ssl_key_log_file_name) { |
| 80 ssl_key_log_file_name_ = ssl_key_log_file_name; | 78 ssl_key_log_file_name_ = ssl_key_log_file_name; |
| 81 } | 79 } |
| 82 | 80 |
| 83 net::URLRequestContext* GetURLRequestContext() const; | 81 // grpc_support::Environment implementation. |
| 84 | 82 bool IsOnNetworkThread() override; |
| 85 bool IsOnNetworkThread(); | |
| 86 | |
| 87 // Runs a closure on the network thread. | |
| 88 void PostToNetworkThread(const tracked_objects::Location& from_here, | 83 void PostToNetworkThread(const tracked_objects::Location& from_here, |
| 89 const base::Closure& task); | 84 const base::Closure& task) override; |
| 85 net::URLRequestContext* GetURLRequestContext() const override; |
| 86 std::string UserAgent() override; |
| 90 | 87 |
| 91 private: | 88 private: |
| 92 // Performs initialization tasks that must happen on the network thread. | 89 // Performs initialization tasks that must happen on the network thread. |
| 93 void InitializeOnNetworkThread(); | 90 void InitializeOnNetworkThread(); |
| 94 | 91 |
| 95 // Runs a closure on the file user blocking thread. | 92 // Runs a closure on the file user blocking thread. |
| 96 void PostToFileUserBlockingThread(const tracked_objects::Location& from_here, | 93 void PostToFileUserBlockingThread(const tracked_objects::Location& from_here, |
| 97 const base::Closure& task); | 94 const base::Closure& task); |
| 98 | 95 |
| 99 // Helper methods that start/stop net logging on the network thread. | 96 // Helper methods that start/stop net logging on the network thread. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 126 std::string user_agent_product_name_; | 123 std::string user_agent_product_name_; |
| 127 std::unique_ptr<net::NetLog> net_log_; | 124 std::unique_ptr<net::NetLog> net_log_; |
| 128 std::unique_ptr<net::WriteToFileNetLogObserver> net_log_observer_; | 125 std::unique_ptr<net::WriteToFileNetLogObserver> net_log_observer_; |
| 129 | 126 |
| 130 DISALLOW_COPY_AND_ASSIGN(CronetEnvironment); | 127 DISALLOW_COPY_AND_ASSIGN(CronetEnvironment); |
| 131 }; | 128 }; |
| 132 | 129 |
| 133 } // namespace cronet | 130 } // namespace cronet |
| 134 | 131 |
| 135 #endif // COMPONENTS_CRONET_IOS_CRONET_ENVIRONMENT_H_ | 132 #endif // COMPONENTS_CRONET_IOS_CRONET_ENVIRONMENT_H_ |
| OLD | NEW |