| 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/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/debug/trace_event.h" | 11 #include "base/debug/trace_event.h" |
| 12 #include "base/environment.h" | 12 #include "base/environment.h" |
| 13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/json/json_file_value_serializer.h" |
| 15 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/path_service.h" | 17 #include "base/path_service.h" |
| 17 #include "base/prefs/json_pref_store.h" | 18 #include "base/prefs/json_pref_store.h" |
| 18 #include "base/prefs/scoped_user_pref_update.h" | 19 #include "base/prefs/scoped_user_pref_update.h" |
| 19 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
| 20 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
| 21 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
| 23 #include "base/synchronization/waitable_event.h" | 24 #include "base/synchronization/waitable_event.h" |
| 24 #include "base/threading/sequenced_worker_pool.h" | 25 #include "base/threading/sequenced_worker_pool.h" |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 prefs::kClearSiteDataOnExit, | 413 prefs::kClearSiteDataOnExit, |
| 413 false, | 414 false, |
| 414 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 415 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
| 415 } | 416 } |
| 416 | 417 |
| 417 // static | 418 // static |
| 418 void ProfileImpl::InitializePrefHashStoreIfRequired( | 419 void ProfileImpl::InitializePrefHashStoreIfRequired( |
| 419 const base::FilePath& profile_path) { | 420 const base::FilePath& profile_path) { |
| 420 scoped_ptr<PrefHashStoreImpl> pref_hash_store(GetPrefHashStore(profile_path)); | 421 scoped_ptr<PrefHashStoreImpl> pref_hash_store(GetPrefHashStore(profile_path)); |
| 421 if (pref_hash_store && !pref_hash_store->IsInitialized()) { | 422 if (pref_hash_store && !pref_hash_store->IsInitialized()) { |
| 422 chrome_prefs::InitializeHashStoreForPrefFile( | 423 chrome_prefs::InitializeHashStoreFromPrefFile( |
| 423 GetPrefFilePathFromProfilePath(profile_path), | 424 GetPrefFilePathFromProfilePath(profile_path), |
| 424 JsonPrefStore::GetTaskRunnerForFile( | 425 JsonPrefStore::GetTaskRunnerForFile( |
| 425 profile_path, BrowserThread::GetBlockingPool()), | 426 profile_path, BrowserThread::GetBlockingPool()), |
| 426 pref_hash_store.PassAs<PrefHashStore>()); | 427 pref_hash_store.PassAs<PrefHashStore>()); |
| 427 } | 428 } |
| 428 } | 429 } |
| 429 | 430 |
| 430 // static | 431 // static |
| 431 void ProfileImpl::ResetPrefHashStore(const base::FilePath& profile_path) { | 432 void ProfileImpl::ResetPrefHashStore(const base::FilePath& profile_path) { |
| 432 GetPrefHashStore(profile_path)->Reset(); | 433 GetPrefHashStore(profile_path)->Reset(); |
| 433 } | 434 } |
| 434 | 435 |
| 436 // static |
| 437 bool ProfileImpl::InitializePrefsFromMasterPrefs( |
| 438 const base::FilePath& profile_path, |
| 439 const base::DictionaryValue& master_prefs) { |
| 440 JSONFileValueSerializer serializer( |
| 441 GetPrefFilePathFromProfilePath(profile_path)); |
| 442 |
| 443 // Call Serialize (which does IO) on the main thread, which would _normally_ |
| 444 // be verboten. In this case however, we require this IO to synchronously |
| 445 // complete before Chrome can start (as master preferences seed the Local |
| 446 // State and Preferences files). This won't trip ThreadIORestrictions as they |
| 447 // won't have kicked in yet on the main thread. |
| 448 bool success = serializer.Serialize(master_prefs); |
| 449 |
| 450 if (success) { |
| 451 scoped_ptr<PrefHashStore> pref_hash_store(GetPrefHashStore(profile_path)); |
| 452 chrome_prefs::InitializeHashStoreFromMasterPrefs(master_prefs, |
| 453 pref_hash_store.Pass()); |
| 454 } |
| 455 |
| 456 UMA_HISTOGRAM_BOOLEAN("Settings.InitializedFromMasterPrefs", success); |
| 457 return success; |
| 458 } |
| 459 |
| 435 ProfileImpl::ProfileImpl( | 460 ProfileImpl::ProfileImpl( |
| 436 const base::FilePath& path, | 461 const base::FilePath& path, |
| 437 Delegate* delegate, | 462 Delegate* delegate, |
| 438 CreateMode create_mode, | 463 CreateMode create_mode, |
| 439 base::SequencedTaskRunner* sequenced_task_runner) | 464 base::SequencedTaskRunner* sequenced_task_runner) |
| 440 : path_(path), | 465 : path_(path), |
| 441 pref_registry_(new user_prefs::PrefRegistrySyncable), | 466 pref_registry_(new user_prefs::PrefRegistrySyncable), |
| 442 io_data_(this), | 467 io_data_(this), |
| 443 host_content_settings_map_(NULL), | 468 host_content_settings_map_(NULL), |
| 444 last_session_exit_type_(EXIT_NORMAL), | 469 last_session_exit_type_(EXIT_NORMAL), |
| (...skipping 901 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1346 PrefProxyConfigTracker* ProfileImpl::CreateProxyConfigTracker() { | 1371 PrefProxyConfigTracker* ProfileImpl::CreateProxyConfigTracker() { |
| 1347 #if defined(OS_CHROMEOS) | 1372 #if defined(OS_CHROMEOS) |
| 1348 if (chromeos::ProfileHelper::IsSigninProfile(this)) { | 1373 if (chromeos::ProfileHelper::IsSigninProfile(this)) { |
| 1349 return ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState( | 1374 return ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState( |
| 1350 g_browser_process->local_state()); | 1375 g_browser_process->local_state()); |
| 1351 } | 1376 } |
| 1352 #endif // defined(OS_CHROMEOS) | 1377 #endif // defined(OS_CHROMEOS) |
| 1353 return ProxyServiceFactory::CreatePrefProxyConfigTrackerOfProfile( | 1378 return ProxyServiceFactory::CreatePrefProxyConfigTrackerOfProfile( |
| 1354 GetPrefs(), g_browser_process->local_state()); | 1379 GetPrefs(), g_browser_process->local_state()); |
| 1355 } | 1380 } |
| OLD | NEW |