| 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 "base/prefs/pref_service.h" | 5 #include "base/prefs/pref_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/location.h" | |
| 12 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/prefs/default_pref_store.h" | 14 #include "base/prefs/default_pref_store.h" |
| 15 #include "base/prefs/pref_notifier_impl.h" | 15 #include "base/prefs/pref_notifier_impl.h" |
| 16 #include "base/prefs/pref_registry.h" | 16 #include "base/prefs/pref_registry.h" |
| 17 #include "base/prefs/pref_value_store.h" | 17 #include "base/prefs/pref_value_store.h" |
| 18 #include "base/single_thread_task_runner.h" | |
| 19 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
| 20 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| 21 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
| 22 #include "base/thread_task_runner_handle.h" | |
| 23 #include "base/value_conversions.h" | 21 #include "base/value_conversions.h" |
| 24 #include "build/build_config.h" | 22 #include "build/build_config.h" |
| 25 | 23 |
| 26 namespace { | 24 namespace { |
| 27 | 25 |
| 28 class ReadErrorHandler : public PersistentPrefStore::ReadErrorDelegate { | 26 class ReadErrorHandler : public PersistentPrefStore::ReadErrorDelegate { |
| 29 public: | 27 public: |
| 30 ReadErrorHandler(base::Callback<void(PersistentPrefStore::PrefReadError)> cb) | 28 ReadErrorHandler(base::Callback<void(PersistentPrefStore::PrefReadError)> cb) |
| 31 : callback_(cb) {} | 29 : callback_(cb) {} |
| 32 | 30 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 pref_notifier_.reset(); | 72 pref_notifier_.reset(); |
| 75 } | 73 } |
| 76 | 74 |
| 77 void PrefService::InitFromStorage(bool async) { | 75 void PrefService::InitFromStorage(bool async) { |
| 78 if (user_pref_store_->IsInitializationComplete()) { | 76 if (user_pref_store_->IsInitializationComplete()) { |
| 79 read_error_callback_.Run(user_pref_store_->GetReadError()); | 77 read_error_callback_.Run(user_pref_store_->GetReadError()); |
| 80 } else if (!async) { | 78 } else if (!async) { |
| 81 read_error_callback_.Run(user_pref_store_->ReadPrefs()); | 79 read_error_callback_.Run(user_pref_store_->ReadPrefs()); |
| 82 } else { | 80 } else { |
| 83 // Guarantee that initialization happens after this function returned. | 81 // Guarantee that initialization happens after this function returned. |
| 84 base::ThreadTaskRunnerHandle::Get()->PostTask( | 82 base::MessageLoop::current()->PostTask( |
| 85 FROM_HERE, | 83 FROM_HERE, |
| 86 base::Bind(&PersistentPrefStore::ReadPrefsAsync, user_pref_store_.get(), | 84 base::Bind(&PersistentPrefStore::ReadPrefsAsync, |
| 85 user_pref_store_.get(), |
| 87 new ReadErrorHandler(read_error_callback_))); | 86 new ReadErrorHandler(read_error_callback_))); |
| 88 } | 87 } |
| 89 } | 88 } |
| 90 | 89 |
| 91 void PrefService::CommitPendingWrite() { | 90 void PrefService::CommitPendingWrite() { |
| 92 DCHECK(CalledOnValidThread()); | 91 DCHECK(CalledOnValidThread()); |
| 93 user_pref_store_->CommitPendingWrite(); | 92 user_pref_store_->CommitPendingWrite(); |
| 94 } | 93 } |
| 95 | 94 |
| 96 bool PrefService::GetBoolean(const std::string& path) const { | 95 bool PrefService::GetBoolean(const std::string& path) const { |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 DCHECK(found_value->IsType(default_type)); | 584 DCHECK(found_value->IsType(default_type)); |
| 586 return found_value; | 585 return found_value; |
| 587 } else { | 586 } else { |
| 588 // Every registered preference has at least a default value. | 587 // Every registered preference has at least a default value. |
| 589 NOTREACHED() << "no valid value found for registered pref " << path; | 588 NOTREACHED() << "no valid value found for registered pref " << path; |
| 590 } | 589 } |
| 591 } | 590 } |
| 592 | 591 |
| 593 return NULL; | 592 return NULL; |
| 594 } | 593 } |
| OLD | NEW |