blob: 97f3da10a73c82d68e0f1bfbefe9616ed1834621 [file] [log] [blame]
sdefresnef40c65a2014-11-13 12:25:021// Copyright 2013 The Chromium Authors. All rights reserved.
sdefresnea010b6d2014-11-12 09:32:202// 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
sdefresne6f95f8f2014-11-21 11:21:1010namespace base {
11class FilePath;
12}
13
sdefresnea010b6d2014-11-12 09:32:2014namespace net {
15class URLRequestContextGetter;
16}
17
18namespace web {
shreyasve8d5f062015-05-26 20:21:4219class ActiveStateManager;
20class BrowsingDataPartition;
stuartmorgand7f6a672015-03-31 22:01:1321class CertificatePolicyCache;
stuartmorganf0e19f912015-04-29 06:01:0122class URLDataManagerIOS;
23class URLDataManagerIOSBackend;
24class URLRequestChromeJob;
sdefresnea010b6d2014-11-12 09:32:2025
26// This class holds the context needed for a browsing session.
27// It lives on the UI thread. All these methods must only be called on the UI
28// thread.
29class BrowserState : public base::SupportsUserData {
30 public:
sdefresnedb52bdf2014-11-13 09:20:3231 ~BrowserState() override;
sdefresnea010b6d2014-11-12 09:32:2032
stuartmorgand7f6a672015-03-31 22:01:1333 // static
34 static scoped_refptr<CertificatePolicyCache> GetCertificatePolicyCache(
35 BrowserState* browser_state);
36
shreyasve8d5f062015-05-26 20:21:4237 // Returns the ActiveStateManager associated with |browser_state.|
38 // Lazily creates one if an ActiveStateManager is not already associated with
39 // the |browser_state|. |browser_state| cannot be a nullptr. Must be accessed
40 // only from the main thread.
41 static ActiveStateManager* GetActiveStateManager(BrowserState* browser_state);
42
43 // Returns the BrowsingDataPartition associated with this browser_state.
44 // Lazily creates one if a BrowsingDataPartition is not already associated
45 // with the |browser_state|. |browser_state| cannot be a nullptr. Must be
46 // accessed only from the main thread.
47 static BrowsingDataPartition* GetBrowsingDataPartition(
48 BrowserState* browser_state);
49
sdefresne6f95f8f2014-11-21 11:21:1050 // Returns whether this BrowserState is incognito. Default is false.
sdefresnea010b6d2014-11-12 09:32:2051 virtual bool IsOffTheRecord() const = 0;
52
sdefresne6f95f8f2014-11-21 11:21:1053 // Returns the path where the BrowserState data is stored.
sdefresne2bbdeed2015-03-02 14:24:2654 // Unlike Profile::GetPath(), incognito BrowserState do not share their path
55 // with their original BrowserState.
56 virtual base::FilePath GetStatePath() const = 0;
sdefresne6f95f8f2014-11-21 11:21:1057
sdefresnea010b6d2014-11-12 09:32:2058 // Returns the request context information associated with this
59 // BrowserState.
60 virtual net::URLRequestContextGetter* GetRequestContext() = 0;
61
sdefresneb30864ac2014-11-21 12:40:5262 // Safely cast a base::SupportsUserData to a BrowserState. Returns nullptr
63 // if |supports_user_data| is not a BrowserState.
64 static BrowserState* FromSupportsUserData(
65 base::SupportsUserData* supports_user_data);
66
sdefresnea010b6d2014-11-12 09:32:2067 protected:
68 BrowserState();
stuartmorganf0e19f912015-04-29 06:01:0169
70 private:
71 friend class URLDataManagerIOS;
72 friend class URLRequestChromeJob;
73
74 // Returns the URLDataManagerIOSBackend instance associated with this
75 // BrowserState, creating it if necessary. Should only be called on the IO
76 // thread.
77 // Not intended for usage outside of //web.
78 URLDataManagerIOSBackend* GetURLDataManagerIOSBackendOnIOThread();
79
80 // The URLDataManagerIOSBackend instance associated with this BrowserState.
81 // Created and destroyed on the IO thread, and should be accessed only from
82 // the IO thread.
83 URLDataManagerIOSBackend* url_data_manager_ios_backend_;
sdefresnea010b6d2014-11-12 09:32:2084};
85
86} // namespace web
87
88#endif // IOS_WEB_PUBLIC_BROWSER_STATE_H_