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 | |
| 8 | #include "base/supports_user_data.h" |
Colin Blundell | d4c96c75 | 2017-07-11 07:24:12 | [diff] [blame^] | 9 | #include "services/service_manager/embedder/embedded_service_info.h" |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 10 | |
sdefresne | 6f95f8f | 2014-11-21 11:21:10 | [diff] [blame] | 11 | namespace base { |
| 12 | class FilePath; |
| 13 | } |
| 14 | |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 15 | namespace net { |
| 16 | class URLRequestContextGetter; |
| 17 | } |
| 18 | |
Colin Blundell | d4c96c75 | 2017-07-11 07:24:12 | [diff] [blame^] | 19 | namespace service_manager { |
| 20 | class Connector; |
| 21 | } |
| 22 | |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 23 | namespace web { |
shreyasv | e8d5f06 | 2015-05-26 20:21:42 | [diff] [blame] | 24 | class ActiveStateManager; |
stuartmorgan | d7f6a67 | 2015-03-31 22:01:13 | [diff] [blame] | 25 | class CertificatePolicyCache; |
Colin Blundell | d4c96c75 | 2017-07-11 07:24:12 | [diff] [blame^] | 26 | class ServiceManagerConnection; |
stuartmorgan | f0e19f91 | 2015-04-29 06:01:01 | [diff] [blame] | 27 | class URLDataManagerIOS; |
| 28 | class URLDataManagerIOSBackend; |
| 29 | class URLRequestChromeJob; |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 30 | |
| 31 | // This class holds the context needed for a browsing session. |
| 32 | // It lives on the UI thread. All these methods must only be called on the UI |
| 33 | // thread. |
| 34 | class BrowserState : public base::SupportsUserData { |
| 35 | public: |
sdefresne | db52bdf | 2014-11-13 09:20:32 | [diff] [blame] | 36 | ~BrowserState() override; |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 37 | |
stuartmorgan | d7f6a67 | 2015-03-31 22:01:13 | [diff] [blame] | 38 | // static |
| 39 | static scoped_refptr<CertificatePolicyCache> GetCertificatePolicyCache( |
| 40 | BrowserState* browser_state); |
| 41 | |
sdefresne | 6eaff4f | 2015-12-29 17:11:40 | [diff] [blame] | 42 | // Returns whether |browser_state| has an associated ActiveStateManager. |
| 43 | // Must only be accessed from main thread. |
| 44 | static bool HasActiveStateManager(BrowserState* browser_state); |
| 45 | |
shreyasv | e8d5f06 | 2015-05-26 20:21:42 | [diff] [blame] | 46 | // Returns the ActiveStateManager associated with |browser_state.| |
| 47 | // Lazily creates one if an ActiveStateManager is not already associated with |
| 48 | // the |browser_state|. |browser_state| cannot be a nullptr. Must be accessed |
| 49 | // only from the main thread. |
| 50 | static ActiveStateManager* GetActiveStateManager(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 | |
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 |
| 71 | // services/service_manager/public/interfaces/connector.mojom. By default, |
| 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: |
| 101 | friend class URLDataManagerIOS; |
| 102 | friend class URLRequestChromeJob; |
| 103 | |
| 104 | // Returns the URLDataManagerIOSBackend instance associated with this |
| 105 | // BrowserState, creating it if necessary. Should only be called on the IO |
| 106 | // thread. |
| 107 | // Not intended for usage outside of //web. |
| 108 | URLDataManagerIOSBackend* GetURLDataManagerIOSBackendOnIOThread(); |
| 109 | |
| 110 | // The URLDataManagerIOSBackend instance associated with this BrowserState. |
| 111 | // Created and destroyed on the IO thread, and should be accessed only from |
| 112 | // the IO thread. |
| 113 | URLDataManagerIOSBackend* url_data_manager_ios_backend_; |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | } // namespace web |
| 117 | |
| 118 | #endif // IOS_WEB_PUBLIC_BROWSER_STATE_H_ |