Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/profiles/profile_impl.h" | 5 #include "chrome/browser/profiles/profile_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/environment.h" | 10 #include "base/environment.h" |
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "base/string_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
| 16 #include "base/string_tokenizer.h" | 16 #include "base/string_tokenizer.h" |
| 17 #include "base/string_util.h" | 17 #include "base/string_util.h" |
| 18 #include "base/stringprintf.h" | 18 #include "base/stringprintf.h" |
| 19 #include "base/threading/sequenced_worker_pool.h" | |
| 19 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
| 20 #include "base/version.h" | 21 #include "base/version.h" |
| 21 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 22 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
| 22 #include "chrome/browser/background/background_contents_service_factory.h" | 23 #include "chrome/browser/background/background_contents_service_factory.h" |
| 23 #include "chrome/browser/background/background_mode_manager.h" | 24 #include "chrome/browser/background/background_mode_manager.h" |
| 24 #include "chrome/browser/browser_process.h" | 25 #include "chrome/browser/browser_process.h" |
| 25 #include "chrome/browser/chrome_plugin_service_filter.h" | 26 #include "chrome/browser/chrome_plugin_service_filter.h" |
| 26 #include "chrome/browser/content_settings/cookie_settings.h" | 27 #include "chrome/browser/content_settings/cookie_settings.h" |
| 27 #include "chrome/browser/content_settings/host_content_settings_map.h" | 28 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 28 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 29 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 #include "chrome/browser/user_style_sheet_watcher.h" | 69 #include "chrome/browser/user_style_sheet_watcher.h" |
| 69 #include "chrome/browser/visitedlink/visitedlink_event_listener.h" | 70 #include "chrome/browser/visitedlink/visitedlink_event_listener.h" |
| 70 #include "chrome/browser/visitedlink/visitedlink_master.h" | 71 #include "chrome/browser/visitedlink/visitedlink_master.h" |
| 71 #include "chrome/browser/web_resource/promo_resource_service.h" | 72 #include "chrome/browser/web_resource/promo_resource_service.h" |
| 72 #include "chrome/browser/webdata/web_data_service.h" | 73 #include "chrome/browser/webdata/web_data_service.h" |
| 73 #include "chrome/common/chrome_constants.h" | 74 #include "chrome/common/chrome_constants.h" |
| 74 #include "chrome/common/chrome_notification_types.h" | 75 #include "chrome/common/chrome_notification_types.h" |
| 75 #include "chrome/common/chrome_paths_internal.h" | 76 #include "chrome/common/chrome_paths_internal.h" |
| 76 #include "chrome/common/chrome_switches.h" | 77 #include "chrome/common/chrome_switches.h" |
| 77 #include "chrome/common/chrome_version_info.h" | 78 #include "chrome/common/chrome_version_info.h" |
| 79 #include "chrome/common/json_pref_store.h" | |
| 78 #include "chrome/common/pref_names.h" | 80 #include "chrome/common/pref_names.h" |
| 79 #include "chrome/common/url_constants.h" | 81 #include "chrome/common/url_constants.h" |
| 80 #include "content/public/browser/browser_thread.h" | 82 #include "content/public/browser/browser_thread.h" |
| 81 #include "content/public/browser/dom_storage_context.h" | 83 #include "content/public/browser/dom_storage_context.h" |
| 82 #include "content/public/browser/host_zoom_map.h" | 84 #include "content/public/browser/host_zoom_map.h" |
| 83 #include "content/public/browser/notification_service.h" | 85 #include "content/public/browser/notification_service.h" |
| 84 #include "content/public/browser/render_process_host.h" | 86 #include "content/public/browser/render_process_host.h" |
| 85 #include "content/public/browser/storage_partition.h" | 87 #include "content/public/browser/storage_partition.h" |
| 86 #include "content/public/browser/user_metrics.h" | 88 #include "content/public/browser/user_metrics.h" |
| 87 #include "content/public/common/content_constants.h" | 89 #include "content/public/common/content_constants.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 NOTREACHED(); | 203 NOTREACHED(); |
| 202 return std::string(); | 204 return std::string(); |
| 203 } | 205 } |
| 204 | 206 |
| 205 } // namespace | 207 } // namespace |
| 206 | 208 |
| 207 // static | 209 // static |
| 208 Profile* Profile::CreateProfile(const FilePath& path, | 210 Profile* Profile::CreateProfile(const FilePath& path, |
| 209 Delegate* delegate, | 211 Delegate* delegate, |
| 210 CreateMode create_mode) { | 212 CreateMode create_mode) { |
| 213 // Get sequenced task runner for making sure that file operations of | |
| 214 // this profile (defined by |path|) are executed in expected order | |
| 215 // (what was previously assured by the FILE thread). | |
| 216 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner = | |
| 217 JsonPrefStore::GetTaskRunnerForFile(path, | |
| 218 BrowserThread::GetBlockingPool()); | |
| 211 if (create_mode == CREATE_MODE_ASYNCHRONOUS) { | 219 if (create_mode == CREATE_MODE_ASYNCHRONOUS) { |
| 212 DCHECK(delegate); | 220 DCHECK(delegate); |
| 213 // This is safe while all file operations are done on the FILE thread. | 221 // We need to make sure that profile directory is created on the same |
| 214 BrowserThread::PostTask( | 222 // blocking pool where we will run all its important file serialization |
| 215 BrowserThread::FILE, FROM_HERE, | 223 // tasks (i.e. JsonPrefStore). |
| 216 base::Bind(&CreateDirectoryNoResult, path)); | 224 sequenced_task_runner->PostTask(FROM_HERE, |
| 225 base::Bind(&CreateDirectoryNoResult, path)); | |
|
Mattias Nissler (ping if slow)
2012/10/22 17:28:21
This is dangerous if other code that is still on t
zel
2012/10/24 02:20:11
Yes, I've tested this and adjusted such FILE depen
Mattias Nissler (ping if slow)
2012/10/24 13:36:16
Well, those were probably the easier ones :) I'm c
zel
2012/10/24 16:49:48
Yeah, that's a great idea. Done - PTAL.
| |
| 217 } else if (create_mode == CREATE_MODE_SYNCHRONOUS) { | 226 } else if (create_mode == CREATE_MODE_SYNCHRONOUS) { |
| 218 if (!file_util::PathExists(path)) { | 227 if (!file_util::PathExists(path)) { |
| 219 // TODO(tc): http://b/1094718 Bad things happen if we can't write to the | 228 // TODO(tc): http://b/1094718 Bad things happen if we can't write to the |
| 220 // profile directory. We should eventually be able to run in this | 229 // profile directory. We should eventually be able to run in this |
| 221 // situation. | 230 // situation. |
| 222 if (!file_util::CreateDirectory(path)) | 231 if (!file_util::CreateDirectory(path)) |
| 223 return NULL; | 232 return NULL; |
| 224 } | 233 } |
| 225 } else { | 234 } else { |
| 226 NOTREACHED(); | 235 NOTREACHED(); |
| 227 } | 236 } |
| 228 | 237 |
| 229 return new ProfileImpl(path, delegate, create_mode); | 238 return new ProfileImpl(path, delegate, create_mode, sequenced_task_runner); |
| 230 } | 239 } |
| 231 | 240 |
| 232 // static | 241 // static |
| 233 int ProfileImpl::create_readme_delay_ms = 60000; | 242 int ProfileImpl::create_readme_delay_ms = 60000; |
| 234 | 243 |
| 235 // static | 244 // static |
| 236 const char* const ProfileImpl::kPrefExitTypeNormal = "Normal"; | 245 const char* const ProfileImpl::kPrefExitTypeNormal = "Normal"; |
| 237 | 246 |
| 238 // static | 247 // static |
| 239 void ProfileImpl::RegisterUserPrefs(PrefService* prefs) { | 248 void ProfileImpl::RegisterUserPrefs(PrefService* prefs) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 prefs->RegisterIntegerPref(prefs::kMediaCacheSize, | 281 prefs->RegisterIntegerPref(prefs::kMediaCacheSize, |
| 273 0, | 282 0, |
| 274 PrefService::UNSYNCABLE_PREF); | 283 PrefService::UNSYNCABLE_PREF); |
| 275 | 284 |
| 276 // Deprecated. Kept around for migration. | 285 // Deprecated. Kept around for migration. |
| 277 prefs->RegisterBooleanPref(prefs::kClearSiteDataOnExit, | 286 prefs->RegisterBooleanPref(prefs::kClearSiteDataOnExit, |
| 278 false, | 287 false, |
| 279 PrefService::SYNCABLE_PREF); | 288 PrefService::SYNCABLE_PREF); |
| 280 } | 289 } |
| 281 | 290 |
| 282 ProfileImpl::ProfileImpl(const FilePath& path, | 291 ProfileImpl::ProfileImpl( |
| 283 Delegate* delegate, | 292 const FilePath& path, |
| 284 CreateMode create_mode) | 293 Delegate* delegate, |
| 294 CreateMode create_mode, | |
| 295 base::SequencedTaskRunner* sequenced_task_runner) | |
| 285 : path_(path), | 296 : path_(path), |
| 286 ALLOW_THIS_IN_INITIALIZER_LIST(visited_link_event_listener_( | 297 ALLOW_THIS_IN_INITIALIZER_LIST(visited_link_event_listener_( |
| 287 new VisitedLinkEventListener(this))), | 298 new VisitedLinkEventListener(this))), |
| 288 ALLOW_THIS_IN_INITIALIZER_LIST(io_data_(this)), | 299 ALLOW_THIS_IN_INITIALIZER_LIST(io_data_(this)), |
| 289 host_content_settings_map_(NULL), | 300 host_content_settings_map_(NULL), |
| 290 last_session_exit_type_(EXIT_NORMAL), | 301 last_session_exit_type_(EXIT_NORMAL), |
| 291 start_time_(Time::Now()), | 302 start_time_(Time::Now()), |
| 292 delegate_(delegate), | 303 delegate_(delegate), |
| 293 predictor_(NULL) { | 304 predictor_(NULL) { |
| 294 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << | 305 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 324 #else | 335 #else |
| 325 policy_service_.reset(new policy::PolicyServiceStub()); | 336 policy_service_.reset(new policy::PolicyServiceStub()); |
| 326 #endif | 337 #endif |
| 327 | 338 |
| 328 if (create_mode == CREATE_MODE_ASYNCHRONOUS) { | 339 if (create_mode == CREATE_MODE_ASYNCHRONOUS) { |
| 329 prefs_.reset(PrefService::CreatePrefService( | 340 prefs_.reset(PrefService::CreatePrefService( |
| 330 GetPrefFilePath(), | 341 GetPrefFilePath(), |
| 331 policy_service_.get(), | 342 policy_service_.get(), |
| 332 new ExtensionPrefStore( | 343 new ExtensionPrefStore( |
| 333 ExtensionPrefValueMapFactory::GetForProfile(this), false), | 344 ExtensionPrefValueMapFactory::GetForProfile(this), false), |
| 334 true)); | 345 true, |
| 346 sequenced_task_runner)); | |
| 335 // Wait for the notification that prefs has been loaded (successfully or | 347 // Wait for the notification that prefs has been loaded (successfully or |
| 336 // not). | 348 // not). |
| 337 registrar_.Add(this, chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED, | 349 registrar_.Add(this, chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED, |
| 338 content::Source<PrefService>(prefs_.get())); | 350 content::Source<PrefService>(prefs_.get())); |
| 339 } else if (create_mode == CREATE_MODE_SYNCHRONOUS) { | 351 } else if (create_mode == CREATE_MODE_SYNCHRONOUS) { |
| 340 // Load prefs synchronously. | 352 // Load prefs synchronously. |
| 341 prefs_.reset(PrefService::CreatePrefService( | 353 prefs_.reset(PrefService::CreatePrefService( |
| 342 GetPrefFilePath(), | 354 GetPrefFilePath(), |
| 343 policy_service_.get(), | 355 policy_service_.get(), |
| 344 new ExtensionPrefStore( | 356 new ExtensionPrefStore( |
| 345 ExtensionPrefValueMapFactory::GetForProfile(this), false), | 357 ExtensionPrefValueMapFactory::GetForProfile(this), false), |
| 346 false)); | 358 false, |
| 359 sequenced_task_runner)); | |
| 347 OnPrefsLoaded(true); | 360 OnPrefsLoaded(true); |
| 348 } else { | 361 } else { |
| 349 NOTREACHED(); | 362 NOTREACHED(); |
| 350 } | 363 } |
| 351 } | 364 } |
| 352 | 365 |
| 353 void ProfileImpl::DoFinalInit(bool is_new_profile) { | 366 void ProfileImpl::DoFinalInit(bool is_new_profile) { |
| 354 PrefService* prefs = GetPrefs(); | 367 PrefService* prefs = GetPrefs(); |
| 355 pref_change_registrar_.Init(prefs); | 368 pref_change_registrar_.Init(prefs); |
| 356 pref_change_registrar_.Add(prefs::kGoogleServicesUsername, this); | 369 pref_change_registrar_.Add(prefs::kGoogleServicesUsername, this); |
| (...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1165 if (!path.empty()) | 1178 if (!path.empty()) |
| 1166 *cache_path = path; | 1179 *cache_path = path; |
| 1167 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : | 1180 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : |
| 1168 prefs_->GetInteger(prefs::kDiskCacheSize); | 1181 prefs_->GetInteger(prefs::kDiskCacheSize); |
| 1169 } | 1182 } |
| 1170 | 1183 |
| 1171 base::Callback<ChromeURLDataManagerBackend*(void)> | 1184 base::Callback<ChromeURLDataManagerBackend*(void)> |
| 1172 ProfileImpl::GetChromeURLDataManagerBackendGetter() const { | 1185 ProfileImpl::GetChromeURLDataManagerBackendGetter() const { |
| 1173 return io_data_.GetChromeURLDataManagerBackendGetter(); | 1186 return io_data_.GetChromeURLDataManagerBackendGetter(); |
| 1174 } | 1187 } |
| OLD | NEW |