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