1 // Copyright 2017 The Chromium Authors 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_CRONET_GLOBAL_STATE_H_ 6 #define COMPONENTS_CRONET_CRONET_GLOBAL_STATE_H_ 7 8 #include <memory> 9 #include <string> 10 #include "base/memory/scoped_refptr.h" 11 #include "base/task/sequenced_task_runner.h" 12 13 namespace net { 14 class NetLog; 15 class ProxyConfigService; 16 class ProxyResolutionService; 17 } // namespace net 18 19 namespace cronet { 20 21 // Returns true when called on the initialization thread. 22 // May only be called after EnsureInitialized() has returned. 23 bool OnInitThread(); 24 25 // Posts a task to run on initialization thread. Blocks until initialization 26 // thread is started. 27 void PostTaskToInitThread(const base::Location& posted_from, 28 base::OnceClosure task); 29 30 // Performs one-off initialization of Cronet global state, including creating, 31 // or binding to an existing thread, to run initialization and process 32 // network notifications on. The implementation must be thread-safe and 33 // idempotent, and must complete initialization before returning. 34 void EnsureInitialized(); 35 36 // Creates a proxy config service appropriate for this platform that fetches the 37 // system proxy settings. Cronet will call this API only after a prior call 38 // to EnsureInitialized() has returned. 39 // On Android, this must be called on the JNI thread. 40 std::unique_ptr<net::ProxyConfigService> CreateProxyConfigService( 41 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner); 42 43 // Creates a proxy resolution service appropriate for this platform that fetches 44 // the system proxy settings. Cronet will call this API only after a prior call 45 // to EnsureInitialized() has returned. 46 std::unique_ptr<net::ProxyResolutionService> CreateProxyResolutionService( 47 std::unique_ptr<net::ProxyConfigService> proxy_config_service, 48 net::NetLog* net_log); 49 50 // Creates default User-Agent request value, combining optional 51 // |partial_user_agent| with system-dependent values. This API may be invoked 52 // before EnsureInitialized(), in which case it may trigger initialization 53 // itself, if necessary. 54 std::string CreateDefaultUserAgent(const std::string& partial_user_agent); 55 56 // Set network thread priority to |priority|. Must be called on the network 57 // thread. Corresponds to android.os.Process.setThreadPriority() 58 // values. 59 void SetNetworkThreadPriorityOnNetworkThread(double priority); 60 61 } // namespace cronet 62 63 #endif // COMPONENTS_CRONET_CRONET_GLOBAL_STATE_H_ 64