1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
|
// Copyright (c) 2012 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.
#ifndef CHROME_BROWSER_PROFILES_PROFILE_IMPL_IO_DATA_H_
#define CHROME_BROWSER_PROFILES_PROFILE_IMPL_IO_DATA_H_
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/containers/hash_tables.h"
#include "base/memory/ref_counted.h"
#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
#include "chrome/browser/net/chrome_url_request_context_getter.h"
#include "chrome/browser/profiles/profile_io_data.h"
#include "content/public/browser/cookie_store_factory.h"
namespace chrome_browser_net {
class Predictor;
} // namespace chrome_browser_net
namespace content {
class CookieCryptoDelegate;
} // namespace content
namespace data_reduction_proxy {
class DataReductionProxyConfigurator;
class DataReductionProxyNetworkDelegate;
} // namespace data_reduction_proxy
namespace domain_reliability {
class DomainReliabilityMonitor;
} // namespace domain_reliability
namespace net {
class FtpTransactionFactory;
class HttpServerProperties;
class HttpServerPropertiesManager;
class HttpTransactionFactory;
class ProxyConfig;
class SdchManager;
class SdchOwner;
} // namespace net
namespace storage {
class SpecialStoragePolicy;
} // namespace storage
class ProfileImplIOData : public ProfileIOData {
public:
class Handle {
public:
explicit Handle(Profile* profile);
~Handle();
// Init() must be called before ~Handle(). It records most of the
// parameters needed to construct a ChromeURLRequestContextGetter.
void Init(
const base::FilePath& cookie_path,
const base::FilePath& channel_id_path,
const base::FilePath& cache_path,
int cache_max_size,
const base::FilePath& media_cache_path,
int media_cache_max_size,
const base::FilePath& extensions_cookie_path,
const base::FilePath& profile_path,
const base::FilePath& infinite_cache_path,
chrome_browser_net::Predictor* predictor,
content::CookieStoreConfig::SessionCookieMode session_cookie_mode,
storage::SpecialStoragePolicy* special_storage_policy,
scoped_ptr<domain_reliability::DomainReliabilityMonitor>
domain_reliability_monitor,
const base::Callback<void(bool)>& data_reduction_proxy_unavailable,
scoped_ptr<data_reduction_proxy::DataReductionProxyConfigurator>
data_reduction_proxy_configurator,
scoped_ptr<data_reduction_proxy::DataReductionProxyParams>
data_reduction_proxy_params,
base::WeakPtr<data_reduction_proxy::DataReductionProxyStatisticsPrefs>
data_reduction_proxy_statistics_prefs,
scoped_ptr<data_reduction_proxy::DataReductionProxyEventStore>
data_reduction_proxy_event_store);
// These Create*ContextGetter() functions are only exposed because the
// circular relationship between Profile, ProfileIOData::Handle, and the
// ChromeURLRequestContextGetter factories requires Profile be able to call
// these functions.
scoped_refptr<ChromeURLRequestContextGetter> CreateMainRequestContextGetter(
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors,
PrefService* local_state,
IOThread* io_thread) const;
scoped_refptr<ChromeURLRequestContextGetter>
CreateIsolatedAppRequestContextGetter(
const base::FilePath& partition_path,
bool in_memory,
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector
request_interceptors) const;
content::ResourceContext* GetResourceContext() const;
// GetResourceContextNoInit() does not call LazyInitialize() so it can be
// safely be used during initialization.
content::ResourceContext* GetResourceContextNoInit() const;
scoped_refptr<ChromeURLRequestContextGetter>
GetMediaRequestContextGetter() const;
scoped_refptr<ChromeURLRequestContextGetter>
GetExtensionsRequestContextGetter() const;
scoped_refptr<ChromeURLRequestContextGetter>
GetIsolatedMediaRequestContextGetter(
const base::FilePath& partition_path,
bool in_memory) const;
// Returns the DevToolsNetworkController attached to ProfileIOData.
DevToolsNetworkController* GetDevToolsNetworkController() const;
// Deletes all network related data since |time|. It deletes transport
// security state since |time| and also deletes HttpServerProperties data.
// Works asynchronously, however if the |completion| callback is non-null,
// it will be posted on the UI thread once the removal process completes.
void ClearNetworkingHistorySince(base::Time time,
const base::Closure& completion);
private:
typedef std::map<StoragePartitionDescriptor,
scoped_refptr<ChromeURLRequestContextGetter>,
StoragePartitionDescriptorLess>
ChromeURLRequestContextGetterMap;
// Lazily initialize ProfileParams. We do this on the calls to
// Get*RequestContextGetter(), so we only initialize ProfileParams right
// before posting a task to the IO thread to start using them. This prevents
// objects that are supposed to be deleted on the IO thread, but are created
// on the UI thread from being unnecessarily initialized.
void LazyInitialize() const;
// Collect references to context getters in reverse order, i.e. last item
// will be main request getter. This list is passed to |io_data_|
// for invalidation on IO thread.
scoped_ptr<ChromeURLRequestContextGetterVector> GetAllContextGetters();
// The getters will be invalidated on the IO thread before
// ProfileIOData instance is deleted.
mutable scoped_refptr<ChromeURLRequestContextGetter>
main_request_context_getter_;
mutable scoped_refptr<ChromeURLRequestContextGetter>
media_request_context_getter_;
mutable scoped_refptr<ChromeURLRequestContextGetter>
extensions_request_context_getter_;
mutable ChromeURLRequestContextGetterMap app_request_context_getter_map_;
mutable ChromeURLRequestContextGetterMap
isolated_media_request_context_getter_map_;
ProfileImplIOData* const io_data_;
Profile* const profile_;
mutable bool initialized_;
DISALLOW_COPY_AND_ASSIGN(Handle);
};
bool IsDataReductionProxyEnabled() const override;
private:
friend class base::RefCountedThreadSafe<ProfileImplIOData>;
struct LazyParams {
LazyParams();
~LazyParams();
// All of these parameters are intended to be read on the IO thread.
base::FilePath cookie_path;
base::FilePath channel_id_path;
base::FilePath cache_path;
int cache_max_size;
base::FilePath media_cache_path;
int media_cache_max_size;
base::FilePath extensions_cookie_path;
base::FilePath infinite_cache_path;
content::CookieStoreConfig::SessionCookieMode session_cookie_mode;
scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy;
};
ProfileImplIOData();
~ProfileImplIOData() override;
void InitializeInternal(
scoped_ptr<ChromeNetworkDelegate> chrome_network_delegate,
ProfileParams* profile_params,
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector
request_interceptors) const override;
void InitializeExtensionsRequestContext(
ProfileParams* profile_params) const override;
net::URLRequestContext* InitializeAppRequestContext(
net::URLRequestContext* main_context,
const StoragePartitionDescriptor& partition_descriptor,
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
protocol_handler_interceptor,
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors)
const override;
net::URLRequestContext* InitializeMediaRequestContext(
net::URLRequestContext* original_context,
const StoragePartitionDescriptor& partition_descriptor) const override;
net::URLRequestContext* AcquireMediaRequestContext() const override;
net::URLRequestContext* AcquireIsolatedAppRequestContext(
net::URLRequestContext* main_context,
const StoragePartitionDescriptor& partition_descriptor,
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
protocol_handler_interceptor,
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors)
const override;
net::URLRequestContext* AcquireIsolatedMediaRequestContext(
net::URLRequestContext* app_context,
const StoragePartitionDescriptor& partition_descriptor) const override;
// Deletes all network related data since |time|. It deletes transport
// security state since |time| and also deletes HttpServerProperties data.
// Works asynchronously, however if the |completion| callback is non-null,
// it will be posted on the UI thread once the removal process completes.
void ClearNetworkingHistorySinceOnIOThread(base::Time time,
const base::Closure& completion);
mutable scoped_ptr<data_reduction_proxy::DataReductionProxyNetworkDelegate>
network_delegate_;
// Lazy initialization params.
mutable scoped_ptr<LazyParams> lazy_params_;
mutable scoped_ptr<net::HttpTransactionFactory> main_http_factory_;
mutable scoped_ptr<net::FtpTransactionFactory> ftp_factory_;
// Same as |ProfileIOData::http_server_properties_|, owned there to maintain
// destruction ordering.
mutable net::HttpServerPropertiesManager* http_server_properties_manager_;
mutable scoped_ptr<chrome_browser_net::Predictor> predictor_;
mutable scoped_ptr<net::URLRequestContext> media_request_context_;
mutable scoped_ptr<net::URLRequestJobFactory> main_job_factory_;
mutable scoped_ptr<net::URLRequestJobFactory> extensions_job_factory_;
mutable scoped_ptr<domain_reliability::DomainReliabilityMonitor>
domain_reliability_monitor_;
mutable scoped_ptr<net::SdchManager> sdch_manager_;
mutable scoped_ptr<net::SdchOwner> sdch_policy_;
mutable BooleanPrefMember data_reduction_proxy_enabled_;
// Parameters needed for isolated apps.
base::FilePath profile_path_;
int app_cache_max_size_;
int app_media_cache_max_size_;
DISALLOW_COPY_AND_ASSIGN(ProfileImplIOData);
};
#endif // CHROME_BROWSER_PROFILES_PROFILE_IMPL_IO_DATA_H_
|