sdefresne | f40c65a | 2014-11-13 12:25:02 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 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 IOS_WEB_PUBLIC_BROWSER_STATE_H_ |
| 6 | #define IOS_WEB_PUBLIC_BROWSER_STATE_H_ |
| 7 | |
John Abd-El-Malek | 07a93f1 | 2018-02-08 19:28:25 | [diff] [blame] | 8 | #include <memory> |
| 9 | |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 10 | #include "base/supports_user_data.h" |
Matt Menke | 1f2fb373 | 2018-03-09 19:14:47 | [diff] [blame] | 11 | #include "services/network/public/mojom/network_service.mojom.h" |
| 12 | #include "services/network/public/mojom/url_loader_factory.mojom.h" |
Colin Blundell | d4c96c75 | 2017-07-11 07:24:12 | [diff] [blame] | 13 | #include "services/service_manager/embedder/embedded_service_info.h" |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 14 | |
sdefresne | 6f95f8f | 2014-11-21 11:21:10 | [diff] [blame] | 15 | namespace base { |
| 16 | class FilePath; |
| 17 | } |
| 18 | |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 19 | namespace net { |
| 20 | class URLRequestContextGetter; |
| 21 | } |
| 22 | |
John Abd-El-Malek | 07a93f1 | 2018-02-08 19:28:25 | [diff] [blame] | 23 | namespace network { |
| 24 | namespace mojom { |
| 25 | class URLLoaderFactory; |
| 26 | } |
| 27 | } // namespace network |
| 28 | |
Colin Blundell | d4c96c75 | 2017-07-11 07:24:12 | [diff] [blame] | 29 | namespace service_manager { |
| 30 | class Connector; |
| 31 | } |
| 32 | |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 33 | namespace web { |
stuartmorgan | d7f6a67 | 2015-03-31 22:01:13 | [diff] [blame] | 34 | class CertificatePolicyCache; |
Maks Orlovich | c71746a6 | 2018-04-27 21:52:17 | [diff] [blame^] | 35 | class NetworkContextOwner; |
Colin Blundell | d4c96c75 | 2017-07-11 07:24:12 | [diff] [blame] | 36 | class ServiceManagerConnection; |
stuartmorgan | f0e19f91 | 2015-04-29 06:01:01 | [diff] [blame] | 37 | class URLDataManagerIOS; |
| 38 | class URLDataManagerIOSBackend; |
| 39 | class URLRequestChromeJob; |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 40 | |
| 41 | // This class holds the context needed for a browsing session. |
| 42 | // It lives on the UI thread. All these methods must only be called on the UI |
| 43 | // thread. |
| 44 | class BrowserState : public base::SupportsUserData { |
| 45 | public: |
sdefresne | db52bdf | 2014-11-13 09:20:32 | [diff] [blame] | 46 | ~BrowserState() override; |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 47 | |
stuartmorgan | d7f6a67 | 2015-03-31 22:01:13 | [diff] [blame] | 48 | // static |
| 49 | static scoped_refptr<CertificatePolicyCache> GetCertificatePolicyCache( |
| 50 | BrowserState* browser_state); |
| 51 | |
sdefresne | 6f95f8f | 2014-11-21 11:21:10 | [diff] [blame] | 52 | // Returns whether this BrowserState is incognito. Default is false. |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 53 | virtual bool IsOffTheRecord() const = 0; |
| 54 | |
sdefresne | 6f95f8f | 2014-11-21 11:21:10 | [diff] [blame] | 55 | // Returns the path where the BrowserState data is stored. |
sdefresne | 2bbdeed | 2015-03-02 14:24:26 | [diff] [blame] | 56 | // Unlike Profile::GetPath(), incognito BrowserState do not share their path |
| 57 | // with their original BrowserState. |
| 58 | virtual base::FilePath GetStatePath() const = 0; |
sdefresne | 6f95f8f | 2014-11-21 11:21:10 | [diff] [blame] | 59 | |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 60 | // Returns the request context information associated with this |
| 61 | // BrowserState. |
| 62 | virtual net::URLRequestContextGetter* GetRequestContext() = 0; |
| 63 | |
John Abd-El-Malek | 07a93f1 | 2018-02-08 19:28:25 | [diff] [blame] | 64 | // Returns a URLLoaderFactory that is backed by GetRequestContext. |
| 65 | network::mojom::URLLoaderFactory* GetURLLoaderFactory(); |
| 66 | |
sdefresne | b30864ac | 2014-11-21 12:40:52 | [diff] [blame] | 67 | // Safely cast a base::SupportsUserData to a BrowserState. Returns nullptr |
| 68 | // if |supports_user_data| is not a BrowserState. |
| 69 | static BrowserState* FromSupportsUserData( |
| 70 | base::SupportsUserData* supports_user_data); |
| 71 | |
Colin Blundell | d4c96c75 | 2017-07-11 07:24:12 | [diff] [blame] | 72 | // Returns a Service User ID associated with this BrowserState. This ID is |
| 73 | // not persistent across runs. See |
Ken Rockot | 543f5e3 | 2018-02-04 02:13:50 | [diff] [blame] | 74 | // services/service_manager/public/mojom/connector.mojom. By default, |
Colin Blundell | d4c96c75 | 2017-07-11 07:24:12 | [diff] [blame] | 75 | // this user id is randomly generated when Initialize() is called. |
| 76 | static const std::string& GetServiceUserIdFor(BrowserState* browser_state); |
| 77 | |
| 78 | // Returns a Connector associated with this BrowserState, which can be used |
| 79 | // to connect to service instances bound as this user. |
| 80 | static service_manager::Connector* GetConnectorFor( |
| 81 | BrowserState* browser_state); |
| 82 | |
| 83 | // Returns a ServiceManagerConnection associated with this BrowserState, |
| 84 | // which can be used to connect to service instances bound as this user. |
| 85 | static ServiceManagerConnection* GetServiceManagerConnectionFor( |
| 86 | BrowserState* browser_state); |
| 87 | |
| 88 | using StaticServiceMap = |
| 89 | std::map<std::string, service_manager::EmbeddedServiceInfo>; |
| 90 | |
| 91 | // Registers per-browser-state services to be loaded by the Service Manager. |
| 92 | virtual void RegisterServices(StaticServiceMap* services) {} |
| 93 | |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 94 | protected: |
| 95 | BrowserState(); |
stuartmorgan | f0e19f91 | 2015-04-29 06:01:01 | [diff] [blame] | 96 | |
Colin Blundell | d4c96c75 | 2017-07-11 07:24:12 | [diff] [blame] | 97 | // Makes the Service Manager aware of this BrowserState, and assigns a user |
| 98 | // ID number to it. Must be called for each BrowserState created. |path| |
| 99 | // should be the same path that would be returned by GetStatePath(). |
| 100 | static void Initialize(BrowserState* browser_state, |
| 101 | const base::FilePath& path); |
| 102 | |
stuartmorgan | f0e19f91 | 2015-04-29 06:01:01 | [diff] [blame] | 103 | private: |
stuartmorgan | f0e19f91 | 2015-04-29 06:01:01 | [diff] [blame] | 104 | friend class URLDataManagerIOS; |
| 105 | friend class URLRequestChromeJob; |
| 106 | |
| 107 | // Returns the URLDataManagerIOSBackend instance associated with this |
| 108 | // BrowserState, creating it if necessary. Should only be called on the IO |
| 109 | // thread. |
| 110 | // Not intended for usage outside of //web. |
| 111 | URLDataManagerIOSBackend* GetURLDataManagerIOSBackendOnIOThread(); |
| 112 | |
Matt Menke | 1f2fb373 | 2018-03-09 19:14:47 | [diff] [blame] | 113 | network::mojom::URLLoaderFactoryPtr url_loader_factory_; |
| 114 | network::mojom::NetworkContextPtr network_context_; |
| 115 | |
| 116 | // Owns the network::NetworkContext that backs |url_loader_factory_|. Created |
| 117 | // on the UI thread, destroyed on the IO thread. |
| 118 | std::unique_ptr<NetworkContextOwner> network_context_owner_; |
John Abd-El-Malek | 07a93f1 | 2018-02-08 19:28:25 | [diff] [blame] | 119 | |
stuartmorgan | f0e19f91 | 2015-04-29 06:01:01 | [diff] [blame] | 120 | // The URLDataManagerIOSBackend instance associated with this BrowserState. |
| 121 | // Created and destroyed on the IO thread, and should be accessed only from |
| 122 | // the IO thread. |
| 123 | URLDataManagerIOSBackend* url_data_manager_ios_backend_; |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | } // namespace web |
| 127 | |
| 128 | #endif // IOS_WEB_PUBLIC_BROWSER_STATE_H_ |