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" |
| 9 | |
sdefresne | 6f95f8f | 2014-11-21 11:21:10 | [diff] [blame] | 10 | namespace base { |
| 11 | class FilePath; |
| 12 | } |
| 13 | |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 14 | namespace net { |
| 15 | class URLRequestContextGetter; |
| 16 | } |
| 17 | |
| 18 | namespace web { |
shreyasv | e8d5f06 | 2015-05-26 20:21:42 | [diff] [blame] | 19 | class ActiveStateManager; |
stuartmorgan | d7f6a67 | 2015-03-31 22:01:13 | [diff] [blame] | 20 | class CertificatePolicyCache; |
stuartmorgan | f0e19f91 | 2015-04-29 06:01:01 | [diff] [blame] | 21 | class URLDataManagerIOS; |
| 22 | class URLDataManagerIOSBackend; |
| 23 | class URLRequestChromeJob; |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 24 | |
| 25 | // This class holds the context needed for a browsing session. |
| 26 | // It lives on the UI thread. All these methods must only be called on the UI |
| 27 | // thread. |
| 28 | class BrowserState : public base::SupportsUserData { |
| 29 | public: |
sdefresne | db52bdf | 2014-11-13 09:20:32 | [diff] [blame] | 30 | ~BrowserState() override; |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 31 | |
stuartmorgan | d7f6a67 | 2015-03-31 22:01:13 | [diff] [blame] | 32 | // static |
| 33 | static scoped_refptr<CertificatePolicyCache> GetCertificatePolicyCache( |
| 34 | BrowserState* browser_state); |
| 35 | |
sdefresne | 6eaff4f | 2015-12-29 17:11:40 | [diff] [blame] | 36 | // Returns whether |browser_state| has an associated ActiveStateManager. |
| 37 | // Must only be accessed from main thread. |
| 38 | static bool HasActiveStateManager(BrowserState* browser_state); |
| 39 | |
shreyasv | e8d5f06 | 2015-05-26 20:21:42 | [diff] [blame] | 40 | // Returns the ActiveStateManager associated with |browser_state.| |
| 41 | // Lazily creates one if an ActiveStateManager is not already associated with |
| 42 | // the |browser_state|. |browser_state| cannot be a nullptr. Must be accessed |
| 43 | // only from the main thread. |
| 44 | static ActiveStateManager* GetActiveStateManager(BrowserState* browser_state); |
| 45 | |
sdefresne | 6f95f8f | 2014-11-21 11:21:10 | [diff] [blame] | 46 | // Returns whether this BrowserState is incognito. Default is false. |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 47 | virtual bool IsOffTheRecord() const = 0; |
| 48 | |
sdefresne | 6f95f8f | 2014-11-21 11:21:10 | [diff] [blame] | 49 | // Returns the path where the BrowserState data is stored. |
sdefresne | 2bbdeed | 2015-03-02 14:24:26 | [diff] [blame] | 50 | // Unlike Profile::GetPath(), incognito BrowserState do not share their path |
| 51 | // with their original BrowserState. |
| 52 | virtual base::FilePath GetStatePath() const = 0; |
sdefresne | 6f95f8f | 2014-11-21 11:21:10 | [diff] [blame] | 53 | |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 54 | // Returns the request context information associated with this |
| 55 | // BrowserState. |
| 56 | virtual net::URLRequestContextGetter* GetRequestContext() = 0; |
| 57 | |
sdefresne | b30864ac | 2014-11-21 12:40:52 | [diff] [blame] | 58 | // Safely cast a base::SupportsUserData to a BrowserState. Returns nullptr |
| 59 | // if |supports_user_data| is not a BrowserState. |
| 60 | static BrowserState* FromSupportsUserData( |
| 61 | base::SupportsUserData* supports_user_data); |
| 62 | |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 63 | protected: |
| 64 | BrowserState(); |
stuartmorgan | f0e19f91 | 2015-04-29 06:01:01 | [diff] [blame] | 65 | |
| 66 | private: |
| 67 | friend class URLDataManagerIOS; |
| 68 | friend class URLRequestChromeJob; |
| 69 | |
| 70 | // Returns the URLDataManagerIOSBackend instance associated with this |
| 71 | // BrowserState, creating it if necessary. Should only be called on the IO |
| 72 | // thread. |
| 73 | // Not intended for usage outside of //web. |
| 74 | URLDataManagerIOSBackend* GetURLDataManagerIOSBackendOnIOThread(); |
| 75 | |
| 76 | // The URLDataManagerIOSBackend instance associated with this BrowserState. |
| 77 | // Created and destroyed on the IO thread, and should be accessed only from |
| 78 | // the IO thread. |
| 79 | URLDataManagerIOSBackend* url_data_manager_ios_backend_; |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | } // namespace web |
| 83 | |
| 84 | #endif // IOS_WEB_PUBLIC_BROWSER_STATE_H_ |