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