text: // 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_OFF_THE_RECORD_PROFILE_IMPL_H_
  #define CHROME_BROWSER_PROFILES_OFF_THE_RECORD_PROFILE_IMPL_H_
  #pragma once
  
  #include <string>
  
  #include "base/gtest_prod_util.h"
  #include "chrome/browser/profiles/off_the_record_profile_io_data.h"
  #include "chrome/browser/profiles/profile.h"
  #include "chrome/browser/ui/browser_list.h"
  #include "content/public/browser/notification_observer.h"
  
  using base::Time;
  using base::TimeDelta;
  
  ////////////////////////////////////////////////////////////////////////////////
  //
  // OffTheRecordProfileImpl is a profile subclass that wraps an existing profile
  // to make it suitable for the incognito mode.
  //
  // Note: This class is a leaf class and is not intended for subclassing.
  // Providing this header file is for unit testing.
  //
  ////////////////////////////////////////////////////////////////////////////////
  class OffTheRecordProfileImpl : public Profile,
                                  public content::NotificationObserver {
   public:
    explicit OffTheRecordProfileImpl(Profile* real_profile);
    virtual ~OffTheRecordProfileImpl();
    void Init();
  
    // Profile implementation.
    virtual std::string GetProfileName() OVERRIDE;
    virtual Profile* GetOffTheRecordProfile() OVERRIDE;
    virtual void DestroyOffTheRecordProfile() OVERRIDE;
    virtual bool HasOffTheRecordProfile() OVERRIDE;
    virtual Profile* GetOriginalProfile() OVERRIDE;
    virtual VisitedLinkMaster* GetVisitedLinkMaster() OVERRIDE;
    virtual ExtensionService* GetExtensionService() OVERRIDE;
    virtual UserScriptMaster* GetUserScriptMaster() OVERRIDE;
    virtual ExtensionDevToolsManager* GetExtensionDevToolsManager() OVERRIDE;
    virtual ExtensionProcessManager* GetExtensionProcessManager() OVERRIDE;
    virtual ExtensionMessageService* GetExtensionMessageService() OVERRIDE;
    virtual ExtensionEventRouter* GetExtensionEventRouter() OVERRIDE;
    virtual ExtensionSpecialStoragePolicy*
        GetExtensionSpecialStoragePolicy() OVERRIDE;
    virtual LazyBackgroundTaskQueue* GetLazyBackgroundTaskQueue() OVERRIDE;
    virtual GAIAInfoUpdateService* GetGAIAInfoUpdateService() OVERRIDE;
    virtual HistoryService* GetHistoryService(ServiceAccessType sat) OVERRIDE;
    virtual HistoryService* GetHistoryServiceWithoutCreating() OVERRIDE;
    virtual FaviconService* GetFaviconService(ServiceAccessType sat) OVERRIDE;
    virtual AutocompleteClassifier* GetAutocompleteClassifier() OVERRIDE;
    virtual history::ShortcutsBackend* GetShortcutsBackend() OVERRIDE;
    virtual WebDataService* GetWebDataService(ServiceAccessType sat) OVERRIDE;
    virtual WebDataService* GetWebDataServiceWithoutCreating() OVERRIDE;
    virtual PrefService* GetPrefs() OVERRIDE;
    virtual PrefService* GetOffTheRecordPrefs() OVERRIDE;
    virtual TemplateURLFetcher* GetTemplateURLFetcher() OVERRIDE;
    virtual net::URLRequestContextGetter*
        GetRequestContextForExtensions() OVERRIDE;
    virtual net::URLRequestContextGetter* GetRequestContextForIsolatedApp(
        const std::string& app_id) OVERRIDE;
    virtual net::SSLConfigService* GetSSLConfigService() OVERRIDE;
    virtual HostContentSettingsMap* GetHostContentSettingsMap() OVERRIDE;
    virtual UserStyleSheetWatcher* GetUserStyleSheetWatcher() OVERRIDE;
    virtual BookmarkModel* GetBookmarkModel() OVERRIDE;
    virtual ProtocolHandlerRegistry* GetProtocolHandlerRegistry() OVERRIDE;
    virtual bool IsSameProfile(Profile* profile) OVERRIDE;
    virtual Time GetStartTime() const OVERRIDE;
    virtual history::TopSites* GetTopSitesWithoutCreating() OVERRIDE;
    virtual history::TopSites* GetTopSites() OVERRIDE;
    virtual void MarkAsCleanShutdown() OVERRIDE;
    virtual void InitExtensions(bool extensions_enabled) OVERRIDE;
    virtual void InitPromoResources() OVERRIDE;
    virtual void InitRegisteredProtocolHandlers() OVERRIDE;
    virtual FilePath last_selected_directory() OVERRIDE;
    virtual void set_last_selected_directory(const FilePath& path) OVERRIDE;
    virtual bool WasCreatedByVersionOrLater(const std::string& version) OVERRIDE;
  
  #if defined(OS_CHROMEOS)
    virtual void SetupChromeOSEnterpriseExtensionObserver() OVERRIDE;
    virtual void InitChromeOSPreferences() OVERRIDE;
  #endif  // defined(OS_CHROMEOS)
  
    virtual ExtensionInfoMap* GetExtensionInfoMap() OVERRIDE;
    virtual ChromeURLDataManager* GetChromeURLDataManager() OVERRIDE;
    virtual PromoCounter* GetInstantPromoCounter() OVERRIDE;
  
  #if defined(OS_CHROMEOS)
    virtual void ChangeAppLocale(const std::string& locale,
                                 AppLocaleChangedVia) OVERRIDE;
    virtual void OnLogin() OVERRIDE;
  #endif  // defined(OS_CHROMEOS)
  
    virtual PrefProxyConfigTracker* GetProxyConfigTracker() OVERRIDE;
  
    virtual chrome_browser_net::Predictor* GetNetworkPredictor() OVERRIDE;
    virtual void ClearNetworkingHistorySince(base::Time time) OVERRIDE;
    virtual GURL GetHomePage() OVERRIDE;
  
    // content::BrowserContext implementation:
    virtual FilePath GetPath() OVERRIDE;
    virtual bool IsOffTheRecord() const OVERRIDE;
    virtual content::DownloadManager* GetDownloadManager() OVERRIDE;
    virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
    virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(
        int renderer_child_id) OVERRIDE;
    virtual net::URLRequestContextGetter* GetRequestContextForMedia() OVERRIDE;
    virtual content::ResourceContext* GetResourceContext() OVERRIDE;
    virtual content::GeolocationPermissionContext*
        GetGeolocationPermissionContext() OVERRIDE;
    virtual content::SpeechRecognitionPreferences*
        GetSpeechRecognitionPreferences() OVERRIDE;
    virtual bool DidLastSessionExitCleanly() OVERRIDE;
    virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE;
  
    // content::NotificationObserver implementation.
    virtual void Observe(int type,
                         const content::NotificationSource& source,
                         const content::NotificationDetails& details) OVERRIDE;
  
   private:
    FRIEND_TEST_ALL_PREFIXES(OffTheRecordProfileImplTest, GetHostZoomMap);
    void InitHostZoomMap();
  
    content::NotificationRegistrar registrar_;
  
    // The real underlying profile.
    Profile* profile_;
  
    // Weak pointer owned by |profile_|.
    PrefService* prefs_;
  
    OffTheRecordProfileIOData::Handle io_data_;
  
    // Must be freed before |io_data_|. While |extension_process_manager_| still
    // lives, we handle incoming resource requests from extension processes and
    // those require access to the ResourceContext owned by |io_data_|.
    scoped_ptr<ExtensionProcessManager> extension_process_manager_;
  
    // We use a non-persistent content settings map for OTR.
    scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
  
    // Time we were started.
    Time start_time_;
  
    FilePath last_selected_directory_;
  
    scoped_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_;
  
    scoped_ptr<ChromeURLDataManager> chrome_url_data_manager_;
  
    DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl);
  };
  
  #endif  // CHROME_BROWSER_PROFILES_OFF_THE_RECORD_PROFILE_IMPL_H_
  