// Copyright (c) 2011 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_IO_DATA_H_ #define CHROME_BROWSER_PROFILES_PROFILE_IO_DATA_H_ #pragma once #include "base/basictypes.h" #include "base/file_path.h" #include "base/ref_counted.h" #include "base/scoped_ptr.h" #include "chrome/browser/net/chrome_url_request_context.h" #include "chrome/browser/profiles/profile.h" #include "net/base/cookie_monster.h" class CommandLine; class ChromeAppCacheService; class ChromeBlobStorageContext; class ChromeURLRequestContext; class ChromeURLRequestContextGetter; class ExtensionInfoMap; namespace fileapi { class FileSystemContext; } class HostContentSettingsMap; class HostZoomMap; class IOThread; namespace net { class DnsCertProvenanceChecker; class NetLog; class ProxyConfigService; class ProxyService; class SSLConfigService; class TransportSecurityState; } // namespace net namespace prerender { class PrerenderManager; }; // namespace prerender namespace webkit_database { class DatabaseTracker; } // webkit_database // Conceptually speaking, the ProfileIOData represents data that lives on the IO // thread that is owned by a Profile, such as, but not limited to, network // objects like CookieMonster, HttpTransactionFactory, etc. The Profile // implementation will maintain a reference to the ProfileIOData. The // ProfileIOData will originally own a reference to the ChromeURLRequestContexts // that reference its members. When an accessor for a ChromeURLRequestContext is // invoked, then ProfileIOData will release its reference to the // ChromeURLRequestContext and the ChromeURLRequestContext will acquire a // reference to the ProfileIOData, so they exchange ownership. This is done // because it's possible for a context's accessor never to be invoked, so this // ownership reversal prevents shutdown leaks. ProfileIOData will lazily // initialize its members on the first invocation of a ChromeURLRequestContext // accessor. class ProfileIOData : public base::RefCountedThreadSafe { public: // These should only be called at most once each. Ownership is reversed they // get called, from ProfileIOData owning ChromeURLRequestContext to vice // versa. scoped_refptr GetMainRequestContext() const; scoped_refptr GetMediaRequestContext() const; scoped_refptr GetExtensionsRequestContext() const; protected: friend class base::RefCountedThreadSafe; class RequestContext : public ChromeURLRequestContext { public: RequestContext(); ~RequestContext(); // Setter is used to transfer ownership of the ProfileIOData to the context. void set_profile_io_data(const ProfileIOData* profile_io_data) { profile_io_data_ = profile_io_data; } private: scoped_refptr profile_io_data_; }; // Created on the UI thread, read on the IO thread during ProfileIOData lazy // initialization. struct ProfileParams { ProfileParams(); ~ProfileParams(); bool is_off_the_record; bool clear_local_state_on_exit; std::string accept_language; std::string accept_charset; std::string referrer_charset; FilePath user_script_dir_path; scoped_refptr host_content_settings_map; scoped_refptr host_zoom_map; scoped_refptr transport_security_state; scoped_refptr ssl_config_service; scoped_refptr cookie_monster_delegate; scoped_refptr database_tracker; scoped_refptr appcache_service; scoped_refptr blob_storage_context; scoped_refptr file_system_context; scoped_refptr extension_info_map; scoped_refptr prerender_manager; scoped_refptr protocol_handler_registry; // We need to initialize the ProxyConfigService from the UI thread // because on linux it relies on initializing things through gconf, // and needs to be on the main thread. scoped_ptr proxy_config_service; // The profile this struct was populated from. ProfileId profile_id; }; explicit ProfileIOData(bool is_off_the_record); virtual ~ProfileIOData(); // Static helper functions to assist in common operations executed by // subtypes. static void InitializeProfileParams(Profile* profile, ProfileParams* params); static void ApplyProfileParamsToContext(const ProfileParams& profile_params, ChromeURLRequestContext* context); static net::ProxyConfigService* CreateProxyConfigService(Profile* profile); static net::ProxyService* CreateProxyService( net::NetLog* net_log, net::URLRequestContext* context, net::ProxyConfigService* proxy_config_service, const CommandLine& command_line); // Lazy initializes the ProfileIOData object the first time a request context // is requested. The lazy logic is implemented here. The actual initialization // is done in LazyInitializeInternal(), implemented by subtypes. Static helper // functions have been provided to assist in common operations. void LazyInitialize() const; // -------------------------------------------- // Virtual interface for subtypes to implement: // -------------------------------------------- // Does that actual initialization of the ProfileIOData subtype. Subtypes // should use the static helper functions above to implement this. virtual void LazyInitializeInternal() const = 0; // These functions are used to transfer ownership of the lazily initialized // context from ProfileIOData to the URLRequestContextGetter. virtual scoped_refptr AcquireMainRequestContext() const = 0; virtual scoped_refptr AcquireMediaRequestContext() const = 0; virtual scoped_refptr AcquireExtensionsRequestContext() const = 0; mutable bool initialized_; DISALLOW_COPY_AND_ASSIGN(ProfileIOData); }; #endif // CHROME_BROWSER_PROFILES_PROFILE_IO_DATA_H_