Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / profiles / profile_impl.cc
index 7236cda..f770e23 100644 (file)
@@ -12,8 +12,8 @@
 #include "base/compiler_specific.h"
 #include "base/debug/trace_event.h"
 #include "base/environment.h"
-#include "base/file_util.h"
 #include "base/files/file_path.h"
+#include "base/files/file_util.h"
 #include "base/memory/scoped_ptr.h"
 #include "base/path_service.h"
 #include "base/prefs/json_pref_store.h"
@@ -34,8 +34,7 @@
 #include "chrome/browser/chrome_notification_types.h"
 #include "chrome/browser/content_settings/cookie_settings.h"
 #include "chrome/browser/content_settings/host_content_settings_map.h"
-#include "chrome/browser/dom_distiller/dom_distiller_service_factory.h"
-#include "chrome/browser/dom_distiller/lazy_dom_distiller_service.h"
+#include "chrome/browser/dom_distiller/profile_utils.h"
 #include "chrome/browser/domain_reliability/service_factory.h"
 #include "chrome/browser/download/chrome_download_manager_delegate.h"
 #include "chrome/browser/download/download_service.h"
@@ -47,6 +46,7 @@
 #include "chrome/browser/net/proxy_service_factory.h"
 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator.h"
 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
+#include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_factory.h"
 #include "chrome/browser/net/ssl_config_service_manager.h"
 #include "chrome/browser/plugins/chrome_plugin_service_filter.h"
 #include "chrome/browser/plugins/plugin_prefs.h"
 #include "chrome/common/chrome_version_info.h"
 #include "chrome/common/pref_names.h"
 #include "chrome/common/url_constants.h"
+#include "chrome/grit/chromium_strings.h"
 #include "components/bookmarks/browser/bookmark_model.h"
-#include "components/dom_distiller/content/dom_distiller_viewer_source.h"
-#include "components/dom_distiller/core/url_constants.h"
+#include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h"
+#include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.h"
+#include "components/data_reduction_proxy/browser/data_reduction_proxy_statistics_prefs.h"
 #include "components/domain_reliability/monitor.h"
 #include "components/domain_reliability/service.h"
 #include "components/keyed_service/content/browser_context_dependency_manager.h"
 #include "content/public/browser/user_metrics.h"
 #include "content/public/common/content_constants.h"
 #include "content/public/common/page_zoom.h"
-#include "grit/chromium_strings.h"
-#include "grit/generated_resources.h"
 #include "ui/base/l10n/l10n_util.h"
 
 #if defined(OS_ANDROID)
 #include "components/user_manager/user_manager.h"
 #endif
 
-#if defined(SPDY_PROXY_AUTH_ORIGIN)
-#include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_factory.h"
-#include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h"
-#include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.h"
-#endif
-
 #if defined(ENABLE_CONFIGURATION_POLICY)
 #include "chrome/browser/policy/schema_registry_service.h"
 #include "chrome/browser/policy/schema_registry_service_factory.h"
@@ -254,24 +248,6 @@ std::string ExitTypeToSessionTypePrefValue(Profile::ExitType type) {
   return std::string();
 }
 
-// Setup URLDataSource for the chrome-distiller:// scheme for the given
-// |profile|.
-void RegisterDomDistillerViewerSource(Profile* profile) {
-  const CommandLine& command_line = *CommandLine::ForCurrentProcess();
-  if (command_line.HasSwitch(switches::kEnableDomDistiller)) {
-    dom_distiller::DomDistillerServiceFactory* dom_distiller_service_factory =
-        dom_distiller::DomDistillerServiceFactory::GetInstance();
-    // The LazyDomDistillerService deletes itself when the profile is destroyed.
-    dom_distiller::LazyDomDistillerService* lazy_service =
-        new dom_distiller::LazyDomDistillerService(
-            profile, dom_distiller_service_factory);
-    content::URLDataSource::Add(
-        profile,
-        new dom_distiller::DomDistillerViewerSource(
-            lazy_service, dom_distiller::kDomDistillerScheme));
-  }
-}
-
 PrefStore* CreateExtensionPrefStore(Profile* profile,
                                     bool incognito_pref_store) {
 #if defined(ENABLE_EXTENSIONS)
@@ -283,17 +259,6 @@ PrefStore* CreateExtensionPrefStore(Profile* profile,
 #endif
 }
 
-#if !defined(OS_ANDROID)
-// Deletes the file that was used by the AutomaticProfileResetter service, which
-// has since been removed, to store that the prompt had already been shown.
-// TODO(engedy): Remove this and caller in M42 or later. See crbug.com/398813.
-void DeleteResetPromptMementoFile(const base::FilePath& profile_dir) {
-  base::FilePath memento_path =
-      profile_dir.Append(FILE_PATH_LITERAL("Reset Prompt Memento"));
-  base::DeleteFile(memento_path, false);
-}
-#endif
-
 }  // namespace
 
 // static
@@ -502,7 +467,7 @@ ProfileImpl::ProfileImpl(
 
   scoped_refptr<SafeBrowsingService> safe_browsing_service(
       g_browser_process->safe_browsing_service());
-  if (safe_browsing_service) {
+  if (safe_browsing_service.get()) {
     pref_validation_delegate_ =
         safe_browsing_service->CreatePreferenceValidationDelegate(this).Pass();
   }
@@ -666,7 +631,8 @@ void ProfileImpl::DoFinalInit() {
   scoped_ptr<data_reduction_proxy::DataReductionProxyParams>
       data_reduction_proxy_params;
   scoped_ptr<DataReductionProxyChromeConfigurator> chrome_configurator;
-#if defined(SPDY_PROXY_AUTH_ORIGIN)
+  scoped_ptr<data_reduction_proxy::DataReductionProxyStatisticsPrefs>
+      data_reduction_proxy_statistics_prefs;
   DataReductionProxyChromeSettings* data_reduction_proxy_chrome_settings =
       DataReductionProxyChromeSettingsFactory::GetForBrowserContext(this);
   data_reduction_proxy_params =
@@ -687,7 +653,24 @@ void ProfileImpl::DoFinalInit() {
   // settings after ownership is passed.
   DataReductionProxyChromeConfigurator*
       data_reduction_proxy_chrome_configurator = chrome_configurator.get();
+#if defined(OS_ANDROID) || defined(OS_IOS)
+  // On mobile we write data reduction proxy prefs directly to the pref service.
+  // On desktop we store data reduction proxy prefs in memory, writing to disk
+  // every 60 minutes and on termination. Shutdown hooks must be added for
+  // Android and iOS in order for non-zero delays to be supported.
+  // (http://crbug.com/408264)
+  base::TimeDelta commit_delay = base::TimeDelta();
+#else
+  base::TimeDelta commit_delay = base::TimeDelta::FromMinutes(60);
 #endif
+  data_reduction_proxy_statistics_prefs =
+      scoped_ptr<data_reduction_proxy::DataReductionProxyStatisticsPrefs>(
+          new data_reduction_proxy::DataReductionProxyStatisticsPrefs(
+              g_browser_process->local_state(),
+              base::MessageLoopProxy::current(),
+              commit_delay));
+  data_reduction_proxy_chrome_settings->SetDataReductionProxyStatisticsPrefs(
+      data_reduction_proxy_statistics_prefs.get());
 
   // Make sure we initialize the ProfileIOData after everything else has been
   // initialized that we might be reading from the IO thread.
@@ -696,18 +679,16 @@ void ProfileImpl::DoFinalInit() {
                 cache_max_size, media_cache_path, media_cache_max_size,
                 extensions_cookie_path, GetPath(), infinite_cache_path,
                 predictor_, session_cookie_mode, GetSpecialStoragePolicy(),
-                CreateDomainReliabilityMonitor(),
+                CreateDomainReliabilityMonitor(local_state),
                 data_reduction_proxy_unavailable,
                 chrome_configurator.Pass(),
-                data_reduction_proxy_params.Pass());
-
-#if defined(SPDY_PROXY_AUTH_ORIGIN)
+                data_reduction_proxy_params.Pass(),
+                data_reduction_proxy_statistics_prefs.Pass());
   data_reduction_proxy_chrome_settings->InitDataReductionProxySettings(
       data_reduction_proxy_chrome_configurator,
       prefs_.get(),
       g_browser_process->local_state(),
       GetRequestContext());
-#endif
 
 #if defined(ENABLE_PLUGINS)
   ChromePluginServiceFilter::GetInstance()->RegisterResourceContext(
@@ -729,13 +710,6 @@ void ProfileImpl::DoFinalInit() {
   // as a URLDataSource early.
   RegisterDomDistillerViewerSource(this);
 
-#if !defined(OS_ANDROID)
-  BrowserThread::GetBlockingPool()->PostDelayedWorkerTask(
-      FROM_HERE,
-      base::Bind(&DeleteResetPromptMementoFile, GetPath()),
-      base::TimeDelta::FromMilliseconds(2 * create_readme_delay_ms));
-#endif
-
   // Creation has been finished.
   TRACE_EVENT_END1("browser",
                    "Profile::CreateProfile",
@@ -774,7 +748,7 @@ void ProfileImpl::DoFinalInit() {
 }
 
 void ProfileImpl::InitHostZoomMap() {
-  HostZoomMap* host_zoom_map = HostZoomMap::GetForBrowserContext(this);
+  HostZoomMap* host_zoom_map = HostZoomMap::GetDefaultForBrowserContext(this);
   host_zoom_map->SetDefaultZoomLevel(
       prefs_->GetDouble(prefs::kDefaultZoomLevel));
 
@@ -989,10 +963,7 @@ void ProfileImpl::OnPrefsLoaded(bool success) {
   DCHECK(!net_pref_observer_);
   {
     TRACE_EVENT0("browser", "ProfileImpl::OnPrefsLoaded:NetPrefObserver")
-    net_pref_observer_.reset(new NetPrefObserver(
-        prefs_.get(),
-        prerender::PrerenderManagerFactory::GetForProfile(this),
-        predictor_));
+    net_pref_observer_.reset(new NetPrefObserver(prefs_.get()));
   }
 
   chrome_prefs::SchedulePrefsFilePathVerification(path_);
@@ -1149,7 +1120,7 @@ DownloadManagerDelegate* ProfileImpl::GetDownloadManagerDelegate() {
       GetDownloadManagerDelegate();
 }
 
-quota::SpecialStoragePolicy* ProfileImpl::GetSpecialStoragePolicy() {
+storage::SpecialStoragePolicy* ProfileImpl::GetSpecialStoragePolicy() {
 #if defined(ENABLE_EXTENSIONS)
   return GetExtensionSpecialStoragePolicy();
 #else
@@ -1190,7 +1161,7 @@ history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() {
 }
 
 void ProfileImpl::OnDefaultZoomLevelChanged() {
-  HostZoomMap::GetForBrowserContext(this)->SetDefaultZoomLevel(
+  HostZoomMap::GetDefaultForBrowserContext(this)->SetDefaultZoomLevel(
       pref_change_registrar_.prefs()->GetDouble(prefs::kDefaultZoomLevel));
 }
 
@@ -1199,7 +1170,7 @@ void ProfileImpl::OnZoomLevelChanged(
 
   if (change.mode != HostZoomMap::ZOOM_CHANGED_FOR_HOST)
     return;
-  HostZoomMap* host_zoom_map = HostZoomMap::GetForBrowserContext(this);
+  HostZoomMap* host_zoom_map = HostZoomMap::GetDefaultForBrowserContext(this);
   double level = change.zoom_level;
   DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels);
   base::DictionaryValue* host_zoom_dictionary = update.Get();
@@ -1309,8 +1280,7 @@ void ProfileImpl::OnLogin() {
 void ProfileImpl::InitChromeOSPreferences() {
   chromeos_preferences_.reset(new chromeos::Preferences());
   chromeos_preferences_->Init(
-      PrefServiceSyncable::FromProfile(this),
-      chromeos::ProfileHelper::Get()->GetUserByProfile(this));
+      this, chromeos::ProfileHelper::Get()->GetUserByProfile(this));
 }
 
 #endif  // defined(OS_CHROMEOS)
@@ -1456,7 +1426,7 @@ PrefProxyConfigTracker* ProfileImpl::CreateProxyConfigTracker() {
 }
 
 scoped_ptr<domain_reliability::DomainReliabilityMonitor>
-ProfileImpl::CreateDomainReliabilityMonitor() {
+ProfileImpl::CreateDomainReliabilityMonitor(PrefService* local_state) {
   domain_reliability::DomainReliabilityService* service =
       domain_reliability::DomainReliabilityServiceFactory::GetInstance()->
           GetForBrowserContext(this);
@@ -1464,5 +1434,7 @@ ProfileImpl::CreateDomainReliabilityMonitor() {
     return scoped_ptr<domain_reliability::DomainReliabilityMonitor>();
 
   return service->CreateMonitor(
-      BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
+      BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
+      local_state,
+      prefs::kMetricsReportingEnabled);
 }