blob: e5571a17c302393bd2905df8ccf78dd0a199e825 [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"
Colin Blundelld4c96c752017-07-11 07:24:129#include "services/service_manager/embedder/embedded_service_info.h"
sdefresnea010b6d2014-11-12 09:32:2010
sdefresne6f95f8f2014-11-21 11:21:1011namespace base {
12class FilePath;
13}
14
sdefresnea010b6d2014-11-12 09:32:2015namespace net {
16class URLRequestContextGetter;
17}
18
Colin Blundelld4c96c752017-07-11 07:24:1219namespace service_manager {
20class Connector;
21}
22
sdefresnea010b6d2014-11-12 09:32:2023namespace web {
shreyasve8d5f062015-05-26 20:21:4224class ActiveStateManager;
stuartmorgand7f6a672015-03-31 22:01:1325class CertificatePolicyCache;
Colin Blundelld4c96c752017-07-11 07:24:1226class ServiceManagerConnection;
stuartmorganf0e19f912015-04-29 06:01:0127class URLDataManagerIOS;
28class URLDataManagerIOSBackend;
29class URLRequestChromeJob;
sdefresnea010b6d2014-11-12 09:32:2030
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.
34class BrowserState : public base::SupportsUserData {
35 public:
sdefresnedb52bdf2014-11-13 09:20:3236 ~BrowserState() override;
sdefresnea010b6d2014-11-12 09:32:2037
stuartmorgand7f6a672015-03-31 22:01:1338 // static
39 static scoped_refptr<CertificatePolicyCache> GetCertificatePolicyCache(
40 BrowserState* browser_state);
41
sdefresne6eaff4f2015-12-29 17:11:4042 // Returns whether |browser_state| has an associated ActiveStateManager.
43 // Must only be accessed from main thread.
44 static bool HasActiveStateManager(BrowserState* browser_state);
45
shreyasve8d5f062015-05-26 20:21:4246 // 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
sdefresne6f95f8f2014-11-21 11:21:1052 // Returns whether this BrowserState is incognito. Default is false.
sdefresnea010b6d2014-11-12 09:32:2053 virtual bool IsOffTheRecord() const = 0;
54
sdefresne6f95f8f2014-11-21 11:21:1055 // Returns the path where the BrowserState data is stored.
sdefresne2bbdeed2015-03-02 14:24:2656 // Unlike Profile::GetPath(), incognito BrowserState do not share their path
57 // with their original BrowserState.
58 virtual base::FilePath GetStatePath() const = 0;
sdefresne6f95f8f2014-11-21 11:21:1059
sdefresnea010b6d2014-11-12 09:32:2060 // Returns the request context information associated with this
61 // BrowserState.
62 virtual net::URLRequestContextGetter* GetRequestContext() = 0;
63
sdefresneb30864ac2014-11-21 12:40:5264 // 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 Blundelld4c96c752017-07-11 07:24:1269 // 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
sdefresnea010b6d2014-11-12 09:32:2091 protected:
92 BrowserState();
stuartmorganf0e19f912015-04-29 06:01:0193
Colin Blundelld4c96c752017-07-11 07:24:1294 // 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
stuartmorganf0e19f912015-04-29 06:01:01100 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_;
sdefresnea010b6d2014-11-12 09:32:20114};
115
116} // namespace web
117
118#endif // IOS_WEB_PUBLIC_BROWSER_STATE_H_