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/prefs/chrome_pref_service_factory.h" | 5 #include "chrome/browser/prefs/chrome_pref_service_factory.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "base/threading/sequenced_worker_pool.h" | 25 #include "base/threading/sequenced_worker_pool.h" |
26 #include "base/time/time.h" | 26 #include "base/time/time.h" |
27 #include "chrome/browser/browser_process.h" | 27 #include "chrome/browser/browser_process.h" |
28 #include "chrome/browser/prefs/command_line_pref_store.h" | 28 #include "chrome/browser/prefs/command_line_pref_store.h" |
29 #include "chrome/browser/prefs/pref_hash_filter.h" | 29 #include "chrome/browser/prefs/pref_hash_filter.h" |
30 #include "chrome/browser/prefs/pref_model_associator.h" | 30 #include "chrome/browser/prefs/pref_model_associator.h" |
31 #include "chrome/browser/prefs/pref_service_syncable.h" | 31 #include "chrome/browser/prefs/pref_service_syncable.h" |
32 #include "chrome/browser/prefs/pref_service_syncable_factory.h" | 32 #include "chrome/browser/prefs/pref_service_syncable_factory.h" |
33 #include "chrome/browser/prefs/profile_pref_store_manager.h" | 33 #include "chrome/browser/prefs/profile_pref_store_manager.h" |
34 #include "chrome/browser/profiles/file_path_verifier_win.h" | 34 #include "chrome/browser/profiles/file_path_verifier_win.h" |
35 #include "chrome/browser/profiles/profile_info_cache.h" | 35 #include "chrome/browser/profiles/profile.h" |
36 #include "chrome/browser/profiles/profile_manager.h" | |
37 #include "chrome/browser/search_engines/default_search_manager.h" | 36 #include "chrome/browser/search_engines/default_search_manager.h" |
38 #include "chrome/browser/search_engines/default_search_pref_migration.h" | 37 #include "chrome/browser/search_engines/default_search_pref_migration.h" |
39 #include "chrome/browser/ui/profile_error_dialog.h" | 38 #include "chrome/browser/ui/profile_error_dialog.h" |
40 #include "chrome/common/chrome_constants.h" | 39 #include "chrome/common/chrome_constants.h" |
41 #include "chrome/common/pref_names.h" | 40 #include "chrome/common/pref_names.h" |
42 #include "components/pref_registry/pref_registry_syncable.h" | 41 #include "components/pref_registry/pref_registry_syncable.h" |
43 #include "content/public/browser/browser_context.h" | 42 #include "content/public/browser/browser_context.h" |
44 #include "content/public/browser/browser_thread.h" | 43 #include "content/public/browser/browser_thread.h" |
45 #include "extensions/browser/pref_names.h" | 44 #include "extensions/browser/pref_names.h" |
46 #include "grit/browser_resources.h" | 45 #include "grit/browser_resources.h" |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 | 176 |
178 // The count of tracked preferences IDs across all platforms. | 177 // The count of tracked preferences IDs across all platforms. |
179 const size_t kTrackedPrefsReportingIDsCount = 16; | 178 const size_t kTrackedPrefsReportingIDsCount = 16; |
180 COMPILE_ASSERT(kTrackedPrefsReportingIDsCount >= arraysize(kTrackedPrefs), | 179 COMPILE_ASSERT(kTrackedPrefsReportingIDsCount >= arraysize(kTrackedPrefs), |
181 need_to_increment_ids_count); | 180 need_to_increment_ids_count); |
182 | 181 |
183 // Each group enforces a superset of the protection provided by the previous | 182 // Each group enforces a superset of the protection provided by the previous |
184 // one. | 183 // one. |
185 enum SettingsEnforcementGroup { | 184 enum SettingsEnforcementGroup { |
186 GROUP_NO_ENFORCEMENT, | 185 GROUP_NO_ENFORCEMENT, |
187 // Only enforce settings on profile loads; still allow seeding of unloaded | 186 // Enforce protected settings on profile loads. |
188 // profiles. | |
189 GROUP_ENFORCE_ON_LOAD, | |
190 // Also disallow seeding of unloaded profiles. | |
191 GROUP_ENFORCE_ALWAYS, | 187 GROUP_ENFORCE_ALWAYS, |
192 // Also enforce extension settings. | 188 // Also enforce extension settings. |
193 GROUP_ENFORCE_ALWAYS_WITH_EXTENSIONS, | 189 GROUP_ENFORCE_ALWAYS_WITH_EXTENSIONS, |
194 // Also enforce extension settings and default search. | 190 // Also enforce extension settings and default search. |
195 GROUP_ENFORCE_ALWAYS_WITH_EXTENSIONS_AND_DSE, | 191 GROUP_ENFORCE_ALWAYS_WITH_EXTENSIONS_AND_DSE, |
196 // The default enforcement group contains all protection features. | 192 // The default enforcement group contains all protection features. |
197 GROUP_ENFORCE_DEFAULT | 193 GROUP_ENFORCE_DEFAULT |
198 }; | 194 }; |
199 | 195 |
200 SettingsEnforcementGroup GetSettingsEnforcementGroup() { | 196 SettingsEnforcementGroup GetSettingsEnforcementGroup() { |
(...skipping 10 matching lines...) Expand all Loading... |
211 return GROUP_NO_ENFORCEMENT; | 207 return GROUP_NO_ENFORCEMENT; |
212 } | 208 } |
213 #endif | 209 #endif |
214 | 210 |
215 struct { | 211 struct { |
216 const char* group_name; | 212 const char* group_name; |
217 SettingsEnforcementGroup group; | 213 SettingsEnforcementGroup group; |
218 } static const kEnforcementLevelMap[] = { | 214 } static const kEnforcementLevelMap[] = { |
219 { chrome_prefs::internals::kSettingsEnforcementGroupNoEnforcement, | 215 { chrome_prefs::internals::kSettingsEnforcementGroupNoEnforcement, |
220 GROUP_NO_ENFORCEMENT }, | 216 GROUP_NO_ENFORCEMENT }, |
221 { chrome_prefs::internals::kSettingsEnforcementGroupEnforceOnload, | |
222 GROUP_ENFORCE_ON_LOAD }, | |
223 { chrome_prefs::internals::kSettingsEnforcementGroupEnforceAlways, | 217 { chrome_prefs::internals::kSettingsEnforcementGroupEnforceAlways, |
224 GROUP_ENFORCE_ALWAYS }, | 218 GROUP_ENFORCE_ALWAYS }, |
225 { chrome_prefs::internals:: | 219 { chrome_prefs::internals:: |
226 kSettingsEnforcementGroupEnforceAlwaysWithExtensions, | 220 kSettingsEnforcementGroupEnforceAlwaysWithExtensions, |
227 GROUP_ENFORCE_ALWAYS_WITH_EXTENSIONS }, | 221 GROUP_ENFORCE_ALWAYS_WITH_EXTENSIONS }, |
228 { chrome_prefs::internals:: | 222 { chrome_prefs::internals:: |
229 kSettingsEnforcementGroupEnforceAlwaysWithExtensionsAndDSE, | 223 kSettingsEnforcementGroupEnforceAlwaysWithExtensionsAndDSE, |
230 GROUP_ENFORCE_ALWAYS_WITH_EXTENSIONS_AND_DSE }, | 224 GROUP_ENFORCE_ALWAYS_WITH_EXTENSIONS_AND_DSE }, |
231 }; | 225 }; |
232 | 226 |
233 // Use the no enforcement setting in the absence of a field trial | 227 // Use the no enforcement setting in the absence of a field trial |
234 // config. Remember to update the OFFICIAL_BUILD sections of | 228 // config. Remember to update the OFFICIAL_BUILD section of |
235 // pref_hash_browsertest.cc and extension_startup_browsertest.cc when updating | 229 // extension_startup_browsertest.cc when updating the default value below. |
236 // the default value below. | |
237 // TODO(gab): Change this to the strongest enforcement on all platforms. | 230 // TODO(gab): Change this to the strongest enforcement on all platforms. |
238 SettingsEnforcementGroup enforcement_group = GROUP_NO_ENFORCEMENT; | 231 SettingsEnforcementGroup enforcement_group = GROUP_NO_ENFORCEMENT; |
239 bool group_determined_from_trial = false; | 232 bool group_determined_from_trial = false; |
240 base::FieldTrial* trial = | 233 base::FieldTrial* trial = |
241 base::FieldTrialList::Find( | 234 base::FieldTrialList::Find( |
242 chrome_prefs::internals::kSettingsEnforcementTrialName); | 235 chrome_prefs::internals::kSettingsEnforcementTrialName); |
243 if (trial) { | 236 if (trial) { |
244 const std::string& group_name = trial->group_name(); | 237 const std::string& group_name = trial->group_name(); |
245 // ARRAYSIZE_UNSAFE must be used since the array is declared locally; it is | 238 // ARRAYSIZE_UNSAFE must be used since the array is declared locally; it is |
246 // only unsafe because it could not trigger a compile error on some | 239 // only unsafe because it could not trigger a compile error on some |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 | 374 |
382 factory->set_async(async); | 375 factory->set_async(async); |
383 factory->set_extension_prefs(extension_prefs); | 376 factory->set_extension_prefs(extension_prefs); |
384 factory->set_command_line_prefs( | 377 factory->set_command_line_prefs( |
385 make_scoped_refptr( | 378 make_scoped_refptr( |
386 new CommandLinePrefStore(CommandLine::ForCurrentProcess()))); | 379 new CommandLinePrefStore(CommandLine::ForCurrentProcess()))); |
387 factory->set_read_error_callback(base::Bind(&HandleReadError)); | 380 factory->set_read_error_callback(base::Bind(&HandleReadError)); |
388 factory->set_user_prefs(user_pref_store); | 381 factory->set_user_prefs(user_pref_store); |
389 } | 382 } |
390 | 383 |
391 // Initialize/update preference hash stores for all profiles but the one whose | |
392 // path matches |ignored_profile_path|. | |
393 void UpdateAllPrefHashStoresIfRequired( | |
394 const base::FilePath& ignored_profile_path) { | |
395 const ProfileInfoCache& profile_info_cache = | |
396 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
397 const size_t n_profiles = profile_info_cache.GetNumberOfProfiles(); | |
398 for (size_t i = 0; i < n_profiles; ++i) { | |
399 const base::FilePath profile_path = | |
400 profile_info_cache.GetPathOfProfileAtIndex(i); | |
401 if (profile_path != ignored_profile_path) { | |
402 CreateProfilePrefStoreManager(profile_path) | |
403 ->UpdateProfileHashStoreIfRequired( | |
404 JsonPrefStore::GetTaskRunnerForFile( | |
405 profile_path, BrowserThread::GetBlockingPool())); | |
406 } | |
407 } | |
408 } | |
409 | |
410 } // namespace | 384 } // namespace |
411 | 385 |
412 namespace chrome_prefs { | 386 namespace chrome_prefs { |
413 | 387 |
414 namespace internals { | 388 namespace internals { |
415 | 389 |
416 const char kSettingsEnforcementTrialName[] = "SettingsEnforcement"; | 390 const char kSettingsEnforcementTrialName[] = "SettingsEnforcement"; |
417 const char kSettingsEnforcementGroupNoEnforcement[] = "no_enforcement"; | 391 const char kSettingsEnforcementGroupNoEnforcement[] = "no_enforcement"; |
418 const char kSettingsEnforcementGroupEnforceOnload[] = "enforce_on_load"; | |
419 const char kSettingsEnforcementGroupEnforceAlways[] = "enforce_always"; | 392 const char kSettingsEnforcementGroupEnforceAlways[] = "enforce_always"; |
420 const char kSettingsEnforcementGroupEnforceAlwaysWithExtensions[] = | 393 const char kSettingsEnforcementGroupEnforceAlwaysWithExtensions[] = |
421 "enforce_always_with_extensions"; | 394 "enforce_always_with_extensions"; |
422 const char kSettingsEnforcementGroupEnforceAlwaysWithExtensionsAndDSE[] = | 395 const char kSettingsEnforcementGroupEnforceAlwaysWithExtensionsAndDSE[] = |
423 "enforce_always_with_extensions_and_dse"; | 396 "enforce_always_with_extensions_and_dse"; |
424 | 397 |
425 } // namespace internals | 398 } // namespace internals |
426 | 399 |
427 scoped_ptr<PrefService> CreateLocalState( | 400 scoped_ptr<PrefService> CreateLocalState( |
428 const base::FilePath& pref_filename, | 401 const base::FilePath& pref_filename, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 base::TimeDelta::FromSeconds(g_disable_delays_and_domain_check_for_testing | 455 base::TimeDelta::FromSeconds(g_disable_delays_and_domain_check_for_testing |
483 ? 0 | 456 ? 0 |
484 : kVerifyPrefsFileDelaySeconds)); | 457 : kVerifyPrefsFileDelaySeconds)); |
485 #endif | 458 #endif |
486 } | 459 } |
487 | 460 |
488 void DisableDelaysAndDomainCheckForTesting() { | 461 void DisableDelaysAndDomainCheckForTesting() { |
489 g_disable_delays_and_domain_check_for_testing = true; | 462 g_disable_delays_and_domain_check_for_testing = true; |
490 } | 463 } |
491 | 464 |
492 void SchedulePrefHashStoresUpdateCheck( | |
493 const base::FilePath& initial_profile_path) { | |
494 if (!ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking) { | |
495 ProfilePrefStoreManager::ResetAllPrefHashStores( | |
496 g_browser_process->local_state()); | |
497 return; | |
498 } | |
499 | |
500 if (GetSettingsEnforcementGroup() >= GROUP_ENFORCE_ALWAYS) | |
501 return; | |
502 | |
503 const int kDefaultPrefHashStoresUpdateCheckDelaySeconds = 55; | |
504 BrowserThread::PostDelayedTask( | |
505 BrowserThread::UI, | |
506 FROM_HERE, | |
507 base::Bind(&UpdateAllPrefHashStoresIfRequired, | |
508 initial_profile_path), | |
509 base::TimeDelta::FromSeconds( | |
510 g_disable_delays_and_domain_check_for_testing ? | |
511 0 : kDefaultPrefHashStoresUpdateCheckDelaySeconds)); | |
512 } | |
513 | |
514 void ResetPrefHashStore(const base::FilePath& profile_path) { | |
515 CreateProfilePrefStoreManager(profile_path)->ResetPrefHashStore(); | |
516 } | |
517 | |
518 bool InitializePrefsFromMasterPrefs( | 465 bool InitializePrefsFromMasterPrefs( |
519 const base::FilePath& profile_path, | 466 const base::FilePath& profile_path, |
520 const base::DictionaryValue& master_prefs) { | 467 const base::DictionaryValue& master_prefs) { |
521 return CreateProfilePrefStoreManager(profile_path) | 468 return CreateProfilePrefStoreManager(profile_path) |
522 ->InitializePrefsFromMasterPrefs(master_prefs); | 469 ->InitializePrefsFromMasterPrefs(master_prefs); |
523 } | 470 } |
524 | 471 |
525 base::Time GetResetTime(Profile* profile) { | 472 base::Time GetResetTime(Profile* profile) { |
526 return ProfilePrefStoreManager::GetResetTime(profile->GetPrefs()); | 473 return ProfilePrefStoreManager::GetResetTime(profile->GetPrefs()); |
527 } | 474 } |
528 | 475 |
529 void ClearResetTime(Profile* profile) { | 476 void ClearResetTime(Profile* profile) { |
530 ProfilePrefStoreManager::ClearResetTime(profile->GetPrefs()); | 477 ProfilePrefStoreManager::ClearResetTime(profile->GetPrefs()); |
531 } | 478 } |
532 | 479 |
533 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { | 480 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { |
534 ProfilePrefStoreManager::RegisterProfilePrefs(registry); | 481 ProfilePrefStoreManager::RegisterProfilePrefs(registry); |
535 } | 482 } |
536 | 483 |
537 void RegisterPrefs(PrefRegistrySimple* registry) { | 484 void RegisterPrefs(PrefRegistrySimple* registry) { |
538 ProfilePrefStoreManager::RegisterPrefs(registry); | 485 ProfilePrefStoreManager::RegisterPrefs(registry); |
539 } | 486 } |
540 | 487 |
541 } // namespace chrome_prefs | 488 } // namespace chrome_prefs |
OLD | NEW |