| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS 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 "update_engine/prefs.h" | 5 #include "update_engine/prefs.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/string_number_conversions.h" |
| 9 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 10 #include "update_engine/utils.h" | 11 #include "update_engine/utils.h" |
| 11 | 12 |
| 12 using std::string; | 13 using std::string; |
| 13 | 14 |
| 14 namespace chromeos_update_engine { | 15 namespace chromeos_update_engine { |
| 15 | 16 |
| 16 const char kPrefsLastActivePingDay[] = "last-active-ping-day"; | 17 const char kPrefsLastActivePingDay[] = "last-active-ping-day"; |
| 17 const char kPrefsLastRollCallPingDay[] = "last-roll-call-ping-day"; | 18 const char kPrefsLastRollCallPingDay[] = "last-roll-call-ping-day"; |
| 18 | 19 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 38 TEST_AND_RETURN_FALSE( | 39 TEST_AND_RETURN_FALSE( |
| 39 file_util::WriteFile(filename, value.data(), value.size()) == | 40 file_util::WriteFile(filename, value.data(), value.size()) == |
| 40 static_cast<int>(value.size())); | 41 static_cast<int>(value.size())); |
| 41 return true; | 42 return true; |
| 42 } | 43 } |
| 43 | 44 |
| 44 bool Prefs::GetInt64(const string& key, int64_t* value) { | 45 bool Prefs::GetInt64(const string& key, int64_t* value) { |
| 45 string str_value; | 46 string str_value; |
| 46 TEST_AND_RETURN_FALSE(GetString(key, &str_value)); | 47 TEST_AND_RETURN_FALSE(GetString(key, &str_value)); |
| 47 TrimWhitespaceASCII(str_value, TRIM_ALL, &str_value); | 48 TrimWhitespaceASCII(str_value, TRIM_ALL, &str_value); |
| 48 TEST_AND_RETURN_FALSE(StringToInt64(str_value, value)); | 49 TEST_AND_RETURN_FALSE(base::StringToInt64(str_value, value)); |
| 49 return true; | 50 return true; |
| 50 } | 51 } |
| 51 | 52 |
| 52 bool Prefs::SetInt64(const string& key, const int64_t value) { | 53 bool Prefs::SetInt64(const string& key, const int64_t value) { |
| 53 return SetString(key, Int64ToString(value)); | 54 return SetString(key, base::Int64ToString(value)); |
| 54 } | 55 } |
| 55 | 56 |
| 56 bool Prefs::GetFileNameForKey(const std::string& key, FilePath* filename) { | 57 bool Prefs::GetFileNameForKey(const std::string& key, FilePath* filename) { |
| 57 // Allows only non-empty keys containing [A-Za-z0-9_-]. | 58 // Allows only non-empty keys containing [A-Za-z0-9_-]. |
| 58 TEST_AND_RETURN_FALSE(!key.empty()); | 59 TEST_AND_RETURN_FALSE(!key.empty()); |
| 59 for (size_t i = 0; i < key.size(); ++i) { | 60 for (size_t i = 0; i < key.size(); ++i) { |
| 60 char c = key.at(i); | 61 char c = key.at(i); |
| 61 TEST_AND_RETURN_FALSE(IsAsciiAlpha(c) || IsAsciiDigit(c) || | 62 TEST_AND_RETURN_FALSE(IsAsciiAlpha(c) || IsAsciiDigit(c) || |
| 62 c == '_' || c == '-'); | 63 c == '_' || c == '-'); |
| 63 } | 64 } |
| 64 *filename = prefs_dir_.Append(key); | 65 *filename = prefs_dir_.Append(key); |
| 65 return true; | 66 return true; |
| 66 } | 67 } |
| 67 | 68 |
| 68 } // namespace chromeos_update_engine | 69 } // namespace chromeos_update_engine |
| OLD | NEW |