diff options
Diffstat (limited to 'chrome/common/pref_service.cc')
-rw-r--r-- | chrome/common/pref_service.cc | 36 |
1 files changed, 11 insertions, 25 deletions
diff --git a/chrome/common/pref_service.cc b/chrome/common/pref_service.cc index 5e2f319..a942e32 100644 --- a/chrome/common/pref_service.cc +++ b/chrome/common/pref_service.cc @@ -4,6 +4,7 @@ #include "chrome/common/pref_service.h" +#include "base/compiler_specific.h" #include "base/file_util.h" #include "base/logging.h" #include "base/message_loop.h" @@ -40,13 +41,10 @@ class SaveLaterTask : public Task { int bytes_written = file_util::WriteFile(tmp_file_name, data_.c_str(), static_cast<int>(data_.length())); if (bytes_written != -1) { - if (!MoveFileEx(tmp_file_name.c_str(), file_name_.c_str(), - MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING)) { + if (!file_util::Move(tmp_file_name, file_name_)) { // Rename failed. Try again on the off chance someone has locked either // file and hope we're successful the second time through. - BOOL move_result = - MoveFileEx(tmp_file_name.c_str(), file_name_.c_str(), - MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING); + bool move_result = file_util::Move(tmp_file_name, file_name_); DCHECK(move_result); } } @@ -56,7 +54,7 @@ class SaveLaterTask : public Task { std::wstring file_name_; std::string data_; - DISALLOW_EVIL_CONSTRUCTORS(SaveLaterTask); + DISALLOW_COPY_AND_ASSIGN(SaveLaterTask); }; // A helper function for RegisterLocalized*Pref that creates a Value* based on @@ -75,23 +73,12 @@ Value* CreateLocaleDefaultValue(Value::ValueType type, int message_id) { } case Value::TYPE_INTEGER: { - int num_int = 0; - int parsed_values = swscanf_s(resource_string.c_str(), L"%d", &num_int); - // This is a trusted value (comes from our locale dll), so it should - // successfully parse. - DCHECK(parsed_values == 1); - return Value::CreateIntegerValue(num_int); + return Value::CreateIntegerValue(StringToInt(resource_string)); break; } case Value::TYPE_REAL: { - double num_double = 0.0; - int parsed_values = swscanf_s(resource_string.c_str(), L"%lf", - &num_double); - // This is a trusted value (comes from our locale dll), so it should - // successfully parse. - DCHECK(parsed_values == 1); - return Value::CreateRealValue(num_double); + return Value::CreateRealValue(StringToDouble(resource_string)); break; } @@ -121,8 +108,7 @@ PrefService::PrefService(const std::wstring& pref_filename) : persistent_(new DictionaryValue), transient_(new DictionaryValue), pref_filename_(pref_filename), -#pragma warning(suppress: 4355) // Okay to pass "this" here. - save_preferences_factory_(this) { + ALLOW_THIS_IN_INITIALIZER_LIST(save_preferences_factory_(this)) { LoadPersistentPrefs(pref_filename_); } @@ -434,7 +420,7 @@ void PrefService::AddPrefObserver(const wchar_t* path, // Verify that this observer doesn't already exist. NotificationObserverList::Iterator it(*observer_list); NotificationObserver* existing_obs; - while (existing_obs = it.GetNext()) { + while ((existing_obs = it.GetNext()) != NULL) { DCHECK(existing_obs != obs) << path << " observer already registered"; if (existing_obs == obs) return; @@ -640,7 +626,7 @@ void PrefService::FireObservers(const wchar_t* path) { NotificationObserverList::Iterator it(*(observer_iterator->second)); NotificationObserver* observer; - while (observer = it.GetNext()) { + while ((observer = it.GetNext()) != NULL) { observer->Observe(NOTIFY_PREF_CHANGED, Source<PrefService>(this), Details<std::wstring>(&path_str)); @@ -653,10 +639,10 @@ void PrefService::FireObservers(const wchar_t* path) { PrefService::Preference::Preference(DictionaryValue* root_pref, const wchar_t* name, Value* default_value) - : root_pref_(root_pref), + : type_(Value::TYPE_NULL), name_(name), default_value_(default_value), - type_(Value::TYPE_NULL) { + root_pref_(root_pref) { DCHECK(name); if (default_value) { |