blob: 705c1834beb6df1db65d859fed5bca4b14c5d0b3 [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
John Abd-El-Malek07a93f12018-02-08 19:28:258#include <memory>
9
sdefresnea010b6d2014-11-12 09:32:2010#include "base/supports_user_data.h"
Colin Blundelld4c96c752017-07-11 07:24:1211#include "services/service_manager/embedder/embedded_service_info.h"
sdefresnea010b6d2014-11-12 09:32:2012
sdefresne6f95f8f2014-11-21 11:21:1013namespace base {
14class FilePath;
15}
16
sdefresnea010b6d2014-11-12 09:32:2017namespace net {
18class URLRequestContextGetter;
19}
20
John Abd-El-Malek07a93f12018-02-08 19:28:2521namespace network {
22namespace mojom {
23class URLLoaderFactory;
24}
25} // namespace network
26
Colin Blundelld4c96c752017-07-11 07:24:1227namespace service_manager {
28class Connector;
29}
30
sdefresnea010b6d2014-11-12 09:32:2031namespace web {
stuartmorgand7f6a672015-03-31 22:01:1332class CertificatePolicyCache;
Colin Blundelld4c96c752017-07-11 07:24:1233class ServiceManagerConnection;
stuartmorganf0e19f912015-04-29 06:01:0134class URLDataManagerIOS;
35class URLDataManagerIOSBackend;
36class URLRequestChromeJob;
sdefresnea010b6d2014-11-12 09:32:2037
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.
41class BrowserState : public base::SupportsUserData {
42 public:
sdefresnedb52bdf2014-11-13 09:20:3243 ~BrowserState() override;
sdefresnea010b6d2014-11-12 09:32:2044
stuartmorgand7f6a672015-03-31 22:01:1345 // static
46 static scoped_refptr<CertificatePolicyCache> GetCertificatePolicyCache(
47 BrowserState* browser_state);
48
sdefresne6f95f8f2014-11-21 11:21:1049 // Returns whether this BrowserState is incognito. Default is false.
sdefresnea010b6d2014-11-12 09:32:2050 virtual bool IsOffTheRecord() const = 0;
51
sdefresne6f95f8f2014-11-21 11:21:1052 // Returns the path where the BrowserState data is stored.
sdefresne2bbdeed2015-03-02 14:24:2653 // Unlike Profile::GetPath(), incognito BrowserState do not share their path
54 // with their original BrowserState.
55 virtual base::FilePath GetStatePath() const = 0;
sdefresne6f95f8f2014-11-21 11:21:1056
sdefresnea010b6d2014-11-12 09:32:2057 // Returns the request context information associated with this
58 // BrowserState.
59 virtual net::URLRequestContextGetter* GetRequestContext() = 0;
60
John Abd-El-Malek07a93f12018-02-08 19:28:2561 // Returns a URLLoaderFactory that is backed by GetRequestContext.
62 network::mojom::URLLoaderFactory* GetURLLoaderFactory();
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
Ken Rockot543f5e32018-02-04 02:13:5071 // services/service_manager/public/mojom/connector.mojom. By default,
Colin Blundelld4c96c752017-07-11 07:24:1272 // 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:
John Abd-El-Malek07a93f12018-02-08 19:28:25101 class URLLoaderFactory;
stuartmorganf0e19f912015-04-29 06:01:01102 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-Malek07a93f12018-02-08 19:28:25111 std::unique_ptr<URLLoaderFactory> url_loader_factory_;
112
stuartmorganf0e19f912015-04-29 06:01:01113 // 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_;
sdefresnea010b6d2014-11-12 09:32:20117};
118
119} // namespace web
120
121#endif // IOS_WEB_PUBLIC_BROWSER_STATE_H_