Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: chrome/browser/profiles/off_the_record_profile_impl.cc

Issue 2860683002: WIP: Pref service: use the incognito support from Chrome
Patch Set: Rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/profiles/off_the_record_profile_impl.h" 5 #include "chrome/browser/profiles/off_the_record_profile_impl.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
17 #include "base/threading/sequenced_worker_pool.h"
17 #include "build/build_config.h" 18 #include "build/build_config.h"
18 #include "chrome/browser/background/background_contents_service_factory.h" 19 #include "chrome/browser/background/background_contents_service_factory.h"
19 #include "chrome/browser/background_sync/background_sync_controller_factory.h" 20 #include "chrome/browser/background_sync/background_sync_controller_factory.h"
20 #include "chrome/browser/background_sync/background_sync_controller_impl.h" 21 #include "chrome/browser/background_sync/background_sync_controller_impl.h"
21 #include "chrome/browser/browser_process.h" 22 #include "chrome/browser/browser_process.h"
22 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 23 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
23 #include "chrome/browser/dom_distiller/profile_utils.h" 24 #include "chrome/browser/dom_distiller/profile_utils.h"
24 #include "chrome/browser/download/chrome_download_manager_delegate.h" 25 #include "chrome/browser/download/chrome_download_manager_delegate.h"
25 #include "chrome/browser/download/download_core_service.h" 26 #include "chrome/browser/download/download_core_service.h"
26 #include "chrome/browser/download/download_core_service_factory.h" 27 #include "chrome/browser/download/download_core_service_factory.h"
27 #include "chrome/browser/io_thread.h" 28 #include "chrome/browser/io_thread.h"
28 #include "chrome/browser/net/chrome_url_request_context_getter.h" 29 #include "chrome/browser/net/chrome_url_request_context_getter.h"
29 #include "chrome/browser/net/proxy_service_factory.h" 30 #include "chrome/browser/net/proxy_service_factory.h"
30 #include "chrome/browser/permissions/permission_manager.h" 31 #include "chrome/browser/permissions/permission_manager.h"
31 #include "chrome/browser/permissions/permission_manager_factory.h" 32 #include "chrome/browser/permissions/permission_manager_factory.h"
32 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" 33 #include "chrome/browser/plugins/chrome_plugin_service_filter.h"
33 #include "chrome/browser/plugins/plugin_prefs.h" 34 #include "chrome/browser/plugins/plugin_prefs.h"
35 #include "chrome/browser/prefs/browser_prefs.h"
34 #include "chrome/browser/prefs/incognito_mode_prefs.h" 36 #include "chrome/browser/prefs/incognito_mode_prefs.h"
35 #include "chrome/browser/prefs/pref_service_syncable_util.h" 37 #include "chrome/browser/prefs/pref_service_syncable_util.h"
36 #include "chrome/browser/profiles/profile_manager.h" 38 #include "chrome/browser/profiles/profile_manager.h"
37 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h" 39 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h"
38 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate_factory.h" 40 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate_factory.h"
39 #include "chrome/browser/themes/theme_service.h" 41 #include "chrome/browser/themes/theme_service.h"
40 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" 42 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
41 #include "chrome/browser/ui/zoom/chrome_zoom_level_otr_delegate.h" 43 #include "chrome/browser/ui/zoom/chrome_zoom_level_otr_delegate.h"
42 #include "chrome/common/chrome_constants.h" 44 #include "chrome/common/chrome_constants.h"
45 #include "chrome/common/chrome_features.h"
43 #include "chrome/common/chrome_paths.h" 46 #include "chrome/common/chrome_paths.h"
44 #include "chrome/common/chrome_switches.h" 47 #include "chrome/common/chrome_switches.h"
45 #include "chrome/common/features.h" 48 #include "chrome/common/features.h"
46 #include "components/content_settings/core/browser/host_content_settings_map.h" 49 #include "components/content_settings/core/browser/host_content_settings_map.h"
47 #include "components/keyed_service/content/browser_context_dependency_manager.h" 50 #include "components/keyed_service/content/browser_context_dependency_manager.h"
48 #include "components/prefs/json_pref_store.h" 51 #include "components/prefs/json_pref_store.h"
49 #include "components/proxy_config/pref_proxy_config_tracker.h" 52 #include "components/proxy_config/pref_proxy_config_tracker.h"
50 #include "components/sync_preferences/pref_service_syncable.h" 53 #include "components/sync_preferences/pref_service_syncable.h"
51 #include "components/user_prefs/user_prefs.h" 54 #include "components/user_prefs/user_prefs.h"
52 #include "components/zoom/zoom_event_manager.h" 55 #include "components/zoom/zoom_event_manager.h"
53 #include "content/public/browser/browser_thread.h" 56 #include "content/public/browser/browser_thread.h"
54 #include "content/public/browser/host_zoom_map.h" 57 #include "content/public/browser/host_zoom_map.h"
55 #include "content/public/browser/render_process_host.h" 58 #include "content/public/browser/render_process_host.h"
56 #include "content/public/browser/storage_partition.h" 59 #include "content/public/browser/storage_partition.h"
57 #include "content/public/browser/url_data_source.h" 60 #include "content/public/browser/url_data_source.h"
58 #include "content/public/browser/web_contents.h" 61 #include "content/public/browser/web_contents.h"
59 #include "extensions/features/features.h" 62 #include "extensions/features/features.h"
60 #include "net/http/http_server_properties.h" 63 #include "net/http/http_server_properties.h"
61 #include "net/http/transport_security_state.h" 64 #include "net/http/transport_security_state.h"
62 #include "ppapi/features/features.h" 65 #include "ppapi/features/features.h"
66 #include "services/preferences/public/cpp/pref_service_main.h"
67 #include "services/preferences/public/interfaces/preferences.mojom.h"
68 #include "services/service_manager/public/cpp/service.h"
63 #include "storage/browser/database/database_tracker.h" 69 #include "storage/browser/database/database_tracker.h"
64 70
65 #if defined(OS_ANDROID) 71 #if defined(OS_ANDROID)
66 #include "components/prefs/scoped_user_pref_update.h" 72 #include "components/prefs/scoped_user_pref_update.h"
67 #include "components/proxy_config/proxy_prefs.h" 73 #include "components/proxy_config/proxy_prefs.h"
68 #endif // defined(OS_ANDROID) 74 #endif // defined(OS_ANDROID)
69 75
70 #if defined(OS_CHROMEOS) 76 #if defined(OS_CHROMEOS)
71 #include "chrome/browser/chromeos/preferences.h" 77 #include "chrome/browser/chromeos/preferences.h"
72 #include "chrome/browser/chromeos/profiles/profile_helper.h" 78 #include "chrome/browser/chromeos/profiles/profile_helper.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 void* otr_profile) { 114 void* otr_profile) {
109 extensions::ExtensionWebRequestEventRouter::GetInstance() 115 extensions::ExtensionWebRequestEventRouter::GetInstance()
110 ->OnOTRBrowserContextDestroyed(original_profile, otr_profile); 116 ->OnOTRBrowserContextDestroyed(original_profile, otr_profile);
111 } 117 }
112 118
113 } // namespace 119 } // namespace
114 #endif 120 #endif
115 121
116 OffTheRecordProfileImpl::OffTheRecordProfileImpl(Profile* real_profile) 122 OffTheRecordProfileImpl::OffTheRecordProfileImpl(Profile* real_profile)
117 : profile_(real_profile), 123 : profile_(real_profile),
118 prefs_(PrefServiceSyncableIncognitoFromProfile(real_profile)),
119 start_time_(Time::Now()) { 124 start_time_(Time::Now()) {
125 // Must happen before we ask for prefs as prefs needs the connection to the
126 // service manager, which is set up in Initialize.
120 BrowserContext::Initialize(this, profile_->GetPath()); 127 BrowserContext::Initialize(this, profile_->GetPath());
128 service_manager::Connector* otr_connector = nullptr;
129 if (features::PrefServiceEnabled()) {
130 otr_connector = content::BrowserContext::GetConnectorFor(this);
131 }
132 prefs_ = real_profile->CreateOffTheRecordPrefs(otr_connector);
121 // Register on BrowserContext. 133 // Register on BrowserContext.
122 user_prefs::UserPrefs::Set(this, prefs_); 134 user_prefs::UserPrefs::Set(this, prefs_);
123 } 135 }
124 136
125 void OffTheRecordProfileImpl::Init() { 137 void OffTheRecordProfileImpl::Init() {
126 // The construction of OffTheRecordProfileIOData::Handle needs the profile 138 // The construction of OffTheRecordProfileIOData::Handle needs the profile
127 // type returned by this->GetProfileType(). Since GetProfileType() is a 139 // type returned by this->GetProfileType(). Since GetProfileType() is a
128 // virtual member function, we cannot call the function defined in the most 140 // virtual member function, we cannot call the function defined in the most
129 // derived class (e.g. GuestSessionProfile) until a ctor finishes. Thus, 141 // derived class (e.g. GuestSessionProfile) until a ctor finishes. Thus,
130 // we have to instantiate OffTheRecordProfileIOData::Handle here after a ctor. 142 // we have to instantiate OffTheRecordProfileIOData::Handle here after a ctor.
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 } 342 }
331 343
332 net::URLRequestContextGetter* 344 net::URLRequestContextGetter*
333 OffTheRecordProfileImpl::CreateMediaRequestContextForStoragePartition( 345 OffTheRecordProfileImpl::CreateMediaRequestContextForStoragePartition(
334 const base::FilePath& partition_path, 346 const base::FilePath& partition_path,
335 bool in_memory) { 347 bool in_memory) {
336 return io_data_->GetIsolatedAppRequestContextGetter(partition_path, in_memory) 348 return io_data_->GetIsolatedAppRequestContextGetter(partition_path, in_memory)
337 .get(); 349 .get();
338 } 350 }
339 351
352 void OffTheRecordProfileImpl::RegisterInProcessServices(
353 StaticServiceMap* services) {
354 if (features::PrefServiceEnabled()) {
355 content::ServiceInfo info;
356 info.factory = base::Bind(
357 // &prefs::CreatePrefService, std::move(expected),
358 &prefs::CreatePrefService, chrome::ExpectedIncognitoPrefStores(),
359 make_scoped_refptr(content::BrowserThread::GetBlockingPool()));
360 info.task_runner = content::BrowserThread::GetTaskRunnerForThread(
361 content::BrowserThread::IO);
362 services->insert(std::make_pair(prefs::mojom::kServiceName, info));
363 }
364 }
365
340 net::URLRequestContextGetter* OffTheRecordProfileImpl::GetRequestContext() { 366 net::URLRequestContextGetter* OffTheRecordProfileImpl::GetRequestContext() {
341 return GetDefaultStoragePartition(this)->GetURLRequestContext(); 367 return GetDefaultStoragePartition(this)->GetURLRequestContext();
342 } 368 }
343 369
344 net::URLRequestContextGetter* 370 net::URLRequestContextGetter*
345 OffTheRecordProfileImpl::GetRequestContextForExtensions() { 371 OffTheRecordProfileImpl::GetRequestContextForExtensions() {
346 return io_data_->GetExtensionsRequestContextGetter().get(); 372 return io_data_->GetExtensionsRequestContextGetter().get();
347 } 373 }
348 374
349 net::URLRequestContextGetter* 375 net::URLRequestContextGetter*
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 PrefProxyConfigTracker* OffTheRecordProfileImpl::CreateProxyConfigTracker() { 580 PrefProxyConfigTracker* OffTheRecordProfileImpl::CreateProxyConfigTracker() {
555 #if defined(OS_CHROMEOS) 581 #if defined(OS_CHROMEOS)
556 if (chromeos::ProfileHelper::IsSigninProfile(this)) { 582 if (chromeos::ProfileHelper::IsSigninProfile(this)) {
557 return ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState( 583 return ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState(
558 g_browser_process->local_state()); 584 g_browser_process->local_state());
559 } 585 }
560 #endif // defined(OS_CHROMEOS) 586 #endif // defined(OS_CHROMEOS)
561 return ProxyServiceFactory::CreatePrefProxyConfigTrackerOfProfile( 587 return ProxyServiceFactory::CreatePrefProxyConfigTrackerOfProfile(
562 GetPrefs(), g_browser_process->local_state()); 588 GetPrefs(), g_browser_process->local_state());
563 } 589 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/off_the_record_profile_impl.h ('k') | chrome/browser/profiles/profile.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698