blob: 7afd21863a72ae554584bf3c4bd753b679ab38c0 [file] [log] [blame]
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <memory>
#include "base/supports_user_data.h"
#include "services/network/public/mojom/cookie_manager.mojom.h"
#include "services/network/public/mojom/network_service.mojom.h"
#include "services/network/public/mojom/proxy_resolving_socket.mojom.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
#include "services/service_manager/public/cpp/service.h"
#include "services/service_manager/public/mojom/service.mojom.h"
namespace base {
class FilePath;
class Token;
namespace net {
class URLRequestContextGetter;
namespace network {
class SharedURLLoaderFactory;
class WeakWrapperSharedURLLoaderFactory;
} // namespace network
namespace service_manager {
class Connector;
namespace web {
class CertificatePolicyCache;
class NetworkContextOwner;
class ServiceManagerConnection;
class URLDataManagerIOS;
class URLDataManagerIOSBackend;
class URLRequestChromeJob;
// This class holds the context needed for a browsing session.
// It lives on the UI thread. All these methods must only be called on the UI
// thread.
class BrowserState : public base::SupportsUserData {
~BrowserState() override;
// static
static scoped_refptr<CertificatePolicyCache> GetCertificatePolicyCache(
BrowserState* browser_state);
// Returns whether this BrowserState is incognito. Default is false.
virtual bool IsOffTheRecord() const = 0;
// Returns the path where the BrowserState data is stored.
// Unlike Profile::GetPath(), incognito BrowserState do not share their path
// with their original BrowserState.
virtual base::FilePath GetStatePath() const = 0;
// Returns the request context information associated with this
// BrowserState.
virtual net::URLRequestContextGetter* GetRequestContext() = 0;
// Returns a URLLoaderFactory that is backed by GetRequestContext.
network::mojom::URLLoaderFactory* GetURLLoaderFactory();
// Returns a CookieManager that is backed by GetRequestContext.
network::mojom::CookieManager* GetCookieManager();
// Binds a ProxyResolvingSocketFactory request to NetworkContext.
void GetProxyResolvingSocketFactory(
network::mojom::ProxyResolvingSocketFactoryRequest request);
// Like URLLoaderFactory, but wrapped inside SharedURLLoaderFactory
virtual scoped_refptr<network::SharedURLLoaderFactory>
// Safely cast a base::SupportsUserData to a BrowserState. Returns nullptr
// if |supports_user_data| is not a BrowserState.
static BrowserState* FromSupportsUserData(
base::SupportsUserData* supports_user_data);
// Returns a service instance group associated with this BrowserState. This ID
// is not persistent across runs. See
// services/service_manager/public/mojom/connector.mojom. By default,
// this instance group ID is randomly generated when Initialize() is called.
static const base::Token& GetServiceInstanceGroupFor(
BrowserState* browser_state);
// Returns a Connector associated with this BrowserState, which can be used
// to connect to service instances bound as this user.
static service_manager::Connector* GetConnectorFor(
BrowserState* browser_state);
// Returns a ServiceManagerConnection associated with this BrowserState,
// which can be used to connect to service instances bound as this user.
static ServiceManagerConnection* GetServiceManagerConnectionFor(
BrowserState* browser_state);
// Handles an incoming request for a per-browser-state service.
virtual std::unique_ptr<service_manager::Service> HandleServiceRequest(
const std::string& service_name,
service_manager::mojom::ServiceRequest request);
// Updates |cors_exempt_header_list| field of the given |param| to register
// headers that are used in content for special purpose and should not be
// blocked by CORS checks.
virtual void UpdateCorsExemptHeader(
network::mojom::NetworkContextParams* params) {}
// Makes the Service Manager aware of this BrowserState, and assigns an
// instance group ID to it. Must be called for each BrowserState created.
// |path| should be the same path that would be returned by GetStatePath().
static void Initialize(BrowserState* browser_state,
const base::FilePath& path);
friend class URLDataManagerIOS;
friend class URLRequestChromeJob;
// Returns the URLDataManagerIOSBackend instance associated with this
// BrowserState, creating it if necessary. Should only be called on the IO
// thread.
// Not intended for usage outside of //web.
URLDataManagerIOSBackend* GetURLDataManagerIOSBackendOnIOThread();
void CreateNetworkContextIfNecessary();
network::mojom::URLLoaderFactoryPtr url_loader_factory_;
network::mojom::CookieManagerPtr cookie_manager_;
network::mojom::NetworkContextPtr network_context_;
// Owns the network::NetworkContext that backs |url_loader_factory_|. Created
// on the UI thread, destroyed on the IO thread.
std::unique_ptr<NetworkContextOwner> network_context_owner_;
// The URLDataManagerIOSBackend instance associated with this BrowserState.
// Created and destroyed on the IO thread, and should be accessed only from
// the IO thread.
URLDataManagerIOSBackend* url_data_manager_ios_backend_;
} // namespace web