blob: 7f05c2cb334e6eb1666f0f64a5509840c8c8be78 [file] [log] [blame]
[email protected]ea12b5b2012-01-06 21:27:151// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]5a0b42e2010-07-30 23:42:592// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]8ecad5e2010-12-02 21:18:335#include "chrome/browser/profiles/profile_impl.h"
[email protected]5a0b42e2010-07-30 23:42:596
[email protected]54b8e182014-05-02 18:08:297#include <vector>
8
[email protected]791be422011-10-29 19:21:019#include "base/bind.h"
[email protected]a6a7ced2012-11-01 17:24:1810#include "base/callback.h"
[email protected]5a0b42e2010-07-30 23:42:5911#include "base/command_line.h"
[email protected]f6c21cb2011-02-16 19:45:4112#include "base/compiler_specific.h"
[email protected]76b90d312010-08-03 03:00:5013#include "base/environment.h"
[email protected]57999812013-02-24 05:40:5214#include "base/files/file_path.h"
thestig18dfb7a52014-08-26 10:44:0415#include "base/files/file_util.h"
[email protected]3b63f8f42011-03-28 01:54:1516#include "base/memory/scoped_ptr.h"
wjmaclean2c98cb192014-11-26 19:55:2717#include "base/memory/weak_ptr.h"
rkaplow058da3132015-02-19 18:18:3818#include "base/metrics/histogram_macros.h"
[email protected]5a0b42e2010-07-30 23:42:5919#include "base/path_service.h"
[email protected]0de615a2012-11-08 04:40:5920#include "base/prefs/json_pref_store.h"
[email protected]9eec53fe2013-10-30 20:21:1721#include "base/prefs/scoped_user_pref_update.h"
[email protected]3ea1b182013-02-08 22:38:4122#include "base/strings/string_number_conversions.h"
[email protected]76fb05c2013-06-11 04:38:0523#include "base/strings/string_util.h"
24#include "base/strings/stringprintf.h"
[email protected]e309f312013-06-07 21:50:0825#include "base/strings/utf_string_conversions.h"
[email protected]0de615a2012-11-08 04:40:5926#include "base/synchronization/waitable_event.h"
27#include "base/threading/sequenced_worker_pool.h"
calamityf4f08cfe2015-06-17 02:39:0228#include "base/threading/thread_restrictions.h"
primiano6221e572015-01-28 12:14:3429#include "base/trace_event/trace_event.h"
[email protected]1bee6ed2012-03-14 06:46:3630#include "base/version.h"
[email protected]a07676b22011-06-17 16:36:5331#include "chrome/browser/background/background_contents_service_factory.h"
[email protected]68b93512013-02-08 18:17:5732#include "chrome/browser/bookmarks/bookmark_model_factory.h"
[email protected]5a0b42e2010-07-30 23:42:5933#include "chrome/browser/browser_process.h"
[email protected]25ff0862013-07-12 00:59:0334#include "chrome/browser/chrome_notification_types.h"
drogerb1716972015-06-30 09:04:0935#include "chrome/browser/content_settings/cookie_settings_factory.h"
nyquist6e3ab0a52014-09-26 17:54:2536#include "chrome/browser/dom_distiller/profile_utils.h"
[email protected]fba33a02014-06-22 15:42:1637#include "chrome/browser/domain_reliability/service_factory.h"
[email protected]47665442012-07-27 02:31:2238#include "chrome/browser/download/chrome_download_manager_delegate.h"
[email protected]9bb54ee2011-10-12 17:43:3539#include "chrome/browser/download/download_service.h"
40#include "chrome/browser/download/download_service_factory.h"
[email protected]dd830072010-10-05 09:32:4441#include "chrome/browser/net/net_pref_observer.h"
[email protected]67372ecf2011-09-10 01:30:4642#include "chrome/browser/net/predictor.h"
[email protected]53c5b0f2013-07-22 10:54:1143#include "chrome/browser/net/pref_proxy_config_tracker.h"
[email protected]6f96cbcb2011-11-04 02:26:0744#include "chrome/browser/net/proxy_service_factory.h"
[email protected]5a0b42e2010-07-30 23:42:5945#include "chrome/browser/net/ssl_config_service_manager.h"
mlamouri4e372022015-03-29 14:51:0646#include "chrome/browser/permissions/permission_manager.h"
47#include "chrome/browser/permissions/permission_manager_factory.h"
[email protected]c2295f72013-01-03 22:18:5648#include "chrome/browser/plugins/chrome_plugin_service_filter.h"
[email protected]0f5e57f52012-09-20 20:53:1849#include "chrome/browser/plugins/plugin_prefs.h"
[email protected]d81bb3e2013-05-02 18:17:0350#include "chrome/browser/policy/profile_policy_connector.h"
51#include "chrome/browser/policy/profile_policy_connector_factory.h"
[email protected]37858e52010-08-26 00:22:0252#include "chrome/browser/prefs/browser_prefs.h"
[email protected]5b199522012-12-22 17:24:4453#include "chrome/browser/prefs/chrome_pref_service_factory.h"
[email protected]c753f142013-02-10 13:14:0454#include "chrome/browser/prefs/pref_service_syncable.h"
[email protected]086dfcb2014-05-26 23:43:0355#include "chrome/browser/prefs/tracked/tracked_preference_validation_delegate.h"
[email protected]3085c502011-10-05 17:50:5056#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]68b93512013-02-08 18:17:5757#include "chrome/browser/profiles/bookmark_model_loaded_observer.h"
[email protected]1bee6ed2012-03-14 06:46:3658#include "chrome/browser/profiles/chrome_version_service.h"
[email protected]933b3f62013-01-03 20:44:2159#include "chrome/browser/profiles/gaia_info_update_service_factory.h"
[email protected]10ce4cf2012-06-26 20:09:1660#include "chrome/browser/profiles/profile_destroyer.h"
[email protected]e8e78092011-09-29 18:15:3861#include "chrome/browser/profiles/profile_info_cache.h"
[email protected]8ecad5e2010-12-02 21:18:3362#include "chrome/browser/profiles/profile_manager.h"
[email protected]e34796d2013-11-28 19:56:3763#include "chrome/browser/profiles/profile_metrics.h"
b.kelemen4596b512015-03-04 18:42:4764#include "chrome/browser/push_messaging/push_messaging_service_factory.h"
65#include "chrome/browser/push_messaging/push_messaging_service_impl.h"
[email protected]0823c68d2014-06-13 22:23:4766#include "chrome/browser/safe_browsing/safe_browsing_service.h"
[email protected]c5c89d042014-06-13 14:43:3767#include "chrome/browser/services/gcm/gcm_profile_service.h"
[email protected]92371eb2011-04-28 11:50:1568#include "chrome/browser/sessions/session_service_factory.h"
rogerta614597db2014-12-05 17:57:3269#include "chrome/browser/signin/signin_manager_factory.h"
[email protected]9086ce5a2014-08-14 15:15:0470#include "chrome/browser/signin/signin_ui_util.h"
[email protected]c5bbe0e2014-08-01 23:23:3071#include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h"
72#include "chrome/browser/ssl/chrome_ssl_host_state_delegate_factory.h"
[email protected]fe7c4872012-05-10 20:06:0373#include "chrome/browser/ui/startup/startup_browser_creator.h"
wjmacleane530aa742014-10-14 21:43:3074#include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h"
[email protected]5a0b42e2010-07-30 23:42:5975#include "chrome/common/chrome_constants.h"
[email protected]b411da32010-11-24 02:23:1576#include "chrome/common/chrome_paths_internal.h"
[email protected]5a0b42e2010-07-30 23:42:5977#include "chrome/common/chrome_switches.h"
[email protected]5a0b42e2010-07-30 23:42:5978#include "chrome/common/pref_names.h"
[email protected]671f9c62011-10-28 19:22:0779#include "chrome/common/url_constants.h"
[email protected]af39f002014-08-22 10:18:1880#include "chrome/grit/chromium_strings.h"
[email protected]a90c8ca2014-05-20 17:16:0481#include "components/bookmarks/browser/bookmark_model.h"
drogerb1716972015-06-30 09:04:0982#include "components/content_settings/core/browser/cookie_settings.h"
mukai8eaec822014-10-25 17:53:1683#include "components/content_settings/core/browser/host_content_settings_map.h"
[email protected]fba33a02014-06-22 15:42:1684#include "components/domain_reliability/monitor.h"
85#include "components/domain_reliability/service.h"
[email protected]540380fc2014-03-14 10:10:3486#include "components/keyed_service/content/browser_context_dependency_manager.h"
[email protected]d6147bd2014-06-11 01:58:1987#include "components/metrics/metrics_service.h"
blundell2102f7c2015-07-09 10:00:5388#include "components/omnibox/browser/autocomplete_classifier.h"
89#include "components/omnibox/browser/shortcuts_backend.h"
[email protected]f0c8c4992014-05-15 17:37:2690#include "components/pref_registry/pref_registry_syncable.h"
rogerta614597db2014-12-05 17:57:3291#include "components/signin/core/browser/signin_manager.h"
wjmaclean7f63c6b2014-12-09 14:59:5592#include "components/ui/zoom/zoom_event_manager.h"
rsleevi24f64dc22015-08-07 21:39:2193#include "components/url_formatter/url_fixer.h"
[email protected]75fee372013-03-06 00:42:4494#include "components/user_prefs/user_prefs.h"
[email protected]c38831a12011-10-28 12:44:4995#include "content/public/browser/browser_thread.h"
[email protected]4d63bbd2012-08-07 09:23:5296#include "content/public/browser/dom_storage_context.h"
[email protected]ad50def52011-10-19 23:17:0797#include "content/public/browser/notification_service.h"
[email protected]fb29e6cf2012-07-12 21:27:2098#include "content/public/browser/render_process_host.h"
[email protected]4c3a23582012-08-18 08:54:3499#include "content/public/browser/storage_partition.h"
[email protected]7e856dde2014-03-15 00:34:05100#include "content/public/browser/url_data_source.h"
[email protected]7f6f44c2011-12-14 13:23:38101#include "content/public/browser/user_metrics.h"
[email protected]3307537b2012-08-29 03:15:15102#include "content/public/common/content_constants.h"
[email protected]54b8e182014-05-02 18:08:29103#include "content/public/common/page_zoom.h"
[email protected]65a9cc12012-03-20 15:10:18104#include "ui/base/l10n/l10n_util.h"
[email protected]5a0b42e2010-07-30 23:42:59105
[email protected]566755f82014-01-08 01:14:57106#if defined(OS_ANDROID)
107#include "chrome/browser/media/protected_media_identifier_permission_context.h"
108#include "chrome/browser/media/protected_media_identifier_permission_context_factory.h"
[email protected]1df3d972014-06-11 04:55:18109#endif
110
111#if defined(OS_CHROMEOS)
112#include "chrome/browser/chromeos/locale_change_guard.h"
[email protected]1df3d972014-06-11 04:55:18113#include "chrome/browser/chromeos/preferences.h"
114#include "chrome/browser/chromeos/profiles/profile_helper.h"
[email protected]4d390782014-08-15 09:22:58115#include "components/user_manager/user_manager.h"
[email protected]1df3d972014-06-11 04:55:18116#endif
[email protected]566755f82014-01-08 01:14:57117
thestige4155842014-10-20 18:58:02118#if defined(ENABLE_BACKGROUND)
119#include "chrome/browser/background/background_mode_manager.h"
120#endif
121
[email protected]e1480482013-09-11 11:49:58122#if defined(ENABLE_CONFIGURATION_POLICY)
[email protected]eb83c392013-11-07 12:53:24123#include "chrome/browser/policy/schema_registry_service.h"
124#include "chrome/browser/policy/schema_registry_service_factory.h"
[email protected]97275822014-01-21 19:30:36125#include "components/policy/core/browser/browser_policy_connector.h"
[email protected]e1480482013-09-11 11:49:58126#if defined(OS_CHROMEOS)
nkostylev4d2391a2014-11-14 16:15:04127#include "chrome/browser/chromeos/login/session/user_session_manager.h"
[email protected]e1480482013-09-11 11:49:58128#include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h"
129#include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chromeos.h"
130#else
[email protected]e1480482013-09-11 11:49:58131#include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h"
[email protected]d769050f2013-12-12 17:48:01132#include "components/policy/core/common/cloud/user_cloud_policy_manager.h"
[email protected]e1480482013-09-11 11:49:58133#endif
134#endif
135
[email protected]1df3d972014-06-11 04:55:18136#if defined(ENABLE_EXTENSIONS)
[email protected]dfc0424c2014-07-25 21:33:20137#include "chrome/browser/extensions/extension_service.h"
138#include "chrome/browser/extensions/extension_special_storage_policy.h"
[email protected]dfc0424c2014-07-25 21:33:20139#include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
fsamuel8dfa19a2015-05-05 01:00:39140#include "components/guest_view/browser/guest_view_manager.h"
[email protected]dfc0424c2014-07-25 21:33:20141#include "extensions/browser/extension_pref_store.h"
142#include "extensions/browser/extension_pref_value_map.h"
143#include "extensions/browser/extension_pref_value_map_factory.h"
144#include "extensions/browser/extension_system.h"
[email protected]1df3d972014-06-11 04:55:18145#endif
146
treib87bb89cbb2014-12-01 16:01:47147#if defined(ENABLE_SUPERVISED_USERS)
knn95221ffe2015-03-04 20:42:43148#include "chrome/browser/content_settings/content_settings_supervised_provider.h"
treib3c8cf132014-12-08 15:09:32149#include "chrome/browser/supervised_user/supervised_user_constants.h"
[email protected]cce15bb2014-06-17 13:43:51150#include "chrome/browser/supervised_user/supervised_user_settings_service.h"
151#include "chrome/browser/supervised_user/supervised_user_settings_service_factory.h"
[email protected]e1480482013-09-11 11:49:58152#endif
153
[email protected]5a0b42e2010-07-30 23:42:59154using base::Time;
155using base::TimeDelta;
[email protected]e6e30ac2014-01-13 21:24:39156using base::UserMetricsAction;
tfarinaa0ec34e2015-01-12 18:46:48157using bookmarks::BookmarkModel;
[email protected]631bb742011-11-02 11:29:39158using content::BrowserThread;
[email protected]b441a8492012-06-06 14:55:57159using content::DownloadManagerDelegate;
[email protected]5a0b42e2010-07-30 23:42:59160
161namespace {
162
[email protected]cdb756ef2012-04-05 18:34:53163#if defined(ENABLE_SESSION_SERVICE)
[email protected]5a0b42e2010-07-30 23:42:59164// Delay, in milliseconds, before we explicitly create the SessionService.
[email protected]dfc0424c2014-07-25 21:33:20165const int kCreateSessionServiceDelayMS = 500;
[email protected]cdb756ef2012-04-05 18:34:53166#endif
[email protected]5a0b42e2010-07-30 23:42:59167
[email protected]65a9cc12012-03-20 15:10:18168// Text content of README file created in each profile directory. Both %s
169// placeholders must contain the product name. This is not localizable and hence
170// not in resources.
[email protected]dfc0424c2014-07-25 21:33:20171const char kReadmeText[] =
[email protected]65a9cc12012-03-20 15:10:18172 "%s settings and storage represent user-selected preferences and "
173 "information and MUST not be extracted, overwritten or modified except "
174 "through %s defined APIs.";
175
[email protected]6c0ca7fc2012-10-05 16:27:22176// Value written to prefs for EXIT_CRASHED and EXIT_SESSION_ENDED.
[email protected]dfc0424c2014-07-25 21:33:20177const char kPrefExitTypeCrashed[] = "Crashed";
178const char kPrefExitTypeSessionEnded[] = "SessionEnded";
[email protected]6c0ca7fc2012-10-05 16:27:22179
calamityf4f08cfe2015-06-17 02:39:02180void CreateProfileReadme(const base::FilePath& profile_path) {
181 base::ThreadRestrictions::AssertIOAllowed();
182 base::FilePath readme_path = profile_path.Append(chrome::kReadmeFilename);
183 std::string product_name = l10n_util::GetStringUTF8(IDS_PRODUCT_NAME);
184 std::string readme_text = base::StringPrintf(
185 kReadmeText, product_name.c_str(), product_name.c_str());
186 if (base::WriteFile(readme_path, readme_text.data(), readme_text.size()) ==
187 -1) {
188 LOG(ERROR) << "Could not create README file.";
189 }
190}
191
[email protected]0de615a2012-11-08 04:40:59192// Helper method needed because PostTask cannot currently take a Callback
193// function with non-void return type.
[email protected]650b2d52013-02-10 03:41:45194void CreateDirectoryAndSignal(const base::FilePath& path,
calamityf4f08cfe2015-06-17 02:39:02195 base::WaitableEvent* done_creating,
196 bool create_readme) {
197 // If the readme exists, the profile directory must also already exist.
198 base::FilePath readme_path = path.Append(chrome::kReadmeFilename);
199 if (base::PathExists(readme_path)) {
200 done_creating->Signal();
201 return;
202 }
203
[email protected]0de615a2012-11-08 04:40:59204 DVLOG(1) << "Creating directory " << path.value();
calamityf4f08cfe2015-06-17 02:39:02205 if (base::CreateDirectory(path) && create_readme)
206 CreateProfileReadme(path);
[email protected]0de615a2012-11-08 04:40:59207 done_creating->Signal();
208}
209
210// Task that blocks the FILE thread until CreateDirectoryAndSignal() finishes on
211// blocking I/O pool.
212void BlockFileThreadOnDirectoryCreate(base::WaitableEvent* done_creating) {
213 done_creating->Wait();
214}
215
216// Initiates creation of profile directory on |sequenced_task_runner| and
calamityf4f08cfe2015-06-17 02:39:02217// ensures that FILE thread is blocked until that operation finishes. If
218// |create_readme| is true, the profile README will be created in the profile
219// directory.
[email protected]0de615a2012-11-08 04:40:59220void CreateProfileDirectory(base::SequencedTaskRunner* sequenced_task_runner,
calamityf4f08cfe2015-06-17 02:39:02221 const base::FilePath& path,
222 bool create_readme) {
[email protected]0de615a2012-11-08 04:40:59223 base::WaitableEvent* done_creating = new base::WaitableEvent(false, false);
calamityf4f08cfe2015-06-17 02:39:02224 sequenced_task_runner->PostTask(
225 FROM_HERE, base::Bind(&CreateDirectoryAndSignal, path, done_creating,
226 create_readme));
[email protected]0de615a2012-11-08 04:40:59227 // Block the FILE thread until directory is created on I/O pool to make sure
228 // that we don't attempt any operation until that part completes.
229 BrowserThread::PostTask(
230 BrowserThread::FILE, FROM_HERE,
231 base::Bind(&BlockFileThreadOnDirectoryCreate,
232 base::Owned(done_creating)));
233}
234
[email protected]650b2d52013-02-10 03:41:45235base::FilePath GetCachePath(const base::FilePath& base) {
[email protected]5a0b42e2010-07-30 23:42:59236 return base.Append(chrome::kCacheDirname);
237}
238
[email protected]650b2d52013-02-10 03:41:45239base::FilePath GetMediaCachePath(const base::FilePath& base) {
[email protected]5a0b42e2010-07-30 23:42:59240 return base.Append(chrome::kMediaCacheDirname);
241}
242
[email protected]6c0ca7fc2012-10-05 16:27:22243// Converts the kSessionExitedCleanly pref to the corresponding EXIT_TYPE.
244Profile::ExitType SessionTypePrefValueToExitType(const std::string& value) {
245 if (value == kPrefExitTypeSessionEnded)
246 return Profile::EXIT_SESSION_ENDED;
247 if (value == kPrefExitTypeCrashed)
248 return Profile::EXIT_CRASHED;
249 return Profile::EXIT_NORMAL;
250}
251
252// Converts an ExitType into a string that is written to prefs.
253std::string ExitTypeToSessionTypePrefValue(Profile::ExitType type) {
254 switch (type) {
255 case Profile::EXIT_NORMAL:
256 return ProfileImpl::kPrefExitTypeNormal;
257 case Profile::EXIT_SESSION_ENDED:
258 return kPrefExitTypeSessionEnded;
259 case Profile::EXIT_CRASHED:
260 return kPrefExitTypeCrashed;
261 }
262 NOTREACHED();
263 return std::string();
264}
265
[email protected]dfc0424c2014-07-25 21:33:20266PrefStore* CreateExtensionPrefStore(Profile* profile,
267 bool incognito_pref_store) {
268#if defined(ENABLE_EXTENSIONS)
269 return new ExtensionPrefStore(
270 ExtensionPrefValueMapFactory::GetForBrowserContext(profile),
271 incognito_pref_store);
272#else
273 return NULL;
274#endif
275}
276
[email protected]5a0b42e2010-07-30 23:42:59277} // namespace
278
279// static
[email protected]650b2d52013-02-10 03:41:45280Profile* Profile::CreateProfile(const base::FilePath& path,
[email protected]00b33f802012-03-13 07:46:03281 Delegate* delegate,
282 CreateMode create_mode) {
rkaplow058da3132015-02-19 18:18:38283 TRACE_EVENT1("browser,startup",
284 "Profile::CreateProfile",
285 "profile_path",
286 path.AsUTF8Unsafe());
[email protected]afe10992014-06-26 17:48:07287
[email protected]0de615a2012-11-08 04:40:59288 // Get sequenced task runner for making sure that file operations of
289 // this profile (defined by |path|) are executed in expected order
290 // (what was previously assured by the FILE thread).
291 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner =
292 JsonPrefStore::GetTaskRunnerForFile(path,
293 BrowserThread::GetBlockingPool());
[email protected]00b33f802012-03-13 07:46:03294 if (create_mode == CREATE_MODE_ASYNCHRONOUS) {
295 DCHECK(delegate);
calamityf4f08cfe2015-06-17 02:39:02296 CreateProfileDirectory(sequenced_task_runner.get(), path, true);
[email protected]00b33f802012-03-13 07:46:03297 } else if (create_mode == CREATE_MODE_SYNCHRONOUS) {
[email protected]7567484142013-07-11 17:36:07298 if (!base::PathExists(path)) {
rkaplow058da3132015-02-19 18:18:38299 // TODO(rogerta): http://crbug/160553 - Bad things happen if we can't
300 // write to the profile directory. We should eventually be able to run in
301 // this situation.
[email protected]426d1c92013-12-03 20:08:54302 if (!base::CreateDirectory(path))
[email protected]00b33f802012-03-13 07:46:03303 return NULL;
calamityf4f08cfe2015-06-17 02:39:02304
305 CreateProfileReadme(path);
[email protected]00b33f802012-03-13 07:46:03306 }
307 } else {
308 NOTREACHED();
[email protected]844a1002011-04-19 11:37:21309 }
[email protected]844a1002011-04-19 11:37:21310
[email protected]5173de8b2013-06-02 21:16:02311 return new ProfileImpl(
312 path, delegate, create_mode, sequenced_task_runner.get());
[email protected]5a0b42e2010-07-30 23:42:59313}
314
[email protected]e19cf1e2010-10-01 12:31:34315// static
[email protected]6c0ca7fc2012-10-05 16:27:22316const char* const ProfileImpl::kPrefExitTypeNormal = "Normal";
317
318// static
[email protected]37ca3fe02013-07-05 15:32:44319void ProfileImpl::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:34320 user_prefs::PrefRegistrySyncable* registry) {
raymesaa608722015-04-27 03:00:25321 registry->RegisterBooleanPref(prefs::kSavingBrowserHistoryDisabled, false);
322 registry->RegisterBooleanPref(prefs::kAllowDeletingBrowserHistory, true);
323 registry->RegisterBooleanPref(prefs::kSigninAllowed, true);
324 registry->RegisterBooleanPref(prefs::kForceGoogleSafeSearch, false);
325 registry->RegisterBooleanPref(prefs::kForceYouTubeSafetyMode, false);
326 registry->RegisterBooleanPref(prefs::kRecordHistory, false);
[email protected]443e9312013-05-06 06:17:34327 registry->RegisterIntegerPref(
328 prefs::kProfileAvatarIndex,
329 -1,
330 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
[email protected]1cdf0932014-08-16 06:00:49331 // Whether a profile is using an avatar without having explicitely chosen it
332 // (i.e. was assigned by default by legacy profile creation).
333 registry->RegisterBooleanPref(
334 prefs::kProfileUsingDefaultAvatar,
335 true,
336 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
337 registry->RegisterBooleanPref(
338 prefs::kProfileUsingGAIAAvatar,
339 false,
340 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
341 // Whether a profile is using a default avatar name (eg. Pickles or Person 1).
342 registry->RegisterBooleanPref(
343 prefs::kProfileUsingDefaultName,
344 true,
345 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
raymesaa608722015-04-27 03:00:25346 registry->RegisterStringPref(prefs::kSupervisedUserId, std::string());
[email protected]443e9312013-05-06 06:17:34347 registry->RegisterStringPref(prefs::kProfileName,
348 std::string(),
349 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
[email protected]c753f142013-02-10 13:14:04350 registry->RegisterStringPref(prefs::kHomePage,
351 std::string(),
[email protected]443e9312013-05-06 06:17:34352 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
[email protected]0045b0f42012-07-26 11:52:08353#if defined(ENABLE_PRINTING)
raymesaa608722015-04-27 03:00:25354 registry->RegisterBooleanPref(prefs::kPrintingEnabled, true);
[email protected]0045b0f42012-07-26 11:52:08355#endif
raymesaa608722015-04-27 03:00:25356 registry->RegisterBooleanPref(prefs::kPrintPreviewDisabled, false);
357 registry->RegisterBooleanPref(prefs::kForceEphemeralProfiles, false);
[email protected]bca18382012-06-25 19:15:23358
359 // Initialize the cache prefs.
raymesaa608722015-04-27 03:00:25360 registry->RegisterFilePathPref(prefs::kDiskCacheDir, base::FilePath());
361 registry->RegisterIntegerPref(prefs::kDiskCacheSize, 0);
362 registry->RegisterIntegerPref(prefs::kMediaCacheSize, 0);
[email protected]bf510ed2012-06-05 08:31:43363
364 // Deprecated. Kept around for migration.
[email protected]443e9312013-05-06 06:17:34365 registry->RegisterBooleanPref(
366 prefs::kClearSiteDataOnExit,
367 false,
368 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
[email protected]e19cf1e2010-10-01 12:31:34369}
370
[email protected]0de615a2012-11-08 04:40:59371ProfileImpl::ProfileImpl(
[email protected]650b2d52013-02-10 03:41:45372 const base::FilePath& path,
[email protected]0de615a2012-11-08 04:40:59373 Delegate* delegate,
374 CreateMode create_mode,
375 base::SequencedTaskRunner* sequenced_task_runner)
[email protected]117832812013-10-02 07:06:02376 : path_(path),
[email protected]443e9312013-05-06 06:17:34377 pref_registry_(new user_prefs::PrefRegistrySyncable),
[email protected]9c009092013-05-01 03:14:09378 io_data_(this),
[email protected]5a0b42e2010-07-30 23:42:59379 host_content_settings_map_(NULL),
[email protected]6c0ca7fc2012-10-05 16:27:22380 last_session_exit_type_(EXIT_NORMAL),
[email protected]5a0b42e2010-07-30 23:42:59381 start_time_(Time::Now()),
[email protected]67372ecf2011-09-10 01:30:46382 delegate_(delegate),
[email protected]3c7c1442012-08-08 12:21:45383 predictor_(NULL) {
rkaplow058da3132015-02-19 18:18:38384 TRACE_EVENT0("browser,startup", "ProfileImpl::ctor")
[email protected]5a0b42e2010-07-30 23:42:59385 DCHECK(!path.empty()) << "Using an empty path will attempt to write " <<
386 "profile files to the root directory!";
[email protected]0e3a385d2011-05-26 23:38:18387
[email protected]cdb756ef2012-04-05 18:34:53388#if defined(ENABLE_SESSION_SERVICE)
[email protected]d323a172011-09-02 18:23:02389 create_session_service_timer_.Start(FROM_HERE,
[email protected]5a0b42e2010-07-30 23:42:59390 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this,
391 &ProfileImpl::EnsureSessionServiceCreated);
[email protected]cdb756ef2012-04-05 18:34:53392#endif
[email protected]5a0b42e2010-07-30 23:42:59393
mlerman1f090b422015-01-15 16:26:18394 set_is_guest_profile(path == ProfileManager::GetGuestProfilePath());
mlermanb8df6e82015-01-23 19:55:34395 set_is_system_profile(path == ProfileManager::GetSystemProfilePath());
mlerman1f090b422015-01-15 16:26:18396
[email protected]67372ecf2011-09-10 01:30:46397 // Determine if prefetch is enabled for this profile.
398 // If not profile_manager is present, it means we are in a unittest.
avi556c05022014-12-22 23:31:43399 const base::CommandLine* command_line =
400 base::CommandLine::ForCurrentProcess();
[email protected]67372ecf2011-09-10 01:30:46401 predictor_ = chrome_browser_net::Predictor::CreatePredictor(
402 !command_line->HasSwitch(switches::kDisablePreconnect),
[email protected]8a9712c22014-07-21 22:47:28403 !command_line->HasSwitch(switches::kDnsPrefetchDisable),
[email protected]67372ecf2011-09-10 01:30:46404 g_browser_process->profile_manager() == NULL);
405
[email protected]d61ee872012-11-19 17:08:38406 // If we are creating the profile synchronously, then we should load the
407 // policy data immediately.
408 bool force_immediate_policy_load = (create_mode == CREATE_MODE_SYNCHRONOUS);
[email protected]d81bb3e2013-05-02 18:17:03409#if defined(ENABLE_CONFIGURATION_POLICY)
[email protected]eb83c392013-11-07 12:53:24410 policy::BrowserPolicyConnector* connector =
411 g_browser_process->browser_policy_connector();
412 schema_registry_service_ =
413 policy::SchemaRegistryServiceFactory::CreateForContext(
414 this, connector->GetChromeSchema(), connector->GetSchemaRegistry());
[email protected]42c0d5ed2013-04-30 17:04:45415#if defined(OS_CHROMEOS)
416 cloud_policy_manager_ =
417 policy::UserCloudPolicyManagerFactoryChromeOS::CreateForProfile(
[email protected]6a6dd9d2013-10-19 18:16:59418 this, force_immediate_policy_load, sequenced_task_runner);
[email protected]42c0d5ed2013-04-30 17:04:45419#else
420 cloud_policy_manager_ =
[email protected]499cb702013-11-06 14:03:05421 policy::UserCloudPolicyManagerFactory::CreateForOriginalBrowserContext(
[email protected]526cf1a42013-11-26 10:38:48422 this,
423 force_immediate_policy_load,
424 sequenced_task_runner,
425 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE),
426 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
[email protected]3c843b42012-12-03 16:00:16427#endif
[email protected]e4ee8692013-03-25 19:05:35428#endif
[email protected]d81bb3e2013-05-02 18:17:03429 profile_policy_connector_ =
pneubeck91534e82015-02-18 17:37:52430 policy::ProfilePolicyConnectorFactory::CreateForBrowserContext(
[email protected]6a6dd9d2013-10-19 18:16:59431 this, force_immediate_policy_load);
[email protected]3b19e8e2012-10-17 19:15:49432
[email protected]70a317a2012-12-19 20:59:33433 DCHECK(create_mode == CREATE_MODE_ASYNCHRONOUS ||
434 create_mode == CREATE_MODE_SYNCHRONOUS);
435 bool async_prefs = create_mode == CREATE_MODE_ASYNCHRONOUS;
[email protected]0dbd75d2013-01-18 00:31:07436
[email protected]37ca3fe02013-07-05 15:32:44437#if defined(OS_CHROMEOS)
[email protected]16918222013-11-06 13:24:51438 if (chromeos::ProfileHelper::IsSigninProfile(this))
[email protected]37ca3fe02013-07-05 15:32:44439 chrome::RegisterLoginProfilePrefs(pref_registry_.get());
440 else
441#endif
[email protected]e1480482013-09-11 11:49:58442 chrome::RegisterUserProfilePrefs(pref_registry_.get());
443
[email protected]d45c5d52013-12-04 23:41:16444 BrowserContextDependencyManager::GetInstance()->
445 RegisterProfilePrefsForServices(this, pref_registry_.get());
446
knn95221ffe2015-03-04 20:42:43447 SupervisedUserSettingsService* supervised_user_settings = nullptr;
treib87bb89cbb2014-12-01 16:01:47448#if defined(ENABLE_SUPERVISED_USERS)
[email protected]cce15bb2014-06-17 13:43:51449 supervised_user_settings =
450 SupervisedUserSettingsServiceFactory::GetForProfile(this);
451 supervised_user_settings->Init(
[email protected]e1480482013-09-11 11:49:58452 path_, sequenced_task_runner, create_mode == CREATE_MODE_SYNCHRONOUS);
453#endif
[email protected]5879cef2013-03-02 17:02:25454
[email protected]0823c68d2014-06-13 22:23:47455 scoped_refptr<SafeBrowsingService> safe_browsing_service(
456 g_browser_process->safe_browsing_service());
dchengf3cfb1d2014-08-26 20:25:59457 if (safe_browsing_service.get()) {
[email protected]0823c68d2014-06-13 22:23:47458 pref_validation_delegate_ =
[email protected]91081cf2014-06-19 13:56:20459 safe_browsing_service->CreatePreferenceValidationDelegate(this).Pass();
[email protected]0823c68d2014-06-13 22:23:47460 }
461
[email protected]0dbd75d2013-01-18 00:31:07462 {
[email protected]e90a01f2013-11-19 04:22:12463 prefs_ = chrome_prefs::CreateProfilePrefs(
[email protected]d9413a3e2014-02-05 21:47:56464 path_,
[email protected]0dbd75d2013-01-18 00:31:07465 sequenced_task_runner,
[email protected]086dfcb2014-05-26 23:43:03466 pref_validation_delegate_.get(),
[email protected]d81bb3e2013-05-02 18:17:03467 profile_policy_connector_->policy_service(),
[email protected]cce15bb2014-06-17 13:43:51468 supervised_user_settings,
[email protected]dfc0424c2014-07-25 21:33:20469 CreateExtensionPrefStore(this, false),
[email protected]c753f142013-02-10 13:14:04470 pref_registry_,
[email protected]e90a01f2013-11-19 04:22:12471 async_prefs).Pass();
[email protected]75fee372013-03-06 00:42:44472 // Register on BrowserContext.
[email protected]c7141feb2013-06-11 13:00:16473 user_prefs::UserPrefs::Set(this, prefs_.get());
[email protected]0dbd75d2013-01-18 00:31:07474 }
475
[email protected]70a317a2012-12-19 20:59:33476 if (async_prefs) {
[email protected]a6a7ced2012-11-01 17:24:18477 // Wait for the notification that prefs has been loaded
478 // (successfully or not). Note that we can use base::Unretained
479 // because the PrefService is owned by this class and lives on
480 // the same thread.
alematef06730292015-05-12 21:36:07481 prefs_->AddPrefInitObserver(base::Bind(
482 &ProfileImpl::OnPrefsLoaded, base::Unretained(this), create_mode));
[email protected]00b33f802012-03-13 07:46:03483 } else {
[email protected]70a317a2012-12-19 20:59:33484 // Prefs were loaded synchronously so we can continue directly.
alematef06730292015-05-12 21:36:07485 OnPrefsLoaded(create_mode, true);
[email protected]844a1002011-04-19 11:37:21486 }
487}
488
[email protected]88c6fb52013-04-09 10:39:18489void ProfileImpl::DoFinalInit() {
[email protected]acd431e2013-05-31 13:34:49490 TRACE_EVENT0("browser", "ProfileImpl::DoFinalInit")
rkaplow3e2016b2015-04-02 17:04:00491 SCOPED_UMA_HISTOGRAM_TIMER("Profile.ProfileImplDoFinalInit");
492
[email protected]5a0b42e2010-07-30 23:42:59493 PrefService* prefs = GetPrefs();
[email protected]2fb7dc982010-09-29 12:24:28494 pref_change_registrar_.Init(prefs);
[email protected]116129e02012-11-21 17:26:27495 pref_change_registrar_.Add(
[email protected]d20d0432014-06-12 17:14:05496 prefs::kSupervisedUserId,
497 base::Bind(&ProfileImpl::UpdateProfileSupervisedUserIdCache,
[email protected]6ebd60c2014-04-28 23:45:20498 base::Unretained(this)));
[email protected]1cdf0932014-08-16 06:00:49499
500 // Changes in the profile avatar.
[email protected]116129e02012-11-21 17:26:27501 pref_change_registrar_.Add(
502 prefs::kProfileAvatarIndex,
503 base::Bind(&ProfileImpl::UpdateProfileAvatarCache,
504 base::Unretained(this)));
505 pref_change_registrar_.Add(
[email protected]1cdf0932014-08-16 06:00:49506 prefs::kProfileUsingDefaultAvatar,
507 base::Bind(&ProfileImpl::UpdateProfileAvatarCache,
508 base::Unretained(this)));
509 pref_change_registrar_.Add(
510 prefs::kProfileUsingGAIAAvatar,
511 base::Bind(&ProfileImpl::UpdateProfileAvatarCache,
512 base::Unretained(this)));
513
514 // Changes in the profile name.
515 pref_change_registrar_.Add(
516 prefs::kProfileUsingDefaultName,
517 base::Bind(&ProfileImpl::UpdateProfileNameCache,
518 base::Unretained(this)));
519 pref_change_registrar_.Add(
[email protected]116129e02012-11-21 17:26:27520 prefs::kProfileName,
521 base::Bind(&ProfileImpl::UpdateProfileNameCache,
522 base::Unretained(this)));
[email protected]1cdf0932014-08-16 06:00:49523
[email protected]8d9243a2013-10-21 17:11:48524 pref_change_registrar_.Add(
525 prefs::kForceEphemeralProfiles,
526 base::Bind(&ProfileImpl::UpdateProfileIsEphemeralCache,
527 base::Unretained(this)));
[email protected]5a0b42e2010-07-30 23:42:59528
[email protected]b411da32010-11-24 02:23:15529 // It would be nice to use PathService for fetching this directory, but
530 // the cache directory depends on the profile directory, which isn't available
531 // to PathService.
532 chrome::GetUserCacheDirectory(path_, &base_cache_path_);
[email protected]00b33f802012-03-13 07:46:03533 // Always create the cache directory asynchronously.
[email protected]0de615a2012-11-08 04:40:59534 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner =
535 JsonPrefStore::GetTaskRunnerForFile(base_cache_path_,
536 BrowserThread::GetBlockingPool());
calamityf4f08cfe2015-06-17 02:39:02537 CreateProfileDirectory(sequenced_task_runner.get(), base_cache_path_, false);
[email protected]5a0b42e2010-07-30 23:42:59538
rogerta614597db2014-12-05 17:57:32539 // Initialize components that depend on the current value.
[email protected]d20d0432014-06-12 17:14:05540 UpdateProfileSupervisedUserIdCache();
[email protected]a02c4ef2013-11-06 20:30:11541 UpdateProfileIsEphemeralCache();
[email protected]933b3f62013-01-03 20:44:21542 GAIAInfoUpdateServiceFactory::GetForProfile(this);
[email protected]c337d1b72012-01-13 04:40:24543
[email protected]81ad7f4a2011-03-16 01:33:29544 PrefService* local_state = g_browser_process->local_state();
[email protected]182fe2f2011-02-14 20:35:15545 ssl_config_service_manager_.reset(
[email protected]e6d017652013-05-17 18:01:40546 SSLConfigServiceManager::CreateDefaultManager(local_state));
[email protected]182fe2f2011-02-14 20:35:15547
thestige4155842014-10-20 18:58:02548#if defined(ENABLE_BACKGROUND)
[email protected]4c793f02010-08-18 20:55:45549 // Initialize the BackgroundModeManager - this has to be done here before
550 // InitExtensions() is called because it relies on receiving notifications
551 // when extensions are loaded. BackgroundModeManager is not needed under
[email protected]120655d2011-09-16 22:10:32552 // ChromeOS because Chrome is always running, no need for special keep-alive
553 // or launch-on-startup support unless kKeepAliveForTest is set.
554 bool init_background_mode_manager = true;
555#if defined(OS_CHROMEOS)
avi556c05022014-12-22 23:31:43556 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
557 switches::kKeepAliveForTest))
[email protected]120655d2011-09-16 22:10:32558 init_background_mode_manager = false;
[email protected]4c793f02010-08-18 20:55:45559#endif
[email protected]120655d2011-09-16 22:10:32560 if (init_background_mode_manager) {
561 if (g_browser_process->background_mode_manager())
562 g_browser_process->background_mode_manager()->RegisterProfile(this);
563 }
thestige4155842014-10-20 18:58:02564#endif // defined(ENABLE_BACKGROUND)
[email protected]4c793f02010-08-18 20:55:45565
[email protected]33ad6ce92013-08-27 14:39:08566 base::FilePath cookie_path = GetPath();
567 cookie_path = cookie_path.Append(chrome::kCookieFilename);
[email protected]6b8a3c742014-07-25 00:25:35568 base::FilePath channel_id_path = GetPath();
569 channel_id_path = channel_id_path.Append(chrome::kChannelIDFilename);
[email protected]650b2d52013-02-10 03:41:45570 base::FilePath cache_path = base_cache_path_;
[email protected]f6c21cb2011-02-16 19:45:41571 int cache_max_size;
[email protected]f2df3112011-11-18 10:21:48572 GetCacheParameters(false, &cache_path, &cache_max_size);
[email protected]f6c21cb2011-02-16 19:45:41573 cache_path = GetCachePath(cache_path);
574
[email protected]650b2d52013-02-10 03:41:45575 base::FilePath media_cache_path = base_cache_path_;
[email protected]f6c21cb2011-02-16 19:45:41576 int media_cache_max_size;
[email protected]f2df3112011-11-18 10:21:48577 GetCacheParameters(true, &media_cache_path, &media_cache_max_size);
[email protected]f6c21cb2011-02-16 19:45:41578 media_cache_path = GetMediaCachePath(media_cache_path);
579
[email protected]650b2d52013-02-10 03:41:45580 base::FilePath extensions_cookie_path = GetPath();
[email protected]f6c21cb2011-02-16 19:45:41581 extensions_cookie_path =
582 extensions_cookie_path.Append(chrome::kExtensionsCookieFilename);
583
[email protected]33ad6ce92013-08-27 14:39:08584#if defined(OS_ANDROID)
585 SessionStartupPref::Type startup_pref_type =
586 SessionStartupPref::GetDefaultStartupType();
587#else
588 SessionStartupPref::Type startup_pref_type =
589 StartupBrowserCreator::GetSessionStartupPref(
avi556c05022014-12-22 23:31:43590 *base::CommandLine::ForCurrentProcess(), this).type;
[email protected]33ad6ce92013-08-27 14:39:08591#endif
[email protected]9a6c2aa2014-01-11 22:39:39592 content::CookieStoreConfig::SessionCookieMode session_cookie_mode =
593 content::CookieStoreConfig::PERSISTANT_SESSION_COOKIES;
594 if (GetLastSessionExitType() == Profile::EXIT_CRASHED ||
595 startup_pref_type == SessionStartupPref::LAST) {
596 session_cookie_mode = content::CookieStoreConfig::RESTORED_SESSION_COOKIES;
597 }
[email protected]33ad6ce92013-08-27 14:39:08598
[email protected]f6c21cb2011-02-16 19:45:41599 // Make sure we initialize the ProfileIOData after everything else has been
600 // initialized that we might be reading from the IO thread.
[email protected]67372ecf2011-09-10 01:30:46601
[email protected]6b8a3c742014-07-25 00:25:35602 io_data_.Init(cookie_path, channel_id_path, cache_path,
[email protected]273e37d2011-08-11 01:49:12603 cache_max_size, media_cache_path, media_cache_max_size,
isherman292673a2015-03-31 22:04:29604 extensions_cookie_path, GetPath(), predictor_,
605 session_cookie_mode, GetSpecialStoragePolicy(),
bengr9463b5772015-01-24 00:24:54606 CreateDomainReliabilityMonitor(local_state));
[email protected]f6c21cb2011-02-16 19:45:41607
[email protected]ebd71962012-12-20 02:56:55608#if defined(ENABLE_PLUGINS)
[email protected]dfba8762011-09-02 12:49:54609 ChromePluginServiceFilter::GetInstance()->RegisterResourceContext(
[email protected]cadac622013-06-11 16:46:36610 PluginPrefs::GetForProfile(this).get(),
[email protected]df02aca2012-02-09 21:03:20611 io_data_.GetResourceContextNoInit());
[email protected]ebd71962012-12-20 02:56:55612#endif
[email protected]dfba8762011-09-02 12:49:54613
[email protected]12360b52014-03-07 19:31:52614 TRACE_EVENT0("browser", "ProfileImpl::SetSaveSessionStorageOnDisk");
615 content::BrowserContext::GetDefaultStoragePartition(this)->
616 GetDOMStorageContext()->SetSaveSessionStorageOnDisk();
[email protected]039124e2012-08-17 00:22:26617
wjmacleancaa7d6d2014-11-12 16:42:11618 // TODO(wjmaclean): Remove this. crbug.com/420643
619 chrome::MigrateProfileZoomLevelPrefs(this);
620
[email protected]7e856dde2014-03-15 00:34:05621 // The DomDistillerViewerSource is not a normal WebUI so it must be registered
622 // as a URLDataSource early.
623 RegisterDomDistillerViewerSource(this);
624
[email protected]afe10992014-06-26 17:48:07625#if defined(OS_CHROMEOS)
nkostylev4d2391a2014-11-14 16:15:04626 if (chromeos::UserSessionManager::GetInstance()
627 ->RestartToApplyPerSessionFlagsIfNeed(this, true)) {
[email protected]afe10992014-06-26 17:48:07628 return;
629 }
630#endif
631
[email protected]acd431e2013-05-31 13:34:49632 if (delegate_) {
633 TRACE_EVENT0("browser", "ProfileImpl::DoFileInit:DelegateOnProfileCreated")
[email protected]88c6fb52013-04-09 10:39:18634 delegate_->OnProfileCreated(this, true, IsNewProfile());
[email protected]acd431e2013-05-31 13:34:49635 }
[email protected]12463cd2011-07-19 09:40:20636
rkaplow3e2016b2015-04-02 17:04:00637 {
638 SCOPED_UMA_HISTOGRAM_TIMER("Profile.NotifyProfileCreatedTime");
639 content::NotificationService::current()->Notify(
640 chrome::NOTIFICATION_PROFILE_CREATED,
641 content::Source<Profile>(this),
642 content::NotificationService::NoDetails());
643 }
[email protected]68b93512013-02-08 18:17:57644#if !defined(OS_CHROMEOS)
645 // Listen for bookmark model load, to bootstrap the sync service.
646 // On CrOS sync service will be initialized after sign in.
[email protected]2f8f25d2013-07-26 10:30:00647 BookmarkModel* model = BookmarkModelFactory::GetForProfile(this);
648 model->AddObserver(new BookmarkModelLoadedObserver(this));
[email protected]68b93512013-02-08 18:17:57649#endif
[email protected]b7176262014-06-18 15:26:29650
b.kelemen4596b512015-03-04 18:42:47651 PushMessagingServiceImpl::InitializeForProfile(this);
[email protected]9086ce5a2014-08-14 15:15:04652
653#if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) && !defined(OS_IOS)
654 signin_ui_util::InitializePrefsForProfile(this);
655#endif
[email protected]5a0b42e2010-07-30 23:42:59656}
657
[email protected]650b2d52013-02-10 03:41:45658base::FilePath ProfileImpl::last_selected_directory() {
[email protected]5a0b42e2010-07-30 23:42:59659 return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory);
660}
661
[email protected]650b2d52013-02-10 03:41:45662void ProfileImpl::set_last_selected_directory(const base::FilePath& path) {
[email protected]5a0b42e2010-07-30 23:42:59663 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path);
664}
665
666ProfileImpl::~ProfileImpl() {
[email protected]a7c4c032012-07-27 00:36:32667 MaybeSendDestroyedNotification();
668
[email protected]38b99942012-04-20 10:44:27669 bool prefs_loaded = prefs_->GetInitializationStatus() !=
670 PrefService::INITIALIZATION_STATUS_WAITING;
[email protected]00617712011-07-22 10:21:06671
[email protected]cdb756ef2012-04-05 18:34:53672#if defined(ENABLE_SESSION_SERVICE)
[email protected]92371eb2011-04-28 11:50:15673 StopCreateSessionServiceTimer();
[email protected]cdb756ef2012-04-05 18:34:53674#endif
[email protected]92371eb2011-04-28 11:50:15675
[email protected]60100b22011-06-29 23:37:25676 // Remove pref observers
677 pref_change_registrar_.RemoveAll();
678
[email protected]ebd71962012-12-20 02:56:55679#if defined(ENABLE_PLUGINS)
[email protected]dfba8762011-09-02 12:49:54680 ChromePluginServiceFilter::GetInstance()->UnregisterResourceContext(
[email protected]df02aca2012-02-09 21:03:20681 io_data_.GetResourceContextNoInit());
[email protected]ebd71962012-12-20 02:56:55682#endif
[email protected]dfba8762011-09-02 12:49:54683
[email protected]d3a9bfc2012-02-07 22:52:47684 // Destroy OTR profile and its profile services first.
[email protected]9332a3f72013-05-07 06:33:52685 if (off_the_record_profile_) {
[email protected]10ce4cf2012-06-26 20:09:16686 ProfileDestroyer::DestroyOffTheRecordProfileNow(
687 off_the_record_profile_.get());
688 } else {
[email protected]dfc0424c2014-07-25 21:33:20689#if defined(ENABLE_EXTENSIONS)
[email protected]7595f1c82013-10-23 14:09:56690 ExtensionPrefValueMapFactory::GetForBrowserContext(this)->
[email protected]10ce4cf2012-06-26 20:09:16691 ClearAllIncognitoSessionOnlyPreferences();
[email protected]dfc0424c2014-07-25 21:33:20692#endif
[email protected]10ce4cf2012-06-26 20:09:16693 }
[email protected]d3a9bfc2012-02-07 22:52:47694
[email protected]f1484c52013-05-22 23:25:44695 BrowserContextDependencyManager::GetInstance()->DestroyBrowserContextServices(
696 this);
[email protected]5cdcd152011-03-31 22:48:52697
[email protected]9332a3f72013-05-07 06:33:52698 if (pref_proxy_config_tracker_)
[email protected]cc5bfd42010-11-24 14:44:02699 pref_proxy_config_tracker_->DetachFromPrefService();
700
[email protected]5173de8b2013-06-02 21:16:02701 if (host_content_settings_map_.get())
[email protected]24ff5ca2011-07-06 14:21:44702 host_content_settings_map_->ShutdownOnUIThread();
703
[email protected]5a0b42e2010-07-30 23:42:59704 // This causes the Preferences file to be written to disk.
[email protected]38b99942012-04-20 10:44:27705 if (prefs_loaded)
[email protected]6c0ca7fc2012-10-05 16:27:22706 SetExitType(EXIT_NORMAL);
[email protected]5a0b42e2010-07-30 23:42:59707}
708
isherman91ffd8b2015-02-19 08:51:32709std::string ProfileImpl::GetProfileUserName() const {
710 const SigninManagerBase* signin_manager =
711 SigninManagerFactory::GetForProfileIfExists(this);
rogerta614597db2014-12-05 17:57:32712 if (signin_manager)
713 return signin_manager->GetAuthenticatedUsername();
714
715 return std::string();
[email protected]29d70252011-04-28 02:16:58716}
717
[email protected]7b7e0b32014-03-17 16:09:23718Profile::ProfileType ProfileImpl::GetProfileType() const {
719 return REGULAR_PROFILE;
720}
721
wjmacleancaa7d6d2014-11-12 16:42:11722scoped_ptr<content::ZoomLevelDelegate>
723ProfileImpl::CreateZoomLevelDelegate(const base::FilePath& partition_path) {
wjmaclean2c98cb192014-11-26 19:55:27724 return make_scoped_ptr(new chrome::ChromeZoomLevelPrefs(
725 GetPrefs(), GetPath(), partition_path,
wjmaclean7f63c6b2014-12-09 14:59:55726 ui_zoom::ZoomEventManager::GetForBrowserContext(this)->GetWeakPtr()));
wjmacleancaa7d6d2014-11-12 16:42:11727}
728
[email protected]4251165a2013-07-17 04:33:40729base::FilePath ProfileImpl::GetPath() const {
[email protected]5a0b42e2010-07-30 23:42:59730 return path_;
731}
732
[email protected]0de615a2012-11-08 04:40:59733scoped_refptr<base::SequencedTaskRunner> ProfileImpl::GetIOTaskRunner() {
734 return JsonPrefStore::GetTaskRunnerForFile(
735 GetPath(), BrowserThread::GetBlockingPool());
736}
737
[email protected]33ad6ce92013-08-27 14:39:08738bool ProfileImpl::IsOffTheRecord() const {
739 return false;
[email protected]5a0b42e2010-07-30 23:42:59740}
741
742Profile* ProfileImpl::GetOffTheRecordProfile() {
[email protected]9332a3f72013-05-07 06:33:52743 if (!off_the_record_profile_) {
[email protected]5a0b42e2010-07-30 23:42:59744 scoped_ptr<Profile> p(CreateOffTheRecordProfile());
745 off_the_record_profile_.swap(p);
[email protected]06e29a92010-10-13 22:43:26746
[email protected]ad50def52011-10-19 23:17:07747 content::NotificationService::current()->Notify(
[email protected]12463cd2011-07-19 09:40:20748 chrome::NOTIFICATION_PROFILE_CREATED,
[email protected]6c2381d2011-10-19 02:52:53749 content::Source<Profile>(off_the_record_profile_.get()),
[email protected]ad50def52011-10-19 23:17:07750 content::NotificationService::NoDetails());
[email protected]5a0b42e2010-07-30 23:42:59751 }
752 return off_the_record_profile_.get();
753}
754
755void ProfileImpl::DestroyOffTheRecordProfile() {
756 off_the_record_profile_.reset();
[email protected]dfc0424c2014-07-25 21:33:20757#if defined(ENABLE_EXTENSIONS)
[email protected]7595f1c82013-10-23 14:09:56758 ExtensionPrefValueMapFactory::GetForBrowserContext(this)->
[email protected]ef9bba12012-04-06 16:26:09759 ClearAllIncognitoSessionOnlyPreferences();
[email protected]dfc0424c2014-07-25 21:33:20760#endif
[email protected]5a0b42e2010-07-30 23:42:59761}
762
763bool ProfileImpl::HasOffTheRecordProfile() {
764 return off_the_record_profile_.get() != NULL;
765}
766
767Profile* ProfileImpl::GetOriginalProfile() {
768 return this;
769}
770
treib2f1cbb42015-08-06 12:33:10771bool ProfileImpl::IsSupervised() const {
[email protected]d20d0432014-06-12 17:14:05772 return !GetPrefs()->GetString(prefs::kSupervisedUserId).empty();
[email protected]e000daf2013-07-31 16:50:58773}
774
treib2f1cbb42015-08-06 12:33:10775bool ProfileImpl::IsChild() const {
treib3c8cf132014-12-08 15:09:32776#if defined(ENABLE_SUPERVISED_USERS)
777 return GetPrefs()->GetString(prefs::kSupervisedUserId) ==
778 supervised_users::kChildAccountSUID;
merkulovae19a3522014-12-04 11:14:06779#else
780 return false;
781#endif
782}
783
treib2f1cbb42015-08-06 12:33:10784bool ProfileImpl::IsLegacySupervised() const {
treib3c8cf132014-12-08 15:09:32785 return IsSupervised() && !IsChild();
786}
787
[email protected]19eb80152011-02-26 00:28:43788ExtensionSpecialStoragePolicy*
789 ProfileImpl::GetExtensionSpecialStoragePolicy() {
[email protected]dfc0424c2014-07-25 21:33:20790#if defined(ENABLE_EXTENSIONS)
[email protected]5173de8b2013-06-02 21:16:02791 if (!extension_special_storage_policy_.get()) {
[email protected]acd431e2013-05-31 13:34:49792 TRACE_EVENT0("browser", "ProfileImpl::GetExtensionSpecialStoragePolicy")
[email protected]67e79992012-02-13 20:47:58793 extension_special_storage_policy_ = new ExtensionSpecialStoragePolicy(
drogerb1716972015-06-30 09:04:09794 CookieSettingsFactory::GetForProfile(this).get());
[email protected]7c5048c2011-08-19 17:07:05795 }
[email protected]19eb80152011-02-26 00:28:43796 return extension_special_storage_policy_.get();
[email protected]dfc0424c2014-07-25 21:33:20797#else
798 return NULL;
799#endif
[email protected]19eb80152011-02-26 00:28:43800}
801
alematef06730292015-05-12 21:36:07802void ProfileImpl::OnLocaleReady() {
803 TRACE_EVENT0("browser", "ProfileImpl::OnLocaleReady");
804 SCOPED_UMA_HISTOGRAM_TIMER("Profile.OnLocaleReadyTime");
rkaplowf216caf2015-03-02 22:37:45805 // Migrate obsolete prefs.
[email protected]665fa012012-05-09 00:24:38806 if (g_browser_process->local_state())
rkaplowf216caf2015-03-02 22:37:45807 chrome::MigrateObsoleteBrowserPrefs(this, g_browser_process->local_state());
808 chrome::MigrateObsoleteProfilePrefs(this);
[email protected]844a1002011-04-19 11:37:21809
[email protected]6c0ca7fc2012-10-05 16:27:22810 // |kSessionExitType| was added after |kSessionExitedCleanly|. If the pref
811 // value is empty fallback to checking for |kSessionExitedCleanly|.
812 const std::string exit_type_pref_value(
813 prefs_->GetString(prefs::kSessionExitType));
814 if (exit_type_pref_value.empty()) {
815 last_session_exit_type_ =
816 prefs_->GetBoolean(prefs::kSessionExitedCleanly) ?
817 EXIT_NORMAL : EXIT_CRASHED;
818 } else {
819 last_session_exit_type_ =
820 SessionTypePrefValueToExitType(exit_type_pref_value);
821 }
[email protected]844a1002011-04-19 11:37:21822 // Mark the session as open.
[email protected]6c0ca7fc2012-10-05 16:27:22823 prefs_->SetString(prefs::kSessionExitType, kPrefExitTypeCrashed);
824 // Force this to true in case we fallback and use it.
825 // TODO(sky): remove this in a couple of releases (m28ish).
826 prefs_->SetBoolean(prefs::kSessionExitedCleanly, true);
[email protected]844a1002011-04-19 11:37:21827
nparkerb2cd5ee2015-05-13 01:12:01828#if defined(SAFE_BROWSING_DB_REMOTE)
829 // Hardcode this pref on this build of Android until the UX is developed.
830 // http://crbug.com/481558
831 prefs_->SetBoolean(prefs::kSafeBrowsingEnabled, true);
[email protected]16a67182014-06-16 16:13:25832#endif
833
[email protected]371662e372013-10-17 22:05:22834 g_browser_process->profile_manager()->InitProfileUserPrefs(this);
835
rkaplow3e2016b2015-04-02 17:04:00836 {
837 SCOPED_UMA_HISTOGRAM_TIMER("Profile.CreateBrowserContextServicesTime");
838 BrowserContextDependencyManager::GetInstance()->
839 CreateBrowserContextServices(this);
840 }
[email protected]6802a825f2012-01-21 01:29:33841
[email protected]9332a3f72013-05-07 06:33:52842 DCHECK(!net_pref_observer_);
[email protected]acd431e2013-05-31 13:34:49843 {
844 TRACE_EVENT0("browser", "ProfileImpl::OnPrefsLoaded:NetPrefObserver")
bnc2551612c2014-09-04 00:48:32845 net_pref_observer_.reset(new NetPrefObserver(prefs_.get()));
[email protected]acd431e2013-05-31 13:34:49846 }
[email protected]844a1002011-04-19 11:37:21847
[email protected]d9413a3e2014-02-05 21:47:56848 chrome_prefs::SchedulePrefsFilePathVerification(path_);
[email protected]d8838c02013-09-20 17:14:20849
[email protected]88c6fb52013-04-09 10:39:18850 ChromeVersionService::OnProfileLoaded(prefs_.get(), IsNewProfile());
851 DoFinalInit();
[email protected]844a1002011-04-19 11:37:21852}
853
alematef06730292015-05-12 21:36:07854void ProfileImpl::OnPrefsLoaded(CreateMode create_mode, bool success) {
855 TRACE_EVENT0("browser", "ProfileImpl::OnPrefsLoaded");
856 if (!success) {
857 if (delegate_)
858 delegate_->OnProfileCreated(this, false, false);
859 return;
860 }
861
862#if defined(OS_CHROMEOS)
863 if (create_mode == CREATE_MODE_SYNCHRONOUS) {
864 // Synchronous create mode implies that either it is restart after crash,
865 // or we are in tests. In both cases the first loaded locale is correct.
866 OnLocaleReady();
867 } else {
868 chromeos::UserSessionManager::GetInstance()->RespectLocalePreferenceWrapper(
869 this, base::Bind(&ProfileImpl::OnLocaleReady, base::Unretained(this)));
870 }
871#else
872 OnLocaleReady();
873#endif
874}
875
[email protected]1bee6ed2012-03-14 06:46:36876bool ProfileImpl::WasCreatedByVersionOrLater(const std::string& version) {
[email protected]c5e4a2222014-01-03 16:06:13877 Version profile_version(ChromeVersionService::GetVersion(prefs_.get()));
878 Version arg_version(version);
[email protected]1bee6ed2012-03-14 06:46:36879 return (profile_version.CompareTo(arg_version) >= 0);
880}
881
[email protected]6c0ca7fc2012-10-05 16:27:22882void ProfileImpl::SetExitType(ExitType exit_type) {
[email protected]1101dbc52013-10-05 00:19:12883#if defined(OS_CHROMEOS)
[email protected]16918222013-11-06 13:24:51884 if (chromeos::ProfileHelper::IsSigninProfile(this))
[email protected]1101dbc52013-10-05 00:19:12885 return;
886#endif
[email protected]df70a5282012-10-26 19:29:33887 if (!prefs_)
888 return;
889 ExitType current_exit_type = SessionTypePrefValueToExitType(
890 prefs_->GetString(prefs::kSessionExitType));
891 // This may be invoked multiple times during shutdown. Only persist the value
892 // first passed in (unless it's a reset to the crash state, which happens when
893 // foregrounding the app on mobile).
894 if (exit_type == EXIT_CRASHED || current_exit_type == EXIT_CRASHED) {
[email protected]6c0ca7fc2012-10-05 16:27:22895 prefs_->SetString(prefs::kSessionExitType,
896 ExitTypeToSessionTypePrefValue(exit_type));
[email protected]6c0ca7fc2012-10-05 16:27:22897 }
898}
899
900Profile::ExitType ProfileImpl::GetLastSessionExitType() {
[email protected]2ca1ea662012-10-04 02:26:36901 // last_session_exited_cleanly_ is set when the preferences are loaded. Force
902 // it to be set by asking for the prefs.
903 GetPrefs();
[email protected]6c0ca7fc2012-10-05 16:27:22904 return last_session_exit_type_;
[email protected]2ca1ea662012-10-04 02:26:36905}
906
[email protected]c753f142013-02-10 13:14:04907PrefService* ProfileImpl::GetPrefs() {
isherman91ffd8b2015-02-19 08:51:32908 return const_cast<PrefService*>(
909 static_cast<const ProfileImpl*>(this)->GetPrefs());
910}
911
912const PrefService* ProfileImpl::GetPrefs() const {
[email protected]9332a3f72013-05-07 06:33:52913 DCHECK(prefs_); // Should explicitly be initialized.
[email protected]5a0b42e2010-07-30 23:42:59914 return prefs_.get();
915}
916
wjmacleane530aa742014-10-14 21:43:30917chrome::ChromeZoomLevelPrefs* ProfileImpl::GetZoomLevelPrefs() {
wjmacleancaa7d6d2014-11-12 16:42:11918 return static_cast<chrome::ChromeZoomLevelPrefs*>(
919 GetDefaultStoragePartition(this)->GetZoomLevelDelegate());
wjmacleane530aa742014-10-14 21:43:30920}
921
[email protected]c753f142013-02-10 13:14:04922PrefService* ProfileImpl::GetOffTheRecordPrefs() {
[email protected]9332a3f72013-05-07 06:33:52923 DCHECK(prefs_);
924 if (!otr_prefs_) {
[email protected]ca759982011-02-04 15:17:40925 // The new ExtensionPrefStore is ref_counted and the new PrefService
926 // stores a reference so that we do not leak memory here.
[email protected]c753f142013-02-10 13:14:04927 otr_prefs_.reset(prefs_->CreateIncognitoPrefService(
[email protected]dfc0424c2014-07-25 21:33:20928 CreateExtensionPrefStore(this, true)));
[email protected]ca759982011-02-04 15:17:40929 }
930 return otr_prefs_.get();
931}
932
[email protected]6bd30072013-02-08 18:17:11933net::URLRequestContextGetter* ProfileImpl::CreateRequestContext(
[email protected]7571263c2014-03-10 22:57:09934 content::ProtocolHandlerMap* protocol_handlers,
[email protected]3b90aab2014-05-30 17:56:15935 content::URLRequestInterceptorScopedVector request_interceptors) {
[email protected]7571263c2014-03-10 22:57:09936 return io_data_.CreateMainRequestContextGetter(
937 protocol_handlers,
[email protected]3b90aab2014-05-30 17:56:15938 request_interceptors.Pass(),
[email protected]7571263c2014-03-10 22:57:09939 g_browser_process->local_state(),
940 g_browser_process->io_thread()).get();
[email protected]6bd30072013-02-08 18:17:11941}
942
[email protected]abe2c032011-03-31 18:49:34943net::URLRequestContextGetter* ProfileImpl::GetRequestContext() {
[email protected]6bd30072013-02-08 18:17:11944 return GetDefaultStoragePartition(this)->GetURLRequestContext();
[email protected]5a0b42e2010-07-30 23:42:59945}
946
[email protected]da5683db2011-04-23 17:12:21947net::URLRequestContextGetter* ProfileImpl::GetRequestContextForRenderProcess(
948 int renderer_child_id) {
[email protected]fb29e6cf2012-07-12 21:27:20949 content::RenderProcessHost* rph = content::RenderProcessHost::FromID(
950 renderer_child_id);
[email protected]27ddfed22012-10-30 23:22:43951
[email protected]1bc28312012-11-08 08:31:53952 return rph->GetStoragePartition()->GetURLRequestContext();
[email protected]d9696672011-03-15 22:45:09953}
954
[email protected]10705a7b2012-08-21 19:07:08955net::URLRequestContextGetter* ProfileImpl::GetMediaRequestContext() {
956 // Return the default media context.
[email protected]cadac622013-06-11 16:46:36957 return io_data_.GetMediaRequestContextGetter().get();
[email protected]10705a7b2012-08-21 19:07:08958}
959
960net::URLRequestContextGetter*
961ProfileImpl::GetMediaRequestContextForRenderProcess(
962 int renderer_child_id) {
[email protected]10705a7b2012-08-21 19:07:08963 content::RenderProcessHost* rph = content::RenderProcessHost::FromID(
964 renderer_child_id);
[email protected]27ddfed22012-10-30 23:22:43965 content::StoragePartition* storage_partition = rph->GetStoragePartition();
966
[email protected]27ddfed22012-10-30 23:22:43967 return storage_partition->GetMediaURLRequestContext();
[email protected]5a0b42e2010-07-30 23:42:59968}
969
[email protected]10eb28162012-09-18 03:04:09970net::URLRequestContextGetter*
971ProfileImpl::GetMediaRequestContextForStoragePartition(
[email protected]650b2d52013-02-10 03:41:45972 const base::FilePath& partition_path,
[email protected]27ddfed22012-10-30 23:22:43973 bool in_memory) {
[email protected]cadac622013-06-11 16:46:36974 return io_data_
975 .GetIsolatedMediaRequestContextGetter(partition_path, in_memory).get();
[email protected]10eb28162012-09-18 03:04:09976}
977
[email protected]df02aca2012-02-09 21:03:20978content::ResourceContext* ProfileImpl::GetResourceContext() {
[email protected]e89b77d2011-04-15 18:58:10979 return io_data_.GetResourceContext();
980}
981
[email protected]33ad6ce92013-08-27 14:39:08982net::URLRequestContextGetter* ProfileImpl::GetRequestContextForExtensions() {
983 return io_data_.GetExtensionsRequestContextGetter().get();
984}
985
[email protected]6bd30072013-02-08 18:17:11986net::URLRequestContextGetter*
987ProfileImpl::CreateRequestContextForStoragePartition(
[email protected]650b2d52013-02-10 03:41:45988 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:11989 bool in_memory,
[email protected]7571263c2014-03-10 22:57:09990 content::ProtocolHandlerMap* protocol_handlers,
[email protected]3b90aab2014-05-30 17:56:15991 content::URLRequestInterceptorScopedVector request_interceptors) {
[email protected]6bd30072013-02-08 18:17:11992 return io_data_.CreateIsolatedAppRequestContextGetter(
[email protected]7571263c2014-03-10 22:57:09993 partition_path,
994 in_memory,
995 protocol_handlers,
[email protected]3b90aab2014-05-30 17:56:15996 request_interceptors.Pass()).get();
[email protected]d9696672011-03-15 22:45:09997}
998
[email protected]5a0b42e2010-07-30 23:42:59999net::SSLConfigService* ProfileImpl::GetSSLConfigService() {
[email protected]08fafe42013-02-03 08:10:491000 // If ssl_config_service_manager_ is null, this typically means that some
[email protected]540380fc2014-03-14 10:10:341001 // KeyedService is trying to create a RequestContext at startup,
[email protected]f1484c52013-05-22 23:25:441002 // but SSLConfigServiceManager is not initialized until DoFinalInit() which is
[email protected]540380fc2014-03-14 10:10:341003 // invoked after all KeyedServices have been initialized (see
[email protected]08fafe42013-02-03 08:10:491004 // http://crbug.com/171406).
[email protected]9332a3f72013-05-07 06:33:521005 DCHECK(ssl_config_service_manager_) <<
[email protected]08fafe42013-02-03 08:10:491006 "SSLConfigServiceManager is not initialized yet";
[email protected]5a0b42e2010-07-30 23:42:591007 return ssl_config_service_manager_->Get();
1008}
1009
1010HostContentSettingsMap* ProfileImpl::GetHostContentSettingsMap() {
mukaia1aa3512014-10-22 20:14:111011 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]5173de8b2013-06-02 21:16:021012 if (!host_content_settings_map_.get()) {
[email protected]646c29cb62012-06-18 14:31:051013 host_content_settings_map_ = new HostContentSettingsMap(GetPrefs(), false);
knn95221ffe2015-03-04 20:42:431014#if defined(ENABLE_SUPERVISED_USERS)
1015 SupervisedUserSettingsService* supervised_user_settings =
1016 SupervisedUserSettingsServiceFactory::GetForProfile(this);
1017 scoped_ptr<content_settings::SupervisedProvider> supervised_provider(
1018 new content_settings::SupervisedProvider(supervised_user_settings));
1019 host_content_settings_map_->RegisterProvider(
1020 HostContentSettingsMap::SUPERVISED_PROVIDER,
1021 supervised_provider.Pass());
1022#endif
[email protected]35552dc52011-07-12 09:04:381023 }
[email protected]5a0b42e2010-07-30 23:42:591024 return host_content_settings_map_.get();
1025}
1026
[email protected]139355f2014-05-11 14:21:281027content::BrowserPluginGuestManager* ProfileImpl::GetGuestManager() {
[email protected]1df3d972014-06-11 04:55:181028#if defined(ENABLE_EXTENSIONS)
fsamuel8dfa19a2015-05-05 01:00:391029 return guest_view::GuestViewManager::FromBrowserContext(this);
[email protected]1df3d972014-06-11 04:55:181030#else
1031 return NULL;
1032#endif
[email protected]24569262014-05-06 03:31:301033}
1034
[email protected]b441a8492012-06-06 14:55:571035DownloadManagerDelegate* ProfileImpl::GetDownloadManagerDelegate() {
[email protected]423939d2013-07-31 20:00:081036 return DownloadServiceFactory::GetForBrowserContext(this)->
[email protected]b441a8492012-06-06 14:55:571037 GetDownloadManagerDelegate();
[email protected]5a0b42e2010-07-30 23:42:591038}
1039
[email protected]cd501a72014-08-22 19:58:311040storage::SpecialStoragePolicy* ProfileImpl::GetSpecialStoragePolicy() {
[email protected]dfc0424c2014-07-25 21:33:201041#if defined(ENABLE_EXTENSIONS)
[email protected]55eb70e762012-02-20 17:38:391042 return GetExtensionSpecialStoragePolicy();
[email protected]dfc0424c2014-07-25 21:33:201043#else
1044 return NULL;
1045#endif
[email protected]55eb70e762012-02-20 17:38:391046}
1047
[email protected]c5c89d042014-06-13 14:43:371048content::PushMessagingService* ProfileImpl::GetPushMessagingService() {
b.kelemen4596b512015-03-04 18:42:471049 return PushMessagingServiceFactory::GetForProfile(this);
[email protected]c5c89d042014-06-13 14:43:371050}
1051
[email protected]c5bbe0e2014-08-01 23:23:301052content::SSLHostStateDelegate* ProfileImpl::GetSSLHostStateDelegate() {
1053 return ChromeSSLHostStateDelegateFactory::GetForProfile(this);
1054}
1055
mlamouri4e372022015-03-29 14:51:061056// TODO(mlamouri): we should all these BrowserContext implementation to Profile
1057// instead of repeating them inside all Profile implementations.
1058content::PermissionManager* ProfileImpl::GetPermissionManager() {
1059 return PermissionManagerFactory::GetForProfile(this);
1060}
1061
[email protected]5a0b42e2010-07-30 23:42:591062bool ProfileImpl::IsSameProfile(Profile* profile) {
1063 if (profile == static_cast<Profile*>(this))
1064 return true;
1065 Profile* otr_profile = off_the_record_profile_.get();
1066 return otr_profile && profile == otr_profile;
1067}
1068
1069Time ProfileImpl::GetStartTime() const {
1070 return start_time_;
1071}
1072
[email protected]cdb756ef2012-04-05 18:34:531073#if defined(ENABLE_SESSION_SERVICE)
[email protected]5a0b42e2010-07-30 23:42:591074void ProfileImpl::StopCreateSessionServiceTimer() {
1075 create_session_service_timer_.Stop();
1076}
1077
[email protected]92371eb2011-04-28 11:50:151078void ProfileImpl::EnsureSessionServiceCreated() {
1079 SessionServiceFactory::GetForProfile(this);
1080}
[email protected]cdb756ef2012-04-05 18:34:531081#endif
[email protected]92371eb2011-04-28 11:50:151082
[email protected]f50278cd2010-08-24 17:34:081083#if defined(OS_CHROMEOS)
[email protected]088a2962011-01-26 12:58:421084void ProfileImpl::ChangeAppLocale(
1085 const std::string& new_locale, AppLocaleChangedVia via) {
1086 if (new_locale.empty()) {
[email protected]61d68ef12011-01-13 14:02:561087 NOTREACHED();
1088 return;
1089 }
[email protected]db3abe62011-02-09 15:13:251090 PrefService* local_state = g_browser_process->local_state();
1091 DCHECK(local_state);
1092 if (local_state->IsManagedPreference(prefs::kApplicationLocale))
1093 return;
[email protected]088a2962011-01-26 12:58:421094 std::string pref_locale = GetPrefs()->GetString(prefs::kApplicationLocale);
1095 bool do_update_pref = true;
1096 switch (via) {
1097 case APP_LOCALE_CHANGED_VIA_SETTINGS:
1098 case APP_LOCALE_CHANGED_VIA_REVERT: {
1099 // We keep kApplicationLocaleBackup value as a reference. In case value
1100 // of kApplicationLocale preference would change due to sync from other
1101 // device then kApplicationLocaleBackup value will trigger and allow us to
1102 // show notification about automatic locale change in LocaleChangeGuard.
1103 GetPrefs()->SetString(prefs::kApplicationLocaleBackup, new_locale);
1104 GetPrefs()->ClearPref(prefs::kApplicationLocaleAccepted);
1105 // We maintain kApplicationLocale property in both a global storage
1106 // and user's profile. Global property determines locale of login screen,
1107 // while user's profile determines his personal locale preference.
[email protected]088a2962011-01-26 12:58:421108 break;
1109 }
[email protected]17fc16682014-07-31 19:51:061110 case APP_LOCALE_CHANGED_VIA_LOGIN:
1111 case APP_LOCALE_CHANGED_VIA_PUBLIC_SESSION_LOGIN: {
[email protected]088a2962011-01-26 12:58:421112 if (!pref_locale.empty()) {
1113 DCHECK(pref_locale == new_locale);
1114 std::string accepted_locale =
1115 GetPrefs()->GetString(prefs::kApplicationLocaleAccepted);
1116 if (accepted_locale == new_locale) {
1117 // If locale is accepted then we do not want to show LocaleChange
1118 // notification. This notification is triggered by different values
1119 // of kApplicationLocaleBackup and kApplicationLocale preferences,
1120 // so make them identical.
1121 GetPrefs()->SetString(prefs::kApplicationLocaleBackup, new_locale);
1122 } else {
1123 // Back up locale of login screen.
[email protected]b07090b32011-04-18 11:56:141124 std::string cur_locale = g_browser_process->GetApplicationLocale();
1125 GetPrefs()->SetString(prefs::kApplicationLocaleBackup, cur_locale);
1126 if (locale_change_guard_ == NULL)
1127 locale_change_guard_.reset(new chromeos::LocaleChangeGuard(this));
1128 locale_change_guard_->PrepareChangingLocale(cur_locale, new_locale);
[email protected]088a2962011-01-26 12:58:421129 }
1130 } else {
1131 std::string cur_locale = g_browser_process->GetApplicationLocale();
1132 std::string backup_locale =
1133 GetPrefs()->GetString(prefs::kApplicationLocaleBackup);
1134 // Profile synchronization takes time and is not completed at that
1135 // moment at first login. So we initialize locale preference in steps:
1136 // (1) first save it to temporary backup;
1137 // (2) on next login we assume that synchronization is already completed
1138 // and we may finalize initialization.
1139 GetPrefs()->SetString(prefs::kApplicationLocaleBackup, cur_locale);
[email protected]c2b68c82013-09-24 02:49:391140 if (!new_locale.empty())
1141 GetPrefs()->SetString(prefs::kApplicationLocale, new_locale);
1142 else if (!backup_locale.empty())
[email protected]088a2962011-01-26 12:58:421143 GetPrefs()->SetString(prefs::kApplicationLocale, backup_locale);
1144 do_update_pref = false;
1145 }
1146 break;
1147 }
1148 case APP_LOCALE_CHANGED_VIA_UNKNOWN:
1149 default: {
1150 NOTREACHED();
1151 break;
1152 }
[email protected]61d68ef12011-01-13 14:02:561153 }
[email protected]088a2962011-01-26 12:58:421154 if (do_update_pref)
1155 GetPrefs()->SetString(prefs::kApplicationLocale, new_locale);
[email protected]17fc16682014-07-31 19:51:061156 if (via != APP_LOCALE_CHANGED_VIA_PUBLIC_SESSION_LOGIN)
1157 local_state->SetString(prefs::kApplicationLocale, new_locale);
[email protected]c2a7e682011-03-16 13:03:181158
[email protected]4d390782014-08-15 09:22:581159 if (user_manager::UserManager::Get()->GetOwnerEmail() ==
[email protected]052e3ac2014-06-30 14:22:471160 chromeos::ProfileHelper::Get()->GetUserByProfile(this)->email())
[email protected]db3abe62011-02-09 15:13:251161 local_state->SetString(prefs::kOwnerLocale, new_locale);
[email protected]61d68ef12011-01-13 14:02:561162}
1163
[email protected]969182a2011-03-03 14:53:231164void ProfileImpl::OnLogin() {
[email protected]b07090b32011-04-18 11:56:141165 if (locale_change_guard_ == NULL)
1166 locale_change_guard_.reset(new chromeos::LocaleChangeGuard(this));
1167 locale_change_guard_->OnLogin();
[email protected]969182a2011-03-03 14:53:231168}
1169
[email protected]45b6ccca2011-02-16 04:27:461170void ProfileImpl::InitChromeOSPreferences() {
1171 chromeos_preferences_.reset(new chromeos::Preferences());
[email protected]aa003a52014-02-15 06:24:231172 chromeos_preferences_->Init(
[email protected]f0881cf2014-08-15 23:31:421173 this, chromeos::ProfileHelper::Get()->GetUserByProfile(this));
[email protected]45b6ccca2011-02-16 04:27:461174}
[email protected]1101dbc52013-10-05 00:19:121175
[email protected]f50278cd2010-08-24 17:34:081176#endif // defined(OS_CHROMEOS)
[email protected]cc5bfd42010-11-24 14:44:021177
1178PrefProxyConfigTracker* ProfileImpl::GetProxyConfigTracker() {
[email protected]e2930d0902013-07-17 05:25:421179 if (!pref_proxy_config_tracker_)
1180 pref_proxy_config_tracker_.reset(CreateProxyConfigTracker());
[email protected]6f96cbcb2011-11-04 02:26:071181 return pref_proxy_config_tracker_.get();
[email protected]cc5bfd42010-11-24 14:44:021182}
[email protected]33f74972010-12-08 16:40:361183
[email protected]67372ecf2011-09-10 01:30:461184chrome_browser_net::Predictor* ProfileImpl::GetNetworkPredictor() {
1185 return predictor_;
1186}
1187
[email protected]a4205202014-06-02 16:03:081188DevToolsNetworkController* ProfileImpl::GetDevToolsNetworkController() {
1189 return io_data_.GetDevToolsNetworkController();
1190}
1191
[email protected]9b2034032014-05-11 18:10:311192void ProfileImpl::ClearNetworkingHistorySince(
1193 base::Time time,
1194 const base::Closure& completion) {
[email protected]e0e1fc22012-11-05 20:25:361195 io_data_.ClearNetworkingHistorySince(time, completion);
[email protected]02896a82011-09-21 18:54:321196}
1197
[email protected]671f9c62011-10-28 19:22:071198GURL ProfileImpl::GetHomePage() {
1199 // --homepage overrides any preferences.
avi556c05022014-12-22 23:31:431200 const base::CommandLine& command_line =
1201 *base::CommandLine::ForCurrentProcess();
[email protected]671f9c62011-10-28 19:22:071202 if (command_line.HasSwitch(switches::kHomePage)) {
1203 // TODO(evanm): clean up usage of DIR_CURRENT.
1204 // http://code.google.com/p/chromium/issues/detail?id=60630
1205 // For now, allow this code to call getcwd().
1206 base::ThreadRestrictions::ScopedAllowIO allow_io;
1207
[email protected]650b2d52013-02-10 03:41:451208 base::FilePath browser_directory;
[email protected]671f9c62011-10-28 19:22:071209 PathService::Get(base::DIR_CURRENT, &browser_directory);
rsleevi24f64dc22015-08-07 21:39:211210 GURL home_page(url_formatter::FixupRelativeFile(
[email protected]9b5b1d602014-06-12 14:29:021211 browser_directory,
[email protected]671f9c62011-10-28 19:22:071212 command_line.GetSwitchValuePath(switches::kHomePage)));
1213 if (home_page.is_valid())
1214 return home_page;
1215 }
1216
1217 if (GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage))
1218 return GURL(chrome::kChromeUINewTabURL);
rsleevi24f64dc22015-08-07 21:39:211219 GURL home_page(url_formatter::FixupURL(
1220 GetPrefs()->GetString(prefs::kHomePage), std::string()));
[email protected]671f9c62011-10-28 19:22:071221 if (!home_page.is_valid())
1222 return GURL(chrome::kChromeUINewTabURL);
1223 return home_page;
1224}
1225
[email protected]d20d0432014-06-12 17:14:051226void ProfileImpl::UpdateProfileSupervisedUserIdCache() {
[email protected]6ebd60c2014-04-28 23:45:201227 ProfileManager* profile_manager = g_browser_process->profile_manager();
1228 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
1229 size_t index = cache.GetIndexOfProfileWithPath(GetPath());
1230 if (index != std::string::npos) {
[email protected]d20d0432014-06-12 17:14:051231 std::string supervised_user_id =
1232 GetPrefs()->GetString(prefs::kSupervisedUserId);
1233 cache.SetSupervisedUserIdOfProfileAtIndex(index, supervised_user_id);
[email protected]6ebd60c2014-04-28 23:45:201234 ProfileMetrics::UpdateReportedProfilesStatistics(profile_manager);
1235 }
1236}
1237
[email protected]881cb0b62011-12-13 20:39:541238void ProfileImpl::UpdateProfileNameCache() {
1239 ProfileManager* profile_manager = g_browser_process->profile_manager();
1240 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
1241 size_t index = cache.GetIndexOfProfileWithPath(GetPath());
1242 if (index != std::string::npos) {
1243 std::string profile_name =
1244 GetPrefs()->GetString(prefs::kProfileName);
[email protected]6778fed2013-12-24 20:09:371245 cache.SetNameOfProfileAtIndex(index, base::UTF8ToUTF16(profile_name));
[email protected]1cdf0932014-08-16 06:00:491246 bool default_name =
1247 GetPrefs()->GetBoolean(prefs::kProfileUsingDefaultName);
1248 cache.SetProfileIsUsingDefaultNameAtIndex(index, default_name);
[email protected]881cb0b62011-12-13 20:39:541249 }
1250}
1251
1252void ProfileImpl::UpdateProfileAvatarCache() {
1253 ProfileManager* profile_manager = g_browser_process->profile_manager();
1254 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
1255 size_t index = cache.GetIndexOfProfileWithPath(GetPath());
1256 if (index != std::string::npos) {
1257 size_t avatar_index =
1258 GetPrefs()->GetInteger(prefs::kProfileAvatarIndex);
1259 cache.SetAvatarIconOfProfileAtIndex(index, avatar_index);
[email protected]1cdf0932014-08-16 06:00:491260 bool default_avatar =
1261 GetPrefs()->GetBoolean(prefs::kProfileUsingDefaultAvatar);
1262 cache.SetProfileIsUsingDefaultAvatarAtIndex(index, default_avatar);
1263 bool gaia_avatar =
1264 GetPrefs()->GetBoolean(prefs::kProfileUsingGAIAAvatar);
1265 cache.SetIsUsingGAIAPictureOfProfileAtIndex(index, gaia_avatar);
[email protected]881cb0b62011-12-13 20:39:541266 }
1267}
1268
[email protected]8d9243a2013-10-21 17:11:481269void ProfileImpl::UpdateProfileIsEphemeralCache() {
1270 ProfileManager* profile_manager = g_browser_process->profile_manager();
1271 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
1272 size_t index = cache.GetIndexOfProfileWithPath(GetPath());
1273 if (index != std::string::npos) {
1274 bool is_ephemeral = GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles);
1275 cache.SetProfileIsEphemeralAtIndex(index, is_ephemeral);
1276 }
1277}
1278
[email protected]f2df3112011-11-18 10:21:481279// Gets the cache parameters from the command line. If |is_media_context| is
1280// set to true then settings for the media context type is what we need,
1281// |cache_path| will be set to the user provided path, or will not be touched if
1282// there is not an argument. |max_size| will be the user provided value or zero
1283// by default.
1284void ProfileImpl::GetCacheParameters(bool is_media_context,
[email protected]650b2d52013-02-10 03:41:451285 base::FilePath* cache_path,
[email protected]f2df3112011-11-18 10:21:481286 int* max_size) {
1287 DCHECK(cache_path);
1288 DCHECK(max_size);
[email protected]650b2d52013-02-10 03:41:451289 base::FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir));
[email protected]f2df3112011-11-18 10:21:481290 if (!path.empty())
1291 *cache_path = path;
1292 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) :
1293 prefs_->GetInteger(prefs::kDiskCacheSize);
1294}
[email protected]e2930d0902013-07-17 05:25:421295
1296PrefProxyConfigTracker* ProfileImpl::CreateProxyConfigTracker() {
1297#if defined(OS_CHROMEOS)
1298 if (chromeos::ProfileHelper::IsSigninProfile(this)) {
1299 return ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState(
1300 g_browser_process->local_state());
1301 }
1302#endif // defined(OS_CHROMEOS)
1303 return ProxyServiceFactory::CreatePrefProxyConfigTrackerOfProfile(
1304 GetPrefs(), g_browser_process->local_state());
1305}
[email protected]fba33a02014-06-22 15:42:161306
1307scoped_ptr<domain_reliability::DomainReliabilityMonitor>
ttuttlefa8427f92014-08-25 19:38:031308ProfileImpl::CreateDomainReliabilityMonitor(PrefService* local_state) {
[email protected]fba33a02014-06-22 15:42:161309 domain_reliability::DomainReliabilityService* service =
1310 domain_reliability::DomainReliabilityServiceFactory::GetInstance()->
1311 GetForBrowserContext(this);
1312 if (!service)
1313 return scoped_ptr<domain_reliability::DomainReliabilityMonitor>();
1314
1315 return service->CreateMonitor(
ttuttle91f1bbd2014-10-07 05:57:541316 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
[email protected]fba33a02014-06-22 15:42:161317}