[email protected] | ea12b5b | 2012-01-06 21:27:15 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 5 | #include "chrome/browser/profiles/profile_impl.h" |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 6 | |
[email protected] | 54b8e18 | 2014-05-02 18:08:29 | [diff] [blame] | 7 | #include <vector> |
| 8 | |
[email protected] | 791be42 | 2011-10-29 19:21:01 | [diff] [blame] | 9 | #include "base/bind.h" |
[email protected] | a6a7ced | 2012-11-01 17:24:18 | [diff] [blame] | 10 | #include "base/callback.h" |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 11 | #include "base/command_line.h" |
[email protected] | f6c21cb | 2011-02-16 19:45:41 | [diff] [blame] | 12 | #include "base/compiler_specific.h" |
[email protected] | 76b90d31 | 2010-08-03 03:00:50 | [diff] [blame] | 13 | #include "base/environment.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 14 | #include "base/files/file_path.h" |
thestig | 18dfb7a5 | 2014-08-26 10:44:04 | [diff] [blame] | 15 | #include "base/files/file_util.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 16 | #include "base/memory/scoped_ptr.h" |
wjmaclean | 2c98cb19 | 2014-11-26 19:55:27 | [diff] [blame] | 17 | #include "base/memory/weak_ptr.h" |
rkaplow | 058da313 | 2015-02-19 18:18:38 | [diff] [blame] | 18 | #include "base/metrics/histogram_macros.h" |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 19 | #include "base/path_service.h" |
[email protected] | 0de615a | 2012-11-08 04:40:59 | [diff] [blame] | 20 | #include "base/prefs/json_pref_store.h" |
[email protected] | 9eec53fe | 2013-10-30 20:21:17 | [diff] [blame] | 21 | #include "base/prefs/scoped_user_pref_update.h" |
[email protected] | 3ea1b18 | 2013-02-08 22:38:41 | [diff] [blame] | 22 | #include "base/strings/string_number_conversions.h" |
[email protected] | 76fb05c | 2013-06-11 04:38:05 | [diff] [blame] | 23 | #include "base/strings/string_util.h" |
| 24 | #include "base/strings/stringprintf.h" |
[email protected] | e309f31 | 2013-06-07 21:50:08 | [diff] [blame] | 25 | #include "base/strings/utf_string_conversions.h" |
[email protected] | 0de615a | 2012-11-08 04:40:59 | [diff] [blame] | 26 | #include "base/synchronization/waitable_event.h" |
| 27 | #include "base/threading/sequenced_worker_pool.h" |
calamity | f4f08cfe | 2015-06-17 02:39:02 | [diff] [blame] | 28 | #include "base/threading/thread_restrictions.h" |
primiano | 6221e57 | 2015-01-28 12:14:34 | [diff] [blame] | 29 | #include "base/trace_event/trace_event.h" |
[email protected] | 1bee6ed | 2012-03-14 06:46:36 | [diff] [blame] | 30 | #include "base/version.h" |
[email protected] | a07676b2 | 2011-06-17 16:36:53 | [diff] [blame] | 31 | #include "chrome/browser/background/background_contents_service_factory.h" |
[email protected] | 68b9351 | 2013-02-08 18:17:57 | [diff] [blame] | 32 | #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 33 | #include "chrome/browser/browser_process.h" |
[email protected] | 25ff086 | 2013-07-12 00:59:03 | [diff] [blame] | 34 | #include "chrome/browser/chrome_notification_types.h" |
droger | b171697 | 2015-06-30 09:04:09 | [diff] [blame] | 35 | #include "chrome/browser/content_settings/cookie_settings_factory.h" |
nyquist | 6e3ab0a5 | 2014-09-26 17:54:25 | [diff] [blame] | 36 | #include "chrome/browser/dom_distiller/profile_utils.h" |
[email protected] | fba33a0 | 2014-06-22 15:42:16 | [diff] [blame] | 37 | #include "chrome/browser/domain_reliability/service_factory.h" |
[email protected] | 4766544 | 2012-07-27 02:31:22 | [diff] [blame] | 38 | #include "chrome/browser/download/chrome_download_manager_delegate.h" |
[email protected] | 9bb54ee | 2011-10-12 17:43:35 | [diff] [blame] | 39 | #include "chrome/browser/download/download_service.h" |
| 40 | #include "chrome/browser/download/download_service_factory.h" |
[email protected] | dd83007 | 2010-10-05 09:32:44 | [diff] [blame] | 41 | #include "chrome/browser/net/net_pref_observer.h" |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 42 | #include "chrome/browser/net/predictor.h" |
[email protected] | 53c5b0f | 2013-07-22 10:54:11 | [diff] [blame] | 43 | #include "chrome/browser/net/pref_proxy_config_tracker.h" |
[email protected] | 6f96cbcb | 2011-11-04 02:26:07 | [diff] [blame] | 44 | #include "chrome/browser/net/proxy_service_factory.h" |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 45 | #include "chrome/browser/net/ssl_config_service_manager.h" |
mlamouri | 4e37202 | 2015-03-29 14:51:06 | [diff] [blame] | 46 | #include "chrome/browser/permissions/permission_manager.h" |
| 47 | #include "chrome/browser/permissions/permission_manager_factory.h" |
[email protected] | c2295f7 | 2013-01-03 22:18:56 | [diff] [blame] | 48 | #include "chrome/browser/plugins/chrome_plugin_service_filter.h" |
[email protected] | 0f5e57f5 | 2012-09-20 20:53:18 | [diff] [blame] | 49 | #include "chrome/browser/plugins/plugin_prefs.h" |
[email protected] | d81bb3e | 2013-05-02 18:17:03 | [diff] [blame] | 50 | #include "chrome/browser/policy/profile_policy_connector.h" |
| 51 | #include "chrome/browser/policy/profile_policy_connector_factory.h" |
[email protected] | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 52 | #include "chrome/browser/prefs/browser_prefs.h" |
[email protected] | 5b19952 | 2012-12-22 17:24:44 | [diff] [blame] | 53 | #include "chrome/browser/prefs/chrome_pref_service_factory.h" |
[email protected] | c753f14 | 2013-02-10 13:14:04 | [diff] [blame] | 54 | #include "chrome/browser/prefs/pref_service_syncable.h" |
[email protected] | 086dfcb | 2014-05-26 23:43:03 | [diff] [blame] | 55 | #include "chrome/browser/prefs/tracked/tracked_preference_validation_delegate.h" |
[email protected] | 3085c50 | 2011-10-05 17:50:50 | [diff] [blame] | 56 | #include "chrome/browser/prerender/prerender_manager_factory.h" |
[email protected] | 68b9351 | 2013-02-08 18:17:57 | [diff] [blame] | 57 | #include "chrome/browser/profiles/bookmark_model_loaded_observer.h" |
[email protected] | 1bee6ed | 2012-03-14 06:46:36 | [diff] [blame] | 58 | #include "chrome/browser/profiles/chrome_version_service.h" |
[email protected] | 933b3f6 | 2013-01-03 20:44:21 | [diff] [blame] | 59 | #include "chrome/browser/profiles/gaia_info_update_service_factory.h" |
[email protected] | 10ce4cf | 2012-06-26 20:09:16 | [diff] [blame] | 60 | #include "chrome/browser/profiles/profile_destroyer.h" |
[email protected] | e8e7809 | 2011-09-29 18:15:38 | [diff] [blame] | 61 | #include "chrome/browser/profiles/profile_info_cache.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 62 | #include "chrome/browser/profiles/profile_manager.h" |
[email protected] | e34796d | 2013-11-28 19:56:37 | [diff] [blame] | 63 | #include "chrome/browser/profiles/profile_metrics.h" |
b.kelemen | 4596b51 | 2015-03-04 18:42:47 | [diff] [blame] | 64 | #include "chrome/browser/push_messaging/push_messaging_service_factory.h" |
| 65 | #include "chrome/browser/push_messaging/push_messaging_service_impl.h" |
[email protected] | 0823c68d | 2014-06-13 22:23:47 | [diff] [blame] | 66 | #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
[email protected] | c5c89d04 | 2014-06-13 14:43:37 | [diff] [blame] | 67 | #include "chrome/browser/services/gcm/gcm_profile_service.h" |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 68 | #include "chrome/browser/sessions/session_service_factory.h" |
rogerta | 614597db | 2014-12-05 17:57:32 | [diff] [blame] | 69 | #include "chrome/browser/signin/signin_manager_factory.h" |
[email protected] | 9086ce5a | 2014-08-14 15:15:04 | [diff] [blame] | 70 | #include "chrome/browser/signin/signin_ui_util.h" |
[email protected] | c5bbe0e | 2014-08-01 23:23:30 | [diff] [blame] | 71 | #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h" |
| 72 | #include "chrome/browser/ssl/chrome_ssl_host_state_delegate_factory.h" |
[email protected] | fe7c487 | 2012-05-10 20:06:03 | [diff] [blame] | 73 | #include "chrome/browser/ui/startup/startup_browser_creator.h" |
wjmaclean | e530aa74 | 2014-10-14 21:43:30 | [diff] [blame] | 74 | #include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h" |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 75 | #include "chrome/common/chrome_constants.h" |
[email protected] | b411da3 | 2010-11-24 02:23:15 | [diff] [blame] | 76 | #include "chrome/common/chrome_paths_internal.h" |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 77 | #include "chrome/common/chrome_switches.h" |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 78 | #include "chrome/common/pref_names.h" |
[email protected] | 671f9c6 | 2011-10-28 19:22:07 | [diff] [blame] | 79 | #include "chrome/common/url_constants.h" |
[email protected] | af39f00 | 2014-08-22 10:18:18 | [diff] [blame] | 80 | #include "chrome/grit/chromium_strings.h" |
[email protected] | a90c8ca | 2014-05-20 17:16:04 | [diff] [blame] | 81 | #include "components/bookmarks/browser/bookmark_model.h" |
droger | b171697 | 2015-06-30 09:04:09 | [diff] [blame] | 82 | #include "components/content_settings/core/browser/cookie_settings.h" |
mukai | 8eaec82 | 2014-10-25 17:53:16 | [diff] [blame] | 83 | #include "components/content_settings/core/browser/host_content_settings_map.h" |
[email protected] | fba33a0 | 2014-06-22 15:42:16 | [diff] [blame] | 84 | #include "components/domain_reliability/monitor.h" |
| 85 | #include "components/domain_reliability/service.h" |
[email protected] | 540380fc | 2014-03-14 10:10:34 | [diff] [blame] | 86 | #include "components/keyed_service/content/browser_context_dependency_manager.h" |
[email protected] | d6147bd | 2014-06-11 01:58:19 | [diff] [blame] | 87 | #include "components/metrics/metrics_service.h" |
blundell | 2102f7c | 2015-07-09 10:00:53 | [diff] [blame] | 88 | #include "components/omnibox/browser/autocomplete_classifier.h" |
| 89 | #include "components/omnibox/browser/shortcuts_backend.h" |
[email protected] | f0c8c499 | 2014-05-15 17:37:26 | [diff] [blame] | 90 | #include "components/pref_registry/pref_registry_syncable.h" |
rogerta | 614597db | 2014-12-05 17:57:32 | [diff] [blame] | 91 | #include "components/signin/core/browser/signin_manager.h" |
wjmaclean | 7f63c6b | 2014-12-09 14:59:55 | [diff] [blame] | 92 | #include "components/ui/zoom/zoom_event_manager.h" |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame^] | 93 | #include "components/url_formatter/url_fixer.h" |
[email protected] | 75fee37 | 2013-03-06 00:42:44 | [diff] [blame] | 94 | #include "components/user_prefs/user_prefs.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 95 | #include "content/public/browser/browser_thread.h" |
[email protected] | 4d63bbd | 2012-08-07 09:23:52 | [diff] [blame] | 96 | #include "content/public/browser/dom_storage_context.h" |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 97 | #include "content/public/browser/notification_service.h" |
[email protected] | fb29e6cf | 2012-07-12 21:27:20 | [diff] [blame] | 98 | #include "content/public/browser/render_process_host.h" |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 99 | #include "content/public/browser/storage_partition.h" |
[email protected] | 7e856dde | 2014-03-15 00:34:05 | [diff] [blame] | 100 | #include "content/public/browser/url_data_source.h" |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 101 | #include "content/public/browser/user_metrics.h" |
[email protected] | 3307537b | 2012-08-29 03:15:15 | [diff] [blame] | 102 | #include "content/public/common/content_constants.h" |
[email protected] | 54b8e18 | 2014-05-02 18:08:29 | [diff] [blame] | 103 | #include "content/public/common/page_zoom.h" |
[email protected] | 65a9cc1 | 2012-03-20 15:10:18 | [diff] [blame] | 104 | #include "ui/base/l10n/l10n_util.h" |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 105 | |
[email protected] | 566755f8 | 2014-01-08 01:14:57 | [diff] [blame] | 106 | #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] | 1df3d97 | 2014-06-11 04:55:18 | [diff] [blame] | 109 | #endif |
| 110 | |
| 111 | #if defined(OS_CHROMEOS) |
| 112 | #include "chrome/browser/chromeos/locale_change_guard.h" |
[email protected] | 1df3d97 | 2014-06-11 04:55:18 | [diff] [blame] | 113 | #include "chrome/browser/chromeos/preferences.h" |
| 114 | #include "chrome/browser/chromeos/profiles/profile_helper.h" |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 115 | #include "components/user_manager/user_manager.h" |
[email protected] | 1df3d97 | 2014-06-11 04:55:18 | [diff] [blame] | 116 | #endif |
[email protected] | 566755f8 | 2014-01-08 01:14:57 | [diff] [blame] | 117 | |
thestig | e415584 | 2014-10-20 18:58:02 | [diff] [blame] | 118 | #if defined(ENABLE_BACKGROUND) |
| 119 | #include "chrome/browser/background/background_mode_manager.h" |
| 120 | #endif |
| 121 | |
[email protected] | e148048 | 2013-09-11 11:49:58 | [diff] [blame] | 122 | #if defined(ENABLE_CONFIGURATION_POLICY) |
[email protected] | eb83c39 | 2013-11-07 12:53:24 | [diff] [blame] | 123 | #include "chrome/browser/policy/schema_registry_service.h" |
| 124 | #include "chrome/browser/policy/schema_registry_service_factory.h" |
[email protected] | 9727582 | 2014-01-21 19:30:36 | [diff] [blame] | 125 | #include "components/policy/core/browser/browser_policy_connector.h" |
[email protected] | e148048 | 2013-09-11 11:49:58 | [diff] [blame] | 126 | #if defined(OS_CHROMEOS) |
nkostylev | 4d2391a | 2014-11-14 16:15:04 | [diff] [blame] | 127 | #include "chrome/browser/chromeos/login/session/user_session_manager.h" |
[email protected] | e148048 | 2013-09-11 11:49:58 | [diff] [blame] | 128 | #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] | e148048 | 2013-09-11 11:49:58 | [diff] [blame] | 131 | #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" |
[email protected] | d769050f | 2013-12-12 17:48:01 | [diff] [blame] | 132 | #include "components/policy/core/common/cloud/user_cloud_policy_manager.h" |
[email protected] | e148048 | 2013-09-11 11:49:58 | [diff] [blame] | 133 | #endif |
| 134 | #endif |
| 135 | |
[email protected] | 1df3d97 | 2014-06-11 04:55:18 | [diff] [blame] | 136 | #if defined(ENABLE_EXTENSIONS) |
[email protected] | dfc0424c | 2014-07-25 21:33:20 | [diff] [blame] | 137 | #include "chrome/browser/extensions/extension_service.h" |
| 138 | #include "chrome/browser/extensions/extension_special_storage_policy.h" |
[email protected] | dfc0424c | 2014-07-25 21:33:20 | [diff] [blame] | 139 | #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
fsamuel | 8dfa19a | 2015-05-05 01:00:39 | [diff] [blame] | 140 | #include "components/guest_view/browser/guest_view_manager.h" |
[email protected] | dfc0424c | 2014-07-25 21:33:20 | [diff] [blame] | 141 | #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] | 1df3d97 | 2014-06-11 04:55:18 | [diff] [blame] | 145 | #endif |
| 146 | |
treib | 87bb89cbb | 2014-12-01 16:01:47 | [diff] [blame] | 147 | #if defined(ENABLE_SUPERVISED_USERS) |
knn | 95221ffe | 2015-03-04 20:42:43 | [diff] [blame] | 148 | #include "chrome/browser/content_settings/content_settings_supervised_provider.h" |
treib | 3c8cf13 | 2014-12-08 15:09:32 | [diff] [blame] | 149 | #include "chrome/browser/supervised_user/supervised_user_constants.h" |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 150 | #include "chrome/browser/supervised_user/supervised_user_settings_service.h" |
| 151 | #include "chrome/browser/supervised_user/supervised_user_settings_service_factory.h" |
[email protected] | e148048 | 2013-09-11 11:49:58 | [diff] [blame] | 152 | #endif |
| 153 | |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 154 | using base::Time; |
| 155 | using base::TimeDelta; |
[email protected] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 156 | using base::UserMetricsAction; |
tfarina | a0ec34e | 2015-01-12 18:46:48 | [diff] [blame] | 157 | using bookmarks::BookmarkModel; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 158 | using content::BrowserThread; |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 159 | using content::DownloadManagerDelegate; |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 160 | |
| 161 | namespace { |
| 162 | |
[email protected] | cdb756ef | 2012-04-05 18:34:53 | [diff] [blame] | 163 | #if defined(ENABLE_SESSION_SERVICE) |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 164 | // Delay, in milliseconds, before we explicitly create the SessionService. |
[email protected] | dfc0424c | 2014-07-25 21:33:20 | [diff] [blame] | 165 | const int kCreateSessionServiceDelayMS = 500; |
[email protected] | cdb756ef | 2012-04-05 18:34:53 | [diff] [blame] | 166 | #endif |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 167 | |
[email protected] | 65a9cc1 | 2012-03-20 15:10:18 | [diff] [blame] | 168 | // 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] | dfc0424c | 2014-07-25 21:33:20 | [diff] [blame] | 171 | const char kReadmeText[] = |
[email protected] | 65a9cc1 | 2012-03-20 15:10:18 | [diff] [blame] | 172 | "%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] | 6c0ca7fc | 2012-10-05 16:27:22 | [diff] [blame] | 176 | // Value written to prefs for EXIT_CRASHED and EXIT_SESSION_ENDED. |
[email protected] | dfc0424c | 2014-07-25 21:33:20 | [diff] [blame] | 177 | const char kPrefExitTypeCrashed[] = "Crashed"; |
| 178 | const char kPrefExitTypeSessionEnded[] = "SessionEnded"; |
[email protected] | 6c0ca7fc | 2012-10-05 16:27:22 | [diff] [blame] | 179 | |
calamity | f4f08cfe | 2015-06-17 02:39:02 | [diff] [blame] | 180 | void 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] | 0de615a | 2012-11-08 04:40:59 | [diff] [blame] | 192 | // Helper method needed because PostTask cannot currently take a Callback |
| 193 | // function with non-void return type. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 194 | void CreateDirectoryAndSignal(const base::FilePath& path, |
calamity | f4f08cfe | 2015-06-17 02:39:02 | [diff] [blame] | 195 | 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] | 0de615a | 2012-11-08 04:40:59 | [diff] [blame] | 204 | DVLOG(1) << "Creating directory " << path.value(); |
calamity | f4f08cfe | 2015-06-17 02:39:02 | [diff] [blame] | 205 | if (base::CreateDirectory(path) && create_readme) |
| 206 | CreateProfileReadme(path); |
[email protected] | 0de615a | 2012-11-08 04:40:59 | [diff] [blame] | 207 | done_creating->Signal(); |
| 208 | } |
| 209 | |
| 210 | // Task that blocks the FILE thread until CreateDirectoryAndSignal() finishes on |
| 211 | // blocking I/O pool. |
| 212 | void BlockFileThreadOnDirectoryCreate(base::WaitableEvent* done_creating) { |
| 213 | done_creating->Wait(); |
| 214 | } |
| 215 | |
| 216 | // Initiates creation of profile directory on |sequenced_task_runner| and |
calamity | f4f08cfe | 2015-06-17 02:39:02 | [diff] [blame] | 217 | // 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] | 0de615a | 2012-11-08 04:40:59 | [diff] [blame] | 220 | void CreateProfileDirectory(base::SequencedTaskRunner* sequenced_task_runner, |
calamity | f4f08cfe | 2015-06-17 02:39:02 | [diff] [blame] | 221 | const base::FilePath& path, |
| 222 | bool create_readme) { |
[email protected] | 0de615a | 2012-11-08 04:40:59 | [diff] [blame] | 223 | base::WaitableEvent* done_creating = new base::WaitableEvent(false, false); |
calamity | f4f08cfe | 2015-06-17 02:39:02 | [diff] [blame] | 224 | sequenced_task_runner->PostTask( |
| 225 | FROM_HERE, base::Bind(&CreateDirectoryAndSignal, path, done_creating, |
| 226 | create_readme)); |
[email protected] | 0de615a | 2012-11-08 04:40:59 | [diff] [blame] | 227 | // 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] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 235 | base::FilePath GetCachePath(const base::FilePath& base) { |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 236 | return base.Append(chrome::kCacheDirname); |
| 237 | } |
| 238 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 239 | base::FilePath GetMediaCachePath(const base::FilePath& base) { |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 240 | return base.Append(chrome::kMediaCacheDirname); |
| 241 | } |
| 242 | |
[email protected] | 6c0ca7fc | 2012-10-05 16:27:22 | [diff] [blame] | 243 | // Converts the kSessionExitedCleanly pref to the corresponding EXIT_TYPE. |
| 244 | Profile::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. |
| 253 | std::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] | dfc0424c | 2014-07-25 21:33:20 | [diff] [blame] | 266 | PrefStore* 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] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 277 | } // namespace |
| 278 | |
| 279 | // static |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 280 | Profile* Profile::CreateProfile(const base::FilePath& path, |
[email protected] | 00b33f80 | 2012-03-13 07:46:03 | [diff] [blame] | 281 | Delegate* delegate, |
| 282 | CreateMode create_mode) { |
rkaplow | 058da313 | 2015-02-19 18:18:38 | [diff] [blame] | 283 | TRACE_EVENT1("browser,startup", |
| 284 | "Profile::CreateProfile", |
| 285 | "profile_path", |
| 286 | path.AsUTF8Unsafe()); |
[email protected] | afe1099 | 2014-06-26 17:48:07 | [diff] [blame] | 287 | |
[email protected] | 0de615a | 2012-11-08 04:40:59 | [diff] [blame] | 288 | // 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] | 00b33f80 | 2012-03-13 07:46:03 | [diff] [blame] | 294 | if (create_mode == CREATE_MODE_ASYNCHRONOUS) { |
| 295 | DCHECK(delegate); |
calamity | f4f08cfe | 2015-06-17 02:39:02 | [diff] [blame] | 296 | CreateProfileDirectory(sequenced_task_runner.get(), path, true); |
[email protected] | 00b33f80 | 2012-03-13 07:46:03 | [diff] [blame] | 297 | } else if (create_mode == CREATE_MODE_SYNCHRONOUS) { |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 298 | if (!base::PathExists(path)) { |
rkaplow | 058da313 | 2015-02-19 18:18:38 | [diff] [blame] | 299 | // 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] | 426d1c9 | 2013-12-03 20:08:54 | [diff] [blame] | 302 | if (!base::CreateDirectory(path)) |
[email protected] | 00b33f80 | 2012-03-13 07:46:03 | [diff] [blame] | 303 | return NULL; |
calamity | f4f08cfe | 2015-06-17 02:39:02 | [diff] [blame] | 304 | |
| 305 | CreateProfileReadme(path); |
[email protected] | 00b33f80 | 2012-03-13 07:46:03 | [diff] [blame] | 306 | } |
| 307 | } else { |
| 308 | NOTREACHED(); |
[email protected] | 844a100 | 2011-04-19 11:37:21 | [diff] [blame] | 309 | } |
[email protected] | 844a100 | 2011-04-19 11:37:21 | [diff] [blame] | 310 | |
[email protected] | 5173de8b | 2013-06-02 21:16:02 | [diff] [blame] | 311 | return new ProfileImpl( |
| 312 | path, delegate, create_mode, sequenced_task_runner.get()); |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 313 | } |
| 314 | |
[email protected] | e19cf1e | 2010-10-01 12:31:34 | [diff] [blame] | 315 | // static |
[email protected] | 6c0ca7fc | 2012-10-05 16:27:22 | [diff] [blame] | 316 | const char* const ProfileImpl::kPrefExitTypeNormal = "Normal"; |
| 317 | |
| 318 | // static |
[email protected] | 37ca3fe0 | 2013-07-05 15:32:44 | [diff] [blame] | 319 | void ProfileImpl::RegisterProfilePrefs( |
[email protected] | 443e931 | 2013-05-06 06:17:34 | [diff] [blame] | 320 | user_prefs::PrefRegistrySyncable* registry) { |
raymes | aa60872 | 2015-04-27 03:00:25 | [diff] [blame] | 321 | 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] | 443e931 | 2013-05-06 06:17:34 | [diff] [blame] | 327 | registry->RegisterIntegerPref( |
| 328 | prefs::kProfileAvatarIndex, |
| 329 | -1, |
| 330 | user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
[email protected] | 1cdf093 | 2014-08-16 06:00:49 | [diff] [blame] | 331 | // 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); |
raymes | aa60872 | 2015-04-27 03:00:25 | [diff] [blame] | 346 | registry->RegisterStringPref(prefs::kSupervisedUserId, std::string()); |
[email protected] | 443e931 | 2013-05-06 06:17:34 | [diff] [blame] | 347 | registry->RegisterStringPref(prefs::kProfileName, |
| 348 | std::string(), |
| 349 | user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
[email protected] | c753f14 | 2013-02-10 13:14:04 | [diff] [blame] | 350 | registry->RegisterStringPref(prefs::kHomePage, |
| 351 | std::string(), |
[email protected] | 443e931 | 2013-05-06 06:17:34 | [diff] [blame] | 352 | user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
[email protected] | 0045b0f4 | 2012-07-26 11:52:08 | [diff] [blame] | 353 | #if defined(ENABLE_PRINTING) |
raymes | aa60872 | 2015-04-27 03:00:25 | [diff] [blame] | 354 | registry->RegisterBooleanPref(prefs::kPrintingEnabled, true); |
[email protected] | 0045b0f4 | 2012-07-26 11:52:08 | [diff] [blame] | 355 | #endif |
raymes | aa60872 | 2015-04-27 03:00:25 | [diff] [blame] | 356 | registry->RegisterBooleanPref(prefs::kPrintPreviewDisabled, false); |
| 357 | registry->RegisterBooleanPref(prefs::kForceEphemeralProfiles, false); |
[email protected] | bca1838 | 2012-06-25 19:15:23 | [diff] [blame] | 358 | |
| 359 | // Initialize the cache prefs. |
raymes | aa60872 | 2015-04-27 03:00:25 | [diff] [blame] | 360 | registry->RegisterFilePathPref(prefs::kDiskCacheDir, base::FilePath()); |
| 361 | registry->RegisterIntegerPref(prefs::kDiskCacheSize, 0); |
| 362 | registry->RegisterIntegerPref(prefs::kMediaCacheSize, 0); |
[email protected] | bf510ed | 2012-06-05 08:31:43 | [diff] [blame] | 363 | |
| 364 | // Deprecated. Kept around for migration. |
[email protected] | 443e931 | 2013-05-06 06:17:34 | [diff] [blame] | 365 | registry->RegisterBooleanPref( |
| 366 | prefs::kClearSiteDataOnExit, |
| 367 | false, |
| 368 | user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
[email protected] | e19cf1e | 2010-10-01 12:31:34 | [diff] [blame] | 369 | } |
| 370 | |
[email protected] | 0de615a | 2012-11-08 04:40:59 | [diff] [blame] | 371 | ProfileImpl::ProfileImpl( |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 372 | const base::FilePath& path, |
[email protected] | 0de615a | 2012-11-08 04:40:59 | [diff] [blame] | 373 | Delegate* delegate, |
| 374 | CreateMode create_mode, |
| 375 | base::SequencedTaskRunner* sequenced_task_runner) |
[email protected] | 11783281 | 2013-10-02 07:06:02 | [diff] [blame] | 376 | : path_(path), |
[email protected] | 443e931 | 2013-05-06 06:17:34 | [diff] [blame] | 377 | pref_registry_(new user_prefs::PrefRegistrySyncable), |
[email protected] | 9c00909 | 2013-05-01 03:14:09 | [diff] [blame] | 378 | io_data_(this), |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 379 | host_content_settings_map_(NULL), |
[email protected] | 6c0ca7fc | 2012-10-05 16:27:22 | [diff] [blame] | 380 | last_session_exit_type_(EXIT_NORMAL), |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 381 | start_time_(Time::Now()), |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 382 | delegate_(delegate), |
[email protected] | 3c7c144 | 2012-08-08 12:21:45 | [diff] [blame] | 383 | predictor_(NULL) { |
rkaplow | 058da313 | 2015-02-19 18:18:38 | [diff] [blame] | 384 | TRACE_EVENT0("browser,startup", "ProfileImpl::ctor") |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 385 | DCHECK(!path.empty()) << "Using an empty path will attempt to write " << |
| 386 | "profile files to the root directory!"; |
[email protected] | 0e3a385d | 2011-05-26 23:38:18 | [diff] [blame] | 387 | |
[email protected] | cdb756ef | 2012-04-05 18:34:53 | [diff] [blame] | 388 | #if defined(ENABLE_SESSION_SERVICE) |
[email protected] | d323a17 | 2011-09-02 18:23:02 | [diff] [blame] | 389 | create_session_service_timer_.Start(FROM_HERE, |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 390 | TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this, |
| 391 | &ProfileImpl::EnsureSessionServiceCreated); |
[email protected] | cdb756ef | 2012-04-05 18:34:53 | [diff] [blame] | 392 | #endif |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 393 | |
mlerman | 1f090b42 | 2015-01-15 16:26:18 | [diff] [blame] | 394 | set_is_guest_profile(path == ProfileManager::GetGuestProfilePath()); |
mlerman | b8df6e8 | 2015-01-23 19:55:34 | [diff] [blame] | 395 | set_is_system_profile(path == ProfileManager::GetSystemProfilePath()); |
mlerman | 1f090b42 | 2015-01-15 16:26:18 | [diff] [blame] | 396 | |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 397 | // Determine if prefetch is enabled for this profile. |
| 398 | // If not profile_manager is present, it means we are in a unittest. |
avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 399 | const base::CommandLine* command_line = |
| 400 | base::CommandLine::ForCurrentProcess(); |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 401 | predictor_ = chrome_browser_net::Predictor::CreatePredictor( |
| 402 | !command_line->HasSwitch(switches::kDisablePreconnect), |
[email protected] | 8a9712c2 | 2014-07-21 22:47:28 | [diff] [blame] | 403 | !command_line->HasSwitch(switches::kDnsPrefetchDisable), |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 404 | g_browser_process->profile_manager() == NULL); |
| 405 | |
[email protected] | d61ee87 | 2012-11-19 17:08:38 | [diff] [blame] | 406 | // 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] | d81bb3e | 2013-05-02 18:17:03 | [diff] [blame] | 409 | #if defined(ENABLE_CONFIGURATION_POLICY) |
[email protected] | eb83c39 | 2013-11-07 12:53:24 | [diff] [blame] | 410 | 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] | 42c0d5ed | 2013-04-30 17:04:45 | [diff] [blame] | 415 | #if defined(OS_CHROMEOS) |
| 416 | cloud_policy_manager_ = |
| 417 | policy::UserCloudPolicyManagerFactoryChromeOS::CreateForProfile( |
[email protected] | 6a6dd9d | 2013-10-19 18:16:59 | [diff] [blame] | 418 | this, force_immediate_policy_load, sequenced_task_runner); |
[email protected] | 42c0d5ed | 2013-04-30 17:04:45 | [diff] [blame] | 419 | #else |
| 420 | cloud_policy_manager_ = |
[email protected] | 499cb70 | 2013-11-06 14:03:05 | [diff] [blame] | 421 | policy::UserCloudPolicyManagerFactory::CreateForOriginalBrowserContext( |
[email protected] | 526cf1a4 | 2013-11-26 10:38:48 | [diff] [blame] | 422 | this, |
| 423 | force_immediate_policy_load, |
| 424 | sequenced_task_runner, |
| 425 | BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), |
| 426 | BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); |
[email protected] | 3c843b4 | 2012-12-03 16:00:16 | [diff] [blame] | 427 | #endif |
[email protected] | e4ee869 | 2013-03-25 19:05:35 | [diff] [blame] | 428 | #endif |
[email protected] | d81bb3e | 2013-05-02 18:17:03 | [diff] [blame] | 429 | profile_policy_connector_ = |
pneubeck | 91534e8 | 2015-02-18 17:37:52 | [diff] [blame] | 430 | policy::ProfilePolicyConnectorFactory::CreateForBrowserContext( |
[email protected] | 6a6dd9d | 2013-10-19 18:16:59 | [diff] [blame] | 431 | this, force_immediate_policy_load); |
[email protected] | 3b19e8e | 2012-10-17 19:15:49 | [diff] [blame] | 432 | |
[email protected] | 70a317a | 2012-12-19 20:59:33 | [diff] [blame] | 433 | DCHECK(create_mode == CREATE_MODE_ASYNCHRONOUS || |
| 434 | create_mode == CREATE_MODE_SYNCHRONOUS); |
| 435 | bool async_prefs = create_mode == CREATE_MODE_ASYNCHRONOUS; |
[email protected] | 0dbd75d | 2013-01-18 00:31:07 | [diff] [blame] | 436 | |
[email protected] | 37ca3fe0 | 2013-07-05 15:32:44 | [diff] [blame] | 437 | #if defined(OS_CHROMEOS) |
[email protected] | 1691822 | 2013-11-06 13:24:51 | [diff] [blame] | 438 | if (chromeos::ProfileHelper::IsSigninProfile(this)) |
[email protected] | 37ca3fe0 | 2013-07-05 15:32:44 | [diff] [blame] | 439 | chrome::RegisterLoginProfilePrefs(pref_registry_.get()); |
| 440 | else |
| 441 | #endif |
[email protected] | e148048 | 2013-09-11 11:49:58 | [diff] [blame] | 442 | chrome::RegisterUserProfilePrefs(pref_registry_.get()); |
| 443 | |
[email protected] | d45c5d5 | 2013-12-04 23:41:16 | [diff] [blame] | 444 | BrowserContextDependencyManager::GetInstance()-> |
| 445 | RegisterProfilePrefsForServices(this, pref_registry_.get()); |
| 446 | |
knn | 95221ffe | 2015-03-04 20:42:43 | [diff] [blame] | 447 | SupervisedUserSettingsService* supervised_user_settings = nullptr; |
treib | 87bb89cbb | 2014-12-01 16:01:47 | [diff] [blame] | 448 | #if defined(ENABLE_SUPERVISED_USERS) |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 449 | supervised_user_settings = |
| 450 | SupervisedUserSettingsServiceFactory::GetForProfile(this); |
| 451 | supervised_user_settings->Init( |
[email protected] | e148048 | 2013-09-11 11:49:58 | [diff] [blame] | 452 | path_, sequenced_task_runner, create_mode == CREATE_MODE_SYNCHRONOUS); |
| 453 | #endif |
[email protected] | 5879cef | 2013-03-02 17:02:25 | [diff] [blame] | 454 | |
[email protected] | 0823c68d | 2014-06-13 22:23:47 | [diff] [blame] | 455 | scoped_refptr<SafeBrowsingService> safe_browsing_service( |
| 456 | g_browser_process->safe_browsing_service()); |
dcheng | f3cfb1d | 2014-08-26 20:25:59 | [diff] [blame] | 457 | if (safe_browsing_service.get()) { |
[email protected] | 0823c68d | 2014-06-13 22:23:47 | [diff] [blame] | 458 | pref_validation_delegate_ = |
[email protected] | 91081cf | 2014-06-19 13:56:20 | [diff] [blame] | 459 | safe_browsing_service->CreatePreferenceValidationDelegate(this).Pass(); |
[email protected] | 0823c68d | 2014-06-13 22:23:47 | [diff] [blame] | 460 | } |
| 461 | |
[email protected] | 0dbd75d | 2013-01-18 00:31:07 | [diff] [blame] | 462 | { |
[email protected] | e90a01f | 2013-11-19 04:22:12 | [diff] [blame] | 463 | prefs_ = chrome_prefs::CreateProfilePrefs( |
[email protected] | d9413a3e | 2014-02-05 21:47:56 | [diff] [blame] | 464 | path_, |
[email protected] | 0dbd75d | 2013-01-18 00:31:07 | [diff] [blame] | 465 | sequenced_task_runner, |
[email protected] | 086dfcb | 2014-05-26 23:43:03 | [diff] [blame] | 466 | pref_validation_delegate_.get(), |
[email protected] | d81bb3e | 2013-05-02 18:17:03 | [diff] [blame] | 467 | profile_policy_connector_->policy_service(), |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 468 | supervised_user_settings, |
[email protected] | dfc0424c | 2014-07-25 21:33:20 | [diff] [blame] | 469 | CreateExtensionPrefStore(this, false), |
[email protected] | c753f14 | 2013-02-10 13:14:04 | [diff] [blame] | 470 | pref_registry_, |
[email protected] | e90a01f | 2013-11-19 04:22:12 | [diff] [blame] | 471 | async_prefs).Pass(); |
[email protected] | 75fee37 | 2013-03-06 00:42:44 | [diff] [blame] | 472 | // Register on BrowserContext. |
[email protected] | c7141feb | 2013-06-11 13:00:16 | [diff] [blame] | 473 | user_prefs::UserPrefs::Set(this, prefs_.get()); |
[email protected] | 0dbd75d | 2013-01-18 00:31:07 | [diff] [blame] | 474 | } |
| 475 | |
[email protected] | 70a317a | 2012-12-19 20:59:33 | [diff] [blame] | 476 | if (async_prefs) { |
[email protected] | a6a7ced | 2012-11-01 17:24:18 | [diff] [blame] | 477 | // 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. |
alemate | f0673029 | 2015-05-12 21:36:07 | [diff] [blame] | 481 | prefs_->AddPrefInitObserver(base::Bind( |
| 482 | &ProfileImpl::OnPrefsLoaded, base::Unretained(this), create_mode)); |
[email protected] | 00b33f80 | 2012-03-13 07:46:03 | [diff] [blame] | 483 | } else { |
[email protected] | 70a317a | 2012-12-19 20:59:33 | [diff] [blame] | 484 | // Prefs were loaded synchronously so we can continue directly. |
alemate | f0673029 | 2015-05-12 21:36:07 | [diff] [blame] | 485 | OnPrefsLoaded(create_mode, true); |
[email protected] | 844a100 | 2011-04-19 11:37:21 | [diff] [blame] | 486 | } |
| 487 | } |
| 488 | |
[email protected] | 88c6fb5 | 2013-04-09 10:39:18 | [diff] [blame] | 489 | void ProfileImpl::DoFinalInit() { |
[email protected] | acd431e | 2013-05-31 13:34:49 | [diff] [blame] | 490 | TRACE_EVENT0("browser", "ProfileImpl::DoFinalInit") |
rkaplow | 3e2016b | 2015-04-02 17:04:00 | [diff] [blame] | 491 | SCOPED_UMA_HISTOGRAM_TIMER("Profile.ProfileImplDoFinalInit"); |
| 492 | |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 493 | PrefService* prefs = GetPrefs(); |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 494 | pref_change_registrar_.Init(prefs); |
[email protected] | 116129e0 | 2012-11-21 17:26:27 | [diff] [blame] | 495 | pref_change_registrar_.Add( |
[email protected] | d20d043 | 2014-06-12 17:14:05 | [diff] [blame] | 496 | prefs::kSupervisedUserId, |
| 497 | base::Bind(&ProfileImpl::UpdateProfileSupervisedUserIdCache, |
[email protected] | 6ebd60c | 2014-04-28 23:45:20 | [diff] [blame] | 498 | base::Unretained(this))); |
[email protected] | 1cdf093 | 2014-08-16 06:00:49 | [diff] [blame] | 499 | |
| 500 | // Changes in the profile avatar. |
[email protected] | 116129e0 | 2012-11-21 17:26:27 | [diff] [blame] | 501 | pref_change_registrar_.Add( |
| 502 | prefs::kProfileAvatarIndex, |
| 503 | base::Bind(&ProfileImpl::UpdateProfileAvatarCache, |
| 504 | base::Unretained(this))); |
| 505 | pref_change_registrar_.Add( |
[email protected] | 1cdf093 | 2014-08-16 06:00:49 | [diff] [blame] | 506 | 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] | 116129e0 | 2012-11-21 17:26:27 | [diff] [blame] | 520 | prefs::kProfileName, |
| 521 | base::Bind(&ProfileImpl::UpdateProfileNameCache, |
| 522 | base::Unretained(this))); |
[email protected] | 1cdf093 | 2014-08-16 06:00:49 | [diff] [blame] | 523 | |
[email protected] | 8d9243a | 2013-10-21 17:11:48 | [diff] [blame] | 524 | pref_change_registrar_.Add( |
| 525 | prefs::kForceEphemeralProfiles, |
| 526 | base::Bind(&ProfileImpl::UpdateProfileIsEphemeralCache, |
| 527 | base::Unretained(this))); |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 528 | |
[email protected] | b411da3 | 2010-11-24 02:23:15 | [diff] [blame] | 529 | // 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] | 00b33f80 | 2012-03-13 07:46:03 | [diff] [blame] | 533 | // Always create the cache directory asynchronously. |
[email protected] | 0de615a | 2012-11-08 04:40:59 | [diff] [blame] | 534 | scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner = |
| 535 | JsonPrefStore::GetTaskRunnerForFile(base_cache_path_, |
| 536 | BrowserThread::GetBlockingPool()); |
calamity | f4f08cfe | 2015-06-17 02:39:02 | [diff] [blame] | 537 | CreateProfileDirectory(sequenced_task_runner.get(), base_cache_path_, false); |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 538 | |
rogerta | 614597db | 2014-12-05 17:57:32 | [diff] [blame] | 539 | // Initialize components that depend on the current value. |
[email protected] | d20d043 | 2014-06-12 17:14:05 | [diff] [blame] | 540 | UpdateProfileSupervisedUserIdCache(); |
[email protected] | a02c4ef | 2013-11-06 20:30:11 | [diff] [blame] | 541 | UpdateProfileIsEphemeralCache(); |
[email protected] | 933b3f6 | 2013-01-03 20:44:21 | [diff] [blame] | 542 | GAIAInfoUpdateServiceFactory::GetForProfile(this); |
[email protected] | c337d1b7 | 2012-01-13 04:40:24 | [diff] [blame] | 543 | |
[email protected] | 81ad7f4a | 2011-03-16 01:33:29 | [diff] [blame] | 544 | PrefService* local_state = g_browser_process->local_state(); |
[email protected] | 182fe2f | 2011-02-14 20:35:15 | [diff] [blame] | 545 | ssl_config_service_manager_.reset( |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 546 | SSLConfigServiceManager::CreateDefaultManager(local_state)); |
[email protected] | 182fe2f | 2011-02-14 20:35:15 | [diff] [blame] | 547 | |
thestig | e415584 | 2014-10-20 18:58:02 | [diff] [blame] | 548 | #if defined(ENABLE_BACKGROUND) |
[email protected] | 4c793f0 | 2010-08-18 20:55:45 | [diff] [blame] | 549 | // 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] | 120655d | 2011-09-16 22:10:32 | [diff] [blame] | 552 | // 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) |
avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 556 | if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 557 | switches::kKeepAliveForTest)) |
[email protected] | 120655d | 2011-09-16 22:10:32 | [diff] [blame] | 558 | init_background_mode_manager = false; |
[email protected] | 4c793f0 | 2010-08-18 20:55:45 | [diff] [blame] | 559 | #endif |
[email protected] | 120655d | 2011-09-16 22:10:32 | [diff] [blame] | 560 | if (init_background_mode_manager) { |
| 561 | if (g_browser_process->background_mode_manager()) |
| 562 | g_browser_process->background_mode_manager()->RegisterProfile(this); |
| 563 | } |
thestig | e415584 | 2014-10-20 18:58:02 | [diff] [blame] | 564 | #endif // defined(ENABLE_BACKGROUND) |
[email protected] | 4c793f0 | 2010-08-18 20:55:45 | [diff] [blame] | 565 | |
[email protected] | 33ad6ce9 | 2013-08-27 14:39:08 | [diff] [blame] | 566 | base::FilePath cookie_path = GetPath(); |
| 567 | cookie_path = cookie_path.Append(chrome::kCookieFilename); |
[email protected] | 6b8a3c74 | 2014-07-25 00:25:35 | [diff] [blame] | 568 | base::FilePath channel_id_path = GetPath(); |
| 569 | channel_id_path = channel_id_path.Append(chrome::kChannelIDFilename); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 570 | base::FilePath cache_path = base_cache_path_; |
[email protected] | f6c21cb | 2011-02-16 19:45:41 | [diff] [blame] | 571 | int cache_max_size; |
[email protected] | f2df311 | 2011-11-18 10:21:48 | [diff] [blame] | 572 | GetCacheParameters(false, &cache_path, &cache_max_size); |
[email protected] | f6c21cb | 2011-02-16 19:45:41 | [diff] [blame] | 573 | cache_path = GetCachePath(cache_path); |
| 574 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 575 | base::FilePath media_cache_path = base_cache_path_; |
[email protected] | f6c21cb | 2011-02-16 19:45:41 | [diff] [blame] | 576 | int media_cache_max_size; |
[email protected] | f2df311 | 2011-11-18 10:21:48 | [diff] [blame] | 577 | GetCacheParameters(true, &media_cache_path, &media_cache_max_size); |
[email protected] | f6c21cb | 2011-02-16 19:45:41 | [diff] [blame] | 578 | media_cache_path = GetMediaCachePath(media_cache_path); |
| 579 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 580 | base::FilePath extensions_cookie_path = GetPath(); |
[email protected] | f6c21cb | 2011-02-16 19:45:41 | [diff] [blame] | 581 | extensions_cookie_path = |
| 582 | extensions_cookie_path.Append(chrome::kExtensionsCookieFilename); |
| 583 | |
[email protected] | 33ad6ce9 | 2013-08-27 14:39:08 | [diff] [blame] | 584 | #if defined(OS_ANDROID) |
| 585 | SessionStartupPref::Type startup_pref_type = |
| 586 | SessionStartupPref::GetDefaultStartupType(); |
| 587 | #else |
| 588 | SessionStartupPref::Type startup_pref_type = |
| 589 | StartupBrowserCreator::GetSessionStartupPref( |
avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 590 | *base::CommandLine::ForCurrentProcess(), this).type; |
[email protected] | 33ad6ce9 | 2013-08-27 14:39:08 | [diff] [blame] | 591 | #endif |
[email protected] | 9a6c2aa | 2014-01-11 22:39:39 | [diff] [blame] | 592 | 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] | 33ad6ce9 | 2013-08-27 14:39:08 | [diff] [blame] | 598 | |
[email protected] | f6c21cb | 2011-02-16 19:45:41 | [diff] [blame] | 599 | // Make sure we initialize the ProfileIOData after everything else has been |
| 600 | // initialized that we might be reading from the IO thread. |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 601 | |
[email protected] | 6b8a3c74 | 2014-07-25 00:25:35 | [diff] [blame] | 602 | io_data_.Init(cookie_path, channel_id_path, cache_path, |
[email protected] | 273e37d | 2011-08-11 01:49:12 | [diff] [blame] | 603 | cache_max_size, media_cache_path, media_cache_max_size, |
isherman | 292673a | 2015-03-31 22:04:29 | [diff] [blame] | 604 | extensions_cookie_path, GetPath(), predictor_, |
| 605 | session_cookie_mode, GetSpecialStoragePolicy(), |
bengr | 9463b577 | 2015-01-24 00:24:54 | [diff] [blame] | 606 | CreateDomainReliabilityMonitor(local_state)); |
[email protected] | f6c21cb | 2011-02-16 19:45:41 | [diff] [blame] | 607 | |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 608 | #if defined(ENABLE_PLUGINS) |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 609 | ChromePluginServiceFilter::GetInstance()->RegisterResourceContext( |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 610 | PluginPrefs::GetForProfile(this).get(), |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 611 | io_data_.GetResourceContextNoInit()); |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 612 | #endif |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 613 | |
[email protected] | 12360b5 | 2014-03-07 19:31:52 | [diff] [blame] | 614 | TRACE_EVENT0("browser", "ProfileImpl::SetSaveSessionStorageOnDisk"); |
| 615 | content::BrowserContext::GetDefaultStoragePartition(this)-> |
| 616 | GetDOMStorageContext()->SetSaveSessionStorageOnDisk(); |
[email protected] | 039124e | 2012-08-17 00:22:26 | [diff] [blame] | 617 | |
wjmaclean | caa7d6d | 2014-11-12 16:42:11 | [diff] [blame] | 618 | // TODO(wjmaclean): Remove this. crbug.com/420643 |
| 619 | chrome::MigrateProfileZoomLevelPrefs(this); |
| 620 | |
[email protected] | 7e856dde | 2014-03-15 00:34:05 | [diff] [blame] | 621 | // The DomDistillerViewerSource is not a normal WebUI so it must be registered |
| 622 | // as a URLDataSource early. |
| 623 | RegisterDomDistillerViewerSource(this); |
| 624 | |
[email protected] | afe1099 | 2014-06-26 17:48:07 | [diff] [blame] | 625 | #if defined(OS_CHROMEOS) |
nkostylev | 4d2391a | 2014-11-14 16:15:04 | [diff] [blame] | 626 | if (chromeos::UserSessionManager::GetInstance() |
| 627 | ->RestartToApplyPerSessionFlagsIfNeed(this, true)) { |
[email protected] | afe1099 | 2014-06-26 17:48:07 | [diff] [blame] | 628 | return; |
| 629 | } |
| 630 | #endif |
| 631 | |
[email protected] | acd431e | 2013-05-31 13:34:49 | [diff] [blame] | 632 | if (delegate_) { |
| 633 | TRACE_EVENT0("browser", "ProfileImpl::DoFileInit:DelegateOnProfileCreated") |
[email protected] | 88c6fb5 | 2013-04-09 10:39:18 | [diff] [blame] | 634 | delegate_->OnProfileCreated(this, true, IsNewProfile()); |
[email protected] | acd431e | 2013-05-31 13:34:49 | [diff] [blame] | 635 | } |
[email protected] | 12463cd | 2011-07-19 09:40:20 | [diff] [blame] | 636 | |
rkaplow | 3e2016b | 2015-04-02 17:04:00 | [diff] [blame] | 637 | { |
| 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] | 68b9351 | 2013-02-08 18:17:57 | [diff] [blame] | 644 | #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] | 2f8f25d | 2013-07-26 10:30:00 | [diff] [blame] | 647 | BookmarkModel* model = BookmarkModelFactory::GetForProfile(this); |
| 648 | model->AddObserver(new BookmarkModelLoadedObserver(this)); |
[email protected] | 68b9351 | 2013-02-08 18:17:57 | [diff] [blame] | 649 | #endif |
[email protected] | b717626 | 2014-06-18 15:26:29 | [diff] [blame] | 650 | |
b.kelemen | 4596b51 | 2015-03-04 18:42:47 | [diff] [blame] | 651 | PushMessagingServiceImpl::InitializeForProfile(this); |
[email protected] | 9086ce5a | 2014-08-14 15:15:04 | [diff] [blame] | 652 | |
| 653 | #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) && !defined(OS_IOS) |
| 654 | signin_ui_util::InitializePrefsForProfile(this); |
| 655 | #endif |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 656 | } |
| 657 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 658 | base::FilePath ProfileImpl::last_selected_directory() { |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 659 | return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory); |
| 660 | } |
| 661 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 662 | void ProfileImpl::set_last_selected_directory(const base::FilePath& path) { |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 663 | GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path); |
| 664 | } |
| 665 | |
| 666 | ProfileImpl::~ProfileImpl() { |
[email protected] | a7c4c03 | 2012-07-27 00:36:32 | [diff] [blame] | 667 | MaybeSendDestroyedNotification(); |
| 668 | |
[email protected] | 38b9994 | 2012-04-20 10:44:27 | [diff] [blame] | 669 | bool prefs_loaded = prefs_->GetInitializationStatus() != |
| 670 | PrefService::INITIALIZATION_STATUS_WAITING; |
[email protected] | 0061771 | 2011-07-22 10:21:06 | [diff] [blame] | 671 | |
[email protected] | cdb756ef | 2012-04-05 18:34:53 | [diff] [blame] | 672 | #if defined(ENABLE_SESSION_SERVICE) |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 673 | StopCreateSessionServiceTimer(); |
[email protected] | cdb756ef | 2012-04-05 18:34:53 | [diff] [blame] | 674 | #endif |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 675 | |
[email protected] | 60100b2 | 2011-06-29 23:37:25 | [diff] [blame] | 676 | // Remove pref observers |
| 677 | pref_change_registrar_.RemoveAll(); |
| 678 | |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 679 | #if defined(ENABLE_PLUGINS) |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 680 | ChromePluginServiceFilter::GetInstance()->UnregisterResourceContext( |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 681 | io_data_.GetResourceContextNoInit()); |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 682 | #endif |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 683 | |
[email protected] | d3a9bfc | 2012-02-07 22:52:47 | [diff] [blame] | 684 | // Destroy OTR profile and its profile services first. |
[email protected] | 9332a3f7 | 2013-05-07 06:33:52 | [diff] [blame] | 685 | if (off_the_record_profile_) { |
[email protected] | 10ce4cf | 2012-06-26 20:09:16 | [diff] [blame] | 686 | ProfileDestroyer::DestroyOffTheRecordProfileNow( |
| 687 | off_the_record_profile_.get()); |
| 688 | } else { |
[email protected] | dfc0424c | 2014-07-25 21:33:20 | [diff] [blame] | 689 | #if defined(ENABLE_EXTENSIONS) |
[email protected] | 7595f1c8 | 2013-10-23 14:09:56 | [diff] [blame] | 690 | ExtensionPrefValueMapFactory::GetForBrowserContext(this)-> |
[email protected] | 10ce4cf | 2012-06-26 20:09:16 | [diff] [blame] | 691 | ClearAllIncognitoSessionOnlyPreferences(); |
[email protected] | dfc0424c | 2014-07-25 21:33:20 | [diff] [blame] | 692 | #endif |
[email protected] | 10ce4cf | 2012-06-26 20:09:16 | [diff] [blame] | 693 | } |
[email protected] | d3a9bfc | 2012-02-07 22:52:47 | [diff] [blame] | 694 | |
[email protected] | f1484c5 | 2013-05-22 23:25:44 | [diff] [blame] | 695 | BrowserContextDependencyManager::GetInstance()->DestroyBrowserContextServices( |
| 696 | this); |
[email protected] | 5cdcd15 | 2011-03-31 22:48:52 | [diff] [blame] | 697 | |
[email protected] | 9332a3f7 | 2013-05-07 06:33:52 | [diff] [blame] | 698 | if (pref_proxy_config_tracker_) |
[email protected] | cc5bfd4 | 2010-11-24 14:44:02 | [diff] [blame] | 699 | pref_proxy_config_tracker_->DetachFromPrefService(); |
| 700 | |
[email protected] | 5173de8b | 2013-06-02 21:16:02 | [diff] [blame] | 701 | if (host_content_settings_map_.get()) |
[email protected] | 24ff5ca | 2011-07-06 14:21:44 | [diff] [blame] | 702 | host_content_settings_map_->ShutdownOnUIThread(); |
| 703 | |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 704 | // This causes the Preferences file to be written to disk. |
[email protected] | 38b9994 | 2012-04-20 10:44:27 | [diff] [blame] | 705 | if (prefs_loaded) |
[email protected] | 6c0ca7fc | 2012-10-05 16:27:22 | [diff] [blame] | 706 | SetExitType(EXIT_NORMAL); |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 707 | } |
| 708 | |
isherman | 91ffd8b | 2015-02-19 08:51:32 | [diff] [blame] | 709 | std::string ProfileImpl::GetProfileUserName() const { |
| 710 | const SigninManagerBase* signin_manager = |
| 711 | SigninManagerFactory::GetForProfileIfExists(this); |
rogerta | 614597db | 2014-12-05 17:57:32 | [diff] [blame] | 712 | if (signin_manager) |
| 713 | return signin_manager->GetAuthenticatedUsername(); |
| 714 | |
| 715 | return std::string(); |
[email protected] | 29d7025 | 2011-04-28 02:16:58 | [diff] [blame] | 716 | } |
| 717 | |
[email protected] | 7b7e0b3 | 2014-03-17 16:09:23 | [diff] [blame] | 718 | Profile::ProfileType ProfileImpl::GetProfileType() const { |
| 719 | return REGULAR_PROFILE; |
| 720 | } |
| 721 | |
wjmaclean | caa7d6d | 2014-11-12 16:42:11 | [diff] [blame] | 722 | scoped_ptr<content::ZoomLevelDelegate> |
| 723 | ProfileImpl::CreateZoomLevelDelegate(const base::FilePath& partition_path) { |
wjmaclean | 2c98cb19 | 2014-11-26 19:55:27 | [diff] [blame] | 724 | return make_scoped_ptr(new chrome::ChromeZoomLevelPrefs( |
| 725 | GetPrefs(), GetPath(), partition_path, |
wjmaclean | 7f63c6b | 2014-12-09 14:59:55 | [diff] [blame] | 726 | ui_zoom::ZoomEventManager::GetForBrowserContext(this)->GetWeakPtr())); |
wjmaclean | caa7d6d | 2014-11-12 16:42:11 | [diff] [blame] | 727 | } |
| 728 | |
[email protected] | 4251165a | 2013-07-17 04:33:40 | [diff] [blame] | 729 | base::FilePath ProfileImpl::GetPath() const { |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 730 | return path_; |
| 731 | } |
| 732 | |
[email protected] | 0de615a | 2012-11-08 04:40:59 | [diff] [blame] | 733 | scoped_refptr<base::SequencedTaskRunner> ProfileImpl::GetIOTaskRunner() { |
| 734 | return JsonPrefStore::GetTaskRunnerForFile( |
| 735 | GetPath(), BrowserThread::GetBlockingPool()); |
| 736 | } |
| 737 | |
[email protected] | 33ad6ce9 | 2013-08-27 14:39:08 | [diff] [blame] | 738 | bool ProfileImpl::IsOffTheRecord() const { |
| 739 | return false; |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | Profile* ProfileImpl::GetOffTheRecordProfile() { |
[email protected] | 9332a3f7 | 2013-05-07 06:33:52 | [diff] [blame] | 743 | if (!off_the_record_profile_) { |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 744 | scoped_ptr<Profile> p(CreateOffTheRecordProfile()); |
| 745 | off_the_record_profile_.swap(p); |
[email protected] | 06e29a9 | 2010-10-13 22:43:26 | [diff] [blame] | 746 | |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 747 | content::NotificationService::current()->Notify( |
[email protected] | 12463cd | 2011-07-19 09:40:20 | [diff] [blame] | 748 | chrome::NOTIFICATION_PROFILE_CREATED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 749 | content::Source<Profile>(off_the_record_profile_.get()), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 750 | content::NotificationService::NoDetails()); |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 751 | } |
| 752 | return off_the_record_profile_.get(); |
| 753 | } |
| 754 | |
| 755 | void ProfileImpl::DestroyOffTheRecordProfile() { |
| 756 | off_the_record_profile_.reset(); |
[email protected] | dfc0424c | 2014-07-25 21:33:20 | [diff] [blame] | 757 | #if defined(ENABLE_EXTENSIONS) |
[email protected] | 7595f1c8 | 2013-10-23 14:09:56 | [diff] [blame] | 758 | ExtensionPrefValueMapFactory::GetForBrowserContext(this)-> |
[email protected] | ef9bba1 | 2012-04-06 16:26:09 | [diff] [blame] | 759 | ClearAllIncognitoSessionOnlyPreferences(); |
[email protected] | dfc0424c | 2014-07-25 21:33:20 | [diff] [blame] | 760 | #endif |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | bool ProfileImpl::HasOffTheRecordProfile() { |
| 764 | return off_the_record_profile_.get() != NULL; |
| 765 | } |
| 766 | |
| 767 | Profile* ProfileImpl::GetOriginalProfile() { |
| 768 | return this; |
| 769 | } |
| 770 | |
treib | 2f1cbb4 | 2015-08-06 12:33:10 | [diff] [blame] | 771 | bool ProfileImpl::IsSupervised() const { |
[email protected] | d20d043 | 2014-06-12 17:14:05 | [diff] [blame] | 772 | return !GetPrefs()->GetString(prefs::kSupervisedUserId).empty(); |
[email protected] | e000daf | 2013-07-31 16:50:58 | [diff] [blame] | 773 | } |
| 774 | |
treib | 2f1cbb4 | 2015-08-06 12:33:10 | [diff] [blame] | 775 | bool ProfileImpl::IsChild() const { |
treib | 3c8cf13 | 2014-12-08 15:09:32 | [diff] [blame] | 776 | #if defined(ENABLE_SUPERVISED_USERS) |
| 777 | return GetPrefs()->GetString(prefs::kSupervisedUserId) == |
| 778 | supervised_users::kChildAccountSUID; |
merkulova | e19a352 | 2014-12-04 11:14:06 | [diff] [blame] | 779 | #else |
| 780 | return false; |
| 781 | #endif |
| 782 | } |
| 783 | |
treib | 2f1cbb4 | 2015-08-06 12:33:10 | [diff] [blame] | 784 | bool ProfileImpl::IsLegacySupervised() const { |
treib | 3c8cf13 | 2014-12-08 15:09:32 | [diff] [blame] | 785 | return IsSupervised() && !IsChild(); |
| 786 | } |
| 787 | |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 788 | ExtensionSpecialStoragePolicy* |
| 789 | ProfileImpl::GetExtensionSpecialStoragePolicy() { |
[email protected] | dfc0424c | 2014-07-25 21:33:20 | [diff] [blame] | 790 | #if defined(ENABLE_EXTENSIONS) |
[email protected] | 5173de8b | 2013-06-02 21:16:02 | [diff] [blame] | 791 | if (!extension_special_storage_policy_.get()) { |
[email protected] | acd431e | 2013-05-31 13:34:49 | [diff] [blame] | 792 | TRACE_EVENT0("browser", "ProfileImpl::GetExtensionSpecialStoragePolicy") |
[email protected] | 67e7999 | 2012-02-13 20:47:58 | [diff] [blame] | 793 | extension_special_storage_policy_ = new ExtensionSpecialStoragePolicy( |
droger | b171697 | 2015-06-30 09:04:09 | [diff] [blame] | 794 | CookieSettingsFactory::GetForProfile(this).get()); |
[email protected] | 7c5048c | 2011-08-19 17:07:05 | [diff] [blame] | 795 | } |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 796 | return extension_special_storage_policy_.get(); |
[email protected] | dfc0424c | 2014-07-25 21:33:20 | [diff] [blame] | 797 | #else |
| 798 | return NULL; |
| 799 | #endif |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 800 | } |
| 801 | |
alemate | f0673029 | 2015-05-12 21:36:07 | [diff] [blame] | 802 | void ProfileImpl::OnLocaleReady() { |
| 803 | TRACE_EVENT0("browser", "ProfileImpl::OnLocaleReady"); |
| 804 | SCOPED_UMA_HISTOGRAM_TIMER("Profile.OnLocaleReadyTime"); |
rkaplow | f216caf | 2015-03-02 22:37:45 | [diff] [blame] | 805 | // Migrate obsolete prefs. |
[email protected] | 665fa01 | 2012-05-09 00:24:38 | [diff] [blame] | 806 | if (g_browser_process->local_state()) |
rkaplow | f216caf | 2015-03-02 22:37:45 | [diff] [blame] | 807 | chrome::MigrateObsoleteBrowserPrefs(this, g_browser_process->local_state()); |
| 808 | chrome::MigrateObsoleteProfilePrefs(this); |
[email protected] | 844a100 | 2011-04-19 11:37:21 | [diff] [blame] | 809 | |
[email protected] | 6c0ca7fc | 2012-10-05 16:27:22 | [diff] [blame] | 810 | // |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] | 844a100 | 2011-04-19 11:37:21 | [diff] [blame] | 822 | // Mark the session as open. |
[email protected] | 6c0ca7fc | 2012-10-05 16:27:22 | [diff] [blame] | 823 | 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] | 844a100 | 2011-04-19 11:37:21 | [diff] [blame] | 827 | |
nparker | b2cd5ee | 2015-05-13 01:12:01 | [diff] [blame] | 828 | #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] | 16a6718 | 2014-06-16 16:13:25 | [diff] [blame] | 832 | #endif |
| 833 | |
[email protected] | 371662e37 | 2013-10-17 22:05:22 | [diff] [blame] | 834 | g_browser_process->profile_manager()->InitProfileUserPrefs(this); |
| 835 | |
rkaplow | 3e2016b | 2015-04-02 17:04:00 | [diff] [blame] | 836 | { |
| 837 | SCOPED_UMA_HISTOGRAM_TIMER("Profile.CreateBrowserContextServicesTime"); |
| 838 | BrowserContextDependencyManager::GetInstance()-> |
| 839 | CreateBrowserContextServices(this); |
| 840 | } |
[email protected] | 6802a825f | 2012-01-21 01:29:33 | [diff] [blame] | 841 | |
[email protected] | 9332a3f7 | 2013-05-07 06:33:52 | [diff] [blame] | 842 | DCHECK(!net_pref_observer_); |
[email protected] | acd431e | 2013-05-31 13:34:49 | [diff] [blame] | 843 | { |
| 844 | TRACE_EVENT0("browser", "ProfileImpl::OnPrefsLoaded:NetPrefObserver") |
bnc | 2551612c | 2014-09-04 00:48:32 | [diff] [blame] | 845 | net_pref_observer_.reset(new NetPrefObserver(prefs_.get())); |
[email protected] | acd431e | 2013-05-31 13:34:49 | [diff] [blame] | 846 | } |
[email protected] | 844a100 | 2011-04-19 11:37:21 | [diff] [blame] | 847 | |
[email protected] | d9413a3e | 2014-02-05 21:47:56 | [diff] [blame] | 848 | chrome_prefs::SchedulePrefsFilePathVerification(path_); |
[email protected] | d8838c0 | 2013-09-20 17:14:20 | [diff] [blame] | 849 | |
[email protected] | 88c6fb5 | 2013-04-09 10:39:18 | [diff] [blame] | 850 | ChromeVersionService::OnProfileLoaded(prefs_.get(), IsNewProfile()); |
| 851 | DoFinalInit(); |
[email protected] | 844a100 | 2011-04-19 11:37:21 | [diff] [blame] | 852 | } |
| 853 | |
alemate | f0673029 | 2015-05-12 21:36:07 | [diff] [blame] | 854 | void 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] | 1bee6ed | 2012-03-14 06:46:36 | [diff] [blame] | 876 | bool ProfileImpl::WasCreatedByVersionOrLater(const std::string& version) { |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 877 | Version profile_version(ChromeVersionService::GetVersion(prefs_.get())); |
| 878 | Version arg_version(version); |
[email protected] | 1bee6ed | 2012-03-14 06:46:36 | [diff] [blame] | 879 | return (profile_version.CompareTo(arg_version) >= 0); |
| 880 | } |
| 881 | |
[email protected] | 6c0ca7fc | 2012-10-05 16:27:22 | [diff] [blame] | 882 | void ProfileImpl::SetExitType(ExitType exit_type) { |
[email protected] | 1101dbc5 | 2013-10-05 00:19:12 | [diff] [blame] | 883 | #if defined(OS_CHROMEOS) |
[email protected] | 1691822 | 2013-11-06 13:24:51 | [diff] [blame] | 884 | if (chromeos::ProfileHelper::IsSigninProfile(this)) |
[email protected] | 1101dbc5 | 2013-10-05 00:19:12 | [diff] [blame] | 885 | return; |
| 886 | #endif |
[email protected] | df70a528 | 2012-10-26 19:29:33 | [diff] [blame] | 887 | 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] | 6c0ca7fc | 2012-10-05 16:27:22 | [diff] [blame] | 895 | prefs_->SetString(prefs::kSessionExitType, |
| 896 | ExitTypeToSessionTypePrefValue(exit_type)); |
[email protected] | 6c0ca7fc | 2012-10-05 16:27:22 | [diff] [blame] | 897 | } |
| 898 | } |
| 899 | |
| 900 | Profile::ExitType ProfileImpl::GetLastSessionExitType() { |
[email protected] | 2ca1ea66 | 2012-10-04 02:26:36 | [diff] [blame] | 901 | // 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] | 6c0ca7fc | 2012-10-05 16:27:22 | [diff] [blame] | 904 | return last_session_exit_type_; |
[email protected] | 2ca1ea66 | 2012-10-04 02:26:36 | [diff] [blame] | 905 | } |
| 906 | |
[email protected] | c753f14 | 2013-02-10 13:14:04 | [diff] [blame] | 907 | PrefService* ProfileImpl::GetPrefs() { |
isherman | 91ffd8b | 2015-02-19 08:51:32 | [diff] [blame] | 908 | return const_cast<PrefService*>( |
| 909 | static_cast<const ProfileImpl*>(this)->GetPrefs()); |
| 910 | } |
| 911 | |
| 912 | const PrefService* ProfileImpl::GetPrefs() const { |
[email protected] | 9332a3f7 | 2013-05-07 06:33:52 | [diff] [blame] | 913 | DCHECK(prefs_); // Should explicitly be initialized. |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 914 | return prefs_.get(); |
| 915 | } |
| 916 | |
wjmaclean | e530aa74 | 2014-10-14 21:43:30 | [diff] [blame] | 917 | chrome::ChromeZoomLevelPrefs* ProfileImpl::GetZoomLevelPrefs() { |
wjmaclean | caa7d6d | 2014-11-12 16:42:11 | [diff] [blame] | 918 | return static_cast<chrome::ChromeZoomLevelPrefs*>( |
| 919 | GetDefaultStoragePartition(this)->GetZoomLevelDelegate()); |
wjmaclean | e530aa74 | 2014-10-14 21:43:30 | [diff] [blame] | 920 | } |
| 921 | |
[email protected] | c753f14 | 2013-02-10 13:14:04 | [diff] [blame] | 922 | PrefService* ProfileImpl::GetOffTheRecordPrefs() { |
[email protected] | 9332a3f7 | 2013-05-07 06:33:52 | [diff] [blame] | 923 | DCHECK(prefs_); |
| 924 | if (!otr_prefs_) { |
[email protected] | ca75998 | 2011-02-04 15:17:40 | [diff] [blame] | 925 | // The new ExtensionPrefStore is ref_counted and the new PrefService |
| 926 | // stores a reference so that we do not leak memory here. |
[email protected] | c753f14 | 2013-02-10 13:14:04 | [diff] [blame] | 927 | otr_prefs_.reset(prefs_->CreateIncognitoPrefService( |
[email protected] | dfc0424c | 2014-07-25 21:33:20 | [diff] [blame] | 928 | CreateExtensionPrefStore(this, true))); |
[email protected] | ca75998 | 2011-02-04 15:17:40 | [diff] [blame] | 929 | } |
| 930 | return otr_prefs_.get(); |
| 931 | } |
| 932 | |
[email protected] | 6bd3007 | 2013-02-08 18:17:11 | [diff] [blame] | 933 | net::URLRequestContextGetter* ProfileImpl::CreateRequestContext( |
[email protected] | 7571263c | 2014-03-10 22:57:09 | [diff] [blame] | 934 | content::ProtocolHandlerMap* protocol_handlers, |
[email protected] | 3b90aab | 2014-05-30 17:56:15 | [diff] [blame] | 935 | content::URLRequestInterceptorScopedVector request_interceptors) { |
[email protected] | 7571263c | 2014-03-10 22:57:09 | [diff] [blame] | 936 | return io_data_.CreateMainRequestContextGetter( |
| 937 | protocol_handlers, |
[email protected] | 3b90aab | 2014-05-30 17:56:15 | [diff] [blame] | 938 | request_interceptors.Pass(), |
[email protected] | 7571263c | 2014-03-10 22:57:09 | [diff] [blame] | 939 | g_browser_process->local_state(), |
| 940 | g_browser_process->io_thread()).get(); |
[email protected] | 6bd3007 | 2013-02-08 18:17:11 | [diff] [blame] | 941 | } |
| 942 | |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 943 | net::URLRequestContextGetter* ProfileImpl::GetRequestContext() { |
[email protected] | 6bd3007 | 2013-02-08 18:17:11 | [diff] [blame] | 944 | return GetDefaultStoragePartition(this)->GetURLRequestContext(); |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 945 | } |
| 946 | |
[email protected] | da5683db | 2011-04-23 17:12:21 | [diff] [blame] | 947 | net::URLRequestContextGetter* ProfileImpl::GetRequestContextForRenderProcess( |
| 948 | int renderer_child_id) { |
[email protected] | fb29e6cf | 2012-07-12 21:27:20 | [diff] [blame] | 949 | content::RenderProcessHost* rph = content::RenderProcessHost::FromID( |
| 950 | renderer_child_id); |
[email protected] | 27ddfed2 | 2012-10-30 23:22:43 | [diff] [blame] | 951 | |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 952 | return rph->GetStoragePartition()->GetURLRequestContext(); |
[email protected] | d969667 | 2011-03-15 22:45:09 | [diff] [blame] | 953 | } |
| 954 | |
[email protected] | 10705a7b | 2012-08-21 19:07:08 | [diff] [blame] | 955 | net::URLRequestContextGetter* ProfileImpl::GetMediaRequestContext() { |
| 956 | // Return the default media context. |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 957 | return io_data_.GetMediaRequestContextGetter().get(); |
[email protected] | 10705a7b | 2012-08-21 19:07:08 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | net::URLRequestContextGetter* |
| 961 | ProfileImpl::GetMediaRequestContextForRenderProcess( |
| 962 | int renderer_child_id) { |
[email protected] | 10705a7b | 2012-08-21 19:07:08 | [diff] [blame] | 963 | content::RenderProcessHost* rph = content::RenderProcessHost::FromID( |
| 964 | renderer_child_id); |
[email protected] | 27ddfed2 | 2012-10-30 23:22:43 | [diff] [blame] | 965 | content::StoragePartition* storage_partition = rph->GetStoragePartition(); |
| 966 | |
[email protected] | 27ddfed2 | 2012-10-30 23:22:43 | [diff] [blame] | 967 | return storage_partition->GetMediaURLRequestContext(); |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 968 | } |
| 969 | |
[email protected] | 10eb2816 | 2012-09-18 03:04:09 | [diff] [blame] | 970 | net::URLRequestContextGetter* |
| 971 | ProfileImpl::GetMediaRequestContextForStoragePartition( |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 972 | const base::FilePath& partition_path, |
[email protected] | 27ddfed2 | 2012-10-30 23:22:43 | [diff] [blame] | 973 | bool in_memory) { |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 974 | return io_data_ |
| 975 | .GetIsolatedMediaRequestContextGetter(partition_path, in_memory).get(); |
[email protected] | 10eb2816 | 2012-09-18 03:04:09 | [diff] [blame] | 976 | } |
| 977 | |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 978 | content::ResourceContext* ProfileImpl::GetResourceContext() { |
[email protected] | e89b77d | 2011-04-15 18:58:10 | [diff] [blame] | 979 | return io_data_.GetResourceContext(); |
| 980 | } |
| 981 | |
[email protected] | 33ad6ce9 | 2013-08-27 14:39:08 | [diff] [blame] | 982 | net::URLRequestContextGetter* ProfileImpl::GetRequestContextForExtensions() { |
| 983 | return io_data_.GetExtensionsRequestContextGetter().get(); |
| 984 | } |
| 985 | |
[email protected] | 6bd3007 | 2013-02-08 18:17:11 | [diff] [blame] | 986 | net::URLRequestContextGetter* |
| 987 | ProfileImpl::CreateRequestContextForStoragePartition( |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 988 | const base::FilePath& partition_path, |
[email protected] | 6bd3007 | 2013-02-08 18:17:11 | [diff] [blame] | 989 | bool in_memory, |
[email protected] | 7571263c | 2014-03-10 22:57:09 | [diff] [blame] | 990 | content::ProtocolHandlerMap* protocol_handlers, |
[email protected] | 3b90aab | 2014-05-30 17:56:15 | [diff] [blame] | 991 | content::URLRequestInterceptorScopedVector request_interceptors) { |
[email protected] | 6bd3007 | 2013-02-08 18:17:11 | [diff] [blame] | 992 | return io_data_.CreateIsolatedAppRequestContextGetter( |
[email protected] | 7571263c | 2014-03-10 22:57:09 | [diff] [blame] | 993 | partition_path, |
| 994 | in_memory, |
| 995 | protocol_handlers, |
[email protected] | 3b90aab | 2014-05-30 17:56:15 | [diff] [blame] | 996 | request_interceptors.Pass()).get(); |
[email protected] | d969667 | 2011-03-15 22:45:09 | [diff] [blame] | 997 | } |
| 998 | |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 999 | net::SSLConfigService* ProfileImpl::GetSSLConfigService() { |
[email protected] | 08fafe4 | 2013-02-03 08:10:49 | [diff] [blame] | 1000 | // If ssl_config_service_manager_ is null, this typically means that some |
[email protected] | 540380fc | 2014-03-14 10:10:34 | [diff] [blame] | 1001 | // KeyedService is trying to create a RequestContext at startup, |
[email protected] | f1484c5 | 2013-05-22 23:25:44 | [diff] [blame] | 1002 | // but SSLConfigServiceManager is not initialized until DoFinalInit() which is |
[email protected] | 540380fc | 2014-03-14 10:10:34 | [diff] [blame] | 1003 | // invoked after all KeyedServices have been initialized (see |
[email protected] | 08fafe4 | 2013-02-03 08:10:49 | [diff] [blame] | 1004 | // http://crbug.com/171406). |
[email protected] | 9332a3f7 | 2013-05-07 06:33:52 | [diff] [blame] | 1005 | DCHECK(ssl_config_service_manager_) << |
[email protected] | 08fafe4 | 2013-02-03 08:10:49 | [diff] [blame] | 1006 | "SSLConfigServiceManager is not initialized yet"; |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 1007 | return ssl_config_service_manager_->Get(); |
| 1008 | } |
| 1009 | |
| 1010 | HostContentSettingsMap* ProfileImpl::GetHostContentSettingsMap() { |
mukai | a1aa351 | 2014-10-22 20:14:11 | [diff] [blame] | 1011 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 5173de8b | 2013-06-02 21:16:02 | [diff] [blame] | 1012 | if (!host_content_settings_map_.get()) { |
[email protected] | 646c29cb6 | 2012-06-18 14:31:05 | [diff] [blame] | 1013 | host_content_settings_map_ = new HostContentSettingsMap(GetPrefs(), false); |
knn | 95221ffe | 2015-03-04 20:42:43 | [diff] [blame] | 1014 | #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] | 35552dc5 | 2011-07-12 09:04:38 | [diff] [blame] | 1023 | } |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 1024 | return host_content_settings_map_.get(); |
| 1025 | } |
| 1026 | |
[email protected] | 139355f | 2014-05-11 14:21:28 | [diff] [blame] | 1027 | content::BrowserPluginGuestManager* ProfileImpl::GetGuestManager() { |
[email protected] | 1df3d97 | 2014-06-11 04:55:18 | [diff] [blame] | 1028 | #if defined(ENABLE_EXTENSIONS) |
fsamuel | 8dfa19a | 2015-05-05 01:00:39 | [diff] [blame] | 1029 | return guest_view::GuestViewManager::FromBrowserContext(this); |
[email protected] | 1df3d97 | 2014-06-11 04:55:18 | [diff] [blame] | 1030 | #else |
| 1031 | return NULL; |
| 1032 | #endif |
[email protected] | 2456926 | 2014-05-06 03:31:30 | [diff] [blame] | 1033 | } |
| 1034 | |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 1035 | DownloadManagerDelegate* ProfileImpl::GetDownloadManagerDelegate() { |
[email protected] | 423939d | 2013-07-31 20:00:08 | [diff] [blame] | 1036 | return DownloadServiceFactory::GetForBrowserContext(this)-> |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 1037 | GetDownloadManagerDelegate(); |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 1038 | } |
| 1039 | |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 1040 | storage::SpecialStoragePolicy* ProfileImpl::GetSpecialStoragePolicy() { |
[email protected] | dfc0424c | 2014-07-25 21:33:20 | [diff] [blame] | 1041 | #if defined(ENABLE_EXTENSIONS) |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 1042 | return GetExtensionSpecialStoragePolicy(); |
[email protected] | dfc0424c | 2014-07-25 21:33:20 | [diff] [blame] | 1043 | #else |
| 1044 | return NULL; |
| 1045 | #endif |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 1046 | } |
| 1047 | |
[email protected] | c5c89d04 | 2014-06-13 14:43:37 | [diff] [blame] | 1048 | content::PushMessagingService* ProfileImpl::GetPushMessagingService() { |
b.kelemen | 4596b51 | 2015-03-04 18:42:47 | [diff] [blame] | 1049 | return PushMessagingServiceFactory::GetForProfile(this); |
[email protected] | c5c89d04 | 2014-06-13 14:43:37 | [diff] [blame] | 1050 | } |
| 1051 | |
[email protected] | c5bbe0e | 2014-08-01 23:23:30 | [diff] [blame] | 1052 | content::SSLHostStateDelegate* ProfileImpl::GetSSLHostStateDelegate() { |
| 1053 | return ChromeSSLHostStateDelegateFactory::GetForProfile(this); |
| 1054 | } |
| 1055 | |
mlamouri | 4e37202 | 2015-03-29 14:51:06 | [diff] [blame] | 1056 | // TODO(mlamouri): we should all these BrowserContext implementation to Profile |
| 1057 | // instead of repeating them inside all Profile implementations. |
| 1058 | content::PermissionManager* ProfileImpl::GetPermissionManager() { |
| 1059 | return PermissionManagerFactory::GetForProfile(this); |
| 1060 | } |
| 1061 | |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 1062 | bool 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 | |
| 1069 | Time ProfileImpl::GetStartTime() const { |
| 1070 | return start_time_; |
| 1071 | } |
| 1072 | |
[email protected] | cdb756ef | 2012-04-05 18:34:53 | [diff] [blame] | 1073 | #if defined(ENABLE_SESSION_SERVICE) |
[email protected] | 5a0b42e | 2010-07-30 23:42:59 | [diff] [blame] | 1074 | void ProfileImpl::StopCreateSessionServiceTimer() { |
| 1075 | create_session_service_timer_.Stop(); |
| 1076 | } |
| 1077 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 1078 | void ProfileImpl::EnsureSessionServiceCreated() { |
| 1079 | SessionServiceFactory::GetForProfile(this); |
| 1080 | } |
[email protected] | cdb756ef | 2012-04-05 18:34:53 | [diff] [blame] | 1081 | #endif |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 1082 | |
[email protected] | f50278cd | 2010-08-24 17:34:08 | [diff] [blame] | 1083 | #if defined(OS_CHROMEOS) |
[email protected] | 088a296 | 2011-01-26 12:58:42 | [diff] [blame] | 1084 | void ProfileImpl::ChangeAppLocale( |
| 1085 | const std::string& new_locale, AppLocaleChangedVia via) { |
| 1086 | if (new_locale.empty()) { |
[email protected] | 61d68ef1 | 2011-01-13 14:02:56 | [diff] [blame] | 1087 | NOTREACHED(); |
| 1088 | return; |
| 1089 | } |
[email protected] | db3abe6 | 2011-02-09 15:13:25 | [diff] [blame] | 1090 | PrefService* local_state = g_browser_process->local_state(); |
| 1091 | DCHECK(local_state); |
| 1092 | if (local_state->IsManagedPreference(prefs::kApplicationLocale)) |
| 1093 | return; |
[email protected] | 088a296 | 2011-01-26 12:58:42 | [diff] [blame] | 1094 | 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] | 088a296 | 2011-01-26 12:58:42 | [diff] [blame] | 1108 | break; |
| 1109 | } |
[email protected] | 17fc1668 | 2014-07-31 19:51:06 | [diff] [blame] | 1110 | case APP_LOCALE_CHANGED_VIA_LOGIN: |
| 1111 | case APP_LOCALE_CHANGED_VIA_PUBLIC_SESSION_LOGIN: { |
[email protected] | 088a296 | 2011-01-26 12:58:42 | [diff] [blame] | 1112 | 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] | b07090b3 | 2011-04-18 11:56:14 | [diff] [blame] | 1124 | 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] | 088a296 | 2011-01-26 12:58:42 | [diff] [blame] | 1129 | } |
| 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] | c2b68c8 | 2013-09-24 02:49:39 | [diff] [blame] | 1140 | if (!new_locale.empty()) |
| 1141 | GetPrefs()->SetString(prefs::kApplicationLocale, new_locale); |
| 1142 | else if (!backup_locale.empty()) |
[email protected] | 088a296 | 2011-01-26 12:58:42 | [diff] [blame] | 1143 | 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] | 61d68ef1 | 2011-01-13 14:02:56 | [diff] [blame] | 1153 | } |
[email protected] | 088a296 | 2011-01-26 12:58:42 | [diff] [blame] | 1154 | if (do_update_pref) |
| 1155 | GetPrefs()->SetString(prefs::kApplicationLocale, new_locale); |
[email protected] | 17fc1668 | 2014-07-31 19:51:06 | [diff] [blame] | 1156 | if (via != APP_LOCALE_CHANGED_VIA_PUBLIC_SESSION_LOGIN) |
| 1157 | local_state->SetString(prefs::kApplicationLocale, new_locale); |
[email protected] | c2a7e68 | 2011-03-16 13:03:18 | [diff] [blame] | 1158 | |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 1159 | if (user_manager::UserManager::Get()->GetOwnerEmail() == |
[email protected] | 052e3ac | 2014-06-30 14:22:47 | [diff] [blame] | 1160 | chromeos::ProfileHelper::Get()->GetUserByProfile(this)->email()) |
[email protected] | db3abe6 | 2011-02-09 15:13:25 | [diff] [blame] | 1161 | local_state->SetString(prefs::kOwnerLocale, new_locale); |
[email protected] | 61d68ef1 | 2011-01-13 14:02:56 | [diff] [blame] | 1162 | } |
| 1163 | |
[email protected] | 969182a | 2011-03-03 14:53:23 | [diff] [blame] | 1164 | void ProfileImpl::OnLogin() { |
[email protected] | b07090b3 | 2011-04-18 11:56:14 | [diff] [blame] | 1165 | if (locale_change_guard_ == NULL) |
| 1166 | locale_change_guard_.reset(new chromeos::LocaleChangeGuard(this)); |
| 1167 | locale_change_guard_->OnLogin(); |
[email protected] | 969182a | 2011-03-03 14:53:23 | [diff] [blame] | 1168 | } |
| 1169 | |
[email protected] | 45b6ccca | 2011-02-16 04:27:46 | [diff] [blame] | 1170 | void ProfileImpl::InitChromeOSPreferences() { |
| 1171 | chromeos_preferences_.reset(new chromeos::Preferences()); |
[email protected] | aa003a5 | 2014-02-15 06:24:23 | [diff] [blame] | 1172 | chromeos_preferences_->Init( |
[email protected] | f0881cf | 2014-08-15 23:31:42 | [diff] [blame] | 1173 | this, chromeos::ProfileHelper::Get()->GetUserByProfile(this)); |
[email protected] | 45b6ccca | 2011-02-16 04:27:46 | [diff] [blame] | 1174 | } |
[email protected] | 1101dbc5 | 2013-10-05 00:19:12 | [diff] [blame] | 1175 | |
[email protected] | f50278cd | 2010-08-24 17:34:08 | [diff] [blame] | 1176 | #endif // defined(OS_CHROMEOS) |
[email protected] | cc5bfd4 | 2010-11-24 14:44:02 | [diff] [blame] | 1177 | |
| 1178 | PrefProxyConfigTracker* ProfileImpl::GetProxyConfigTracker() { |
[email protected] | e2930d090 | 2013-07-17 05:25:42 | [diff] [blame] | 1179 | if (!pref_proxy_config_tracker_) |
| 1180 | pref_proxy_config_tracker_.reset(CreateProxyConfigTracker()); |
[email protected] | 6f96cbcb | 2011-11-04 02:26:07 | [diff] [blame] | 1181 | return pref_proxy_config_tracker_.get(); |
[email protected] | cc5bfd4 | 2010-11-24 14:44:02 | [diff] [blame] | 1182 | } |
[email protected] | 33f7497 | 2010-12-08 16:40:36 | [diff] [blame] | 1183 | |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 1184 | chrome_browser_net::Predictor* ProfileImpl::GetNetworkPredictor() { |
| 1185 | return predictor_; |
| 1186 | } |
| 1187 | |
[email protected] | a420520 | 2014-06-02 16:03:08 | [diff] [blame] | 1188 | DevToolsNetworkController* ProfileImpl::GetDevToolsNetworkController() { |
| 1189 | return io_data_.GetDevToolsNetworkController(); |
| 1190 | } |
| 1191 | |
[email protected] | 9b203403 | 2014-05-11 18:10:31 | [diff] [blame] | 1192 | void ProfileImpl::ClearNetworkingHistorySince( |
| 1193 | base::Time time, |
| 1194 | const base::Closure& completion) { |
[email protected] | e0e1fc2 | 2012-11-05 20:25:36 | [diff] [blame] | 1195 | io_data_.ClearNetworkingHistorySince(time, completion); |
[email protected] | 02896a8 | 2011-09-21 18:54:32 | [diff] [blame] | 1196 | } |
| 1197 | |
[email protected] | 671f9c6 | 2011-10-28 19:22:07 | [diff] [blame] | 1198 | GURL ProfileImpl::GetHomePage() { |
| 1199 | // --homepage overrides any preferences. |
avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 1200 | const base::CommandLine& command_line = |
| 1201 | *base::CommandLine::ForCurrentProcess(); |
[email protected] | 671f9c6 | 2011-10-28 19:22:07 | [diff] [blame] | 1202 | 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] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1208 | base::FilePath browser_directory; |
[email protected] | 671f9c6 | 2011-10-28 19:22:07 | [diff] [blame] | 1209 | PathService::Get(base::DIR_CURRENT, &browser_directory); |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame^] | 1210 | GURL home_page(url_formatter::FixupRelativeFile( |
[email protected] | 9b5b1d60 | 2014-06-12 14:29:02 | [diff] [blame] | 1211 | browser_directory, |
[email protected] | 671f9c6 | 2011-10-28 19:22:07 | [diff] [blame] | 1212 | 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); |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame^] | 1219 | GURL home_page(url_formatter::FixupURL( |
| 1220 | GetPrefs()->GetString(prefs::kHomePage), std::string())); |
[email protected] | 671f9c6 | 2011-10-28 19:22:07 | [diff] [blame] | 1221 | if (!home_page.is_valid()) |
| 1222 | return GURL(chrome::kChromeUINewTabURL); |
| 1223 | return home_page; |
| 1224 | } |
| 1225 | |
[email protected] | d20d043 | 2014-06-12 17:14:05 | [diff] [blame] | 1226 | void ProfileImpl::UpdateProfileSupervisedUserIdCache() { |
[email protected] | 6ebd60c | 2014-04-28 23:45:20 | [diff] [blame] | 1227 | 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] | d20d043 | 2014-06-12 17:14:05 | [diff] [blame] | 1231 | std::string supervised_user_id = |
| 1232 | GetPrefs()->GetString(prefs::kSupervisedUserId); |
| 1233 | cache.SetSupervisedUserIdOfProfileAtIndex(index, supervised_user_id); |
[email protected] | 6ebd60c | 2014-04-28 23:45:20 | [diff] [blame] | 1234 | ProfileMetrics::UpdateReportedProfilesStatistics(profile_manager); |
| 1235 | } |
| 1236 | } |
| 1237 | |
[email protected] | 881cb0b6 | 2011-12-13 20:39:54 | [diff] [blame] | 1238 | void 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] | 6778fed | 2013-12-24 20:09:37 | [diff] [blame] | 1245 | cache.SetNameOfProfileAtIndex(index, base::UTF8ToUTF16(profile_name)); |
[email protected] | 1cdf093 | 2014-08-16 06:00:49 | [diff] [blame] | 1246 | bool default_name = |
| 1247 | GetPrefs()->GetBoolean(prefs::kProfileUsingDefaultName); |
| 1248 | cache.SetProfileIsUsingDefaultNameAtIndex(index, default_name); |
[email protected] | 881cb0b6 | 2011-12-13 20:39:54 | [diff] [blame] | 1249 | } |
| 1250 | } |
| 1251 | |
| 1252 | void 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] | 1cdf093 | 2014-08-16 06:00:49 | [diff] [blame] | 1260 | 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] | 881cb0b6 | 2011-12-13 20:39:54 | [diff] [blame] | 1266 | } |
| 1267 | } |
| 1268 | |
[email protected] | 8d9243a | 2013-10-21 17:11:48 | [diff] [blame] | 1269 | void 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] | f2df311 | 2011-11-18 10:21:48 | [diff] [blame] | 1279 | // 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. |
| 1284 | void ProfileImpl::GetCacheParameters(bool is_media_context, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1285 | base::FilePath* cache_path, |
[email protected] | f2df311 | 2011-11-18 10:21:48 | [diff] [blame] | 1286 | int* max_size) { |
| 1287 | DCHECK(cache_path); |
| 1288 | DCHECK(max_size); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1289 | base::FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir)); |
[email protected] | f2df311 | 2011-11-18 10:21:48 | [diff] [blame] | 1290 | 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] | e2930d090 | 2013-07-17 05:25:42 | [diff] [blame] | 1295 | |
| 1296 | PrefProxyConfigTracker* 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] | fba33a0 | 2014-06-22 15:42:16 | [diff] [blame] | 1306 | |
| 1307 | scoped_ptr<domain_reliability::DomainReliabilityMonitor> |
ttuttle | fa8427f9 | 2014-08-25 19:38:03 | [diff] [blame] | 1308 | ProfileImpl::CreateDomainReliabilityMonitor(PrefService* local_state) { |
[email protected] | fba33a0 | 2014-06-22 15:42:16 | [diff] [blame] | 1309 | 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( |
ttuttle | 91f1bbd | 2014-10-07 05:57:54 | [diff] [blame] | 1316 | BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); |
[email protected] | fba33a0 | 2014-06-22 15:42:16 | [diff] [blame] | 1317 | } |