| 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_number_conversions.h> |
| 10 #include <base/string_util.h> | 10 #include <base/string_util.h> |
| 11 | 11 |
| 12 #include "update_engine/utils.h" | 12 #include "update_engine/utils.h" |
| 13 | 13 |
| 14 using std::string; | 14 using std::string; |
| 15 | 15 |
| 16 namespace chromeos_update_engine { | 16 namespace chromeos_update_engine { |
| 17 | 17 |
| 18 const char kPrefsDeltaUpdateFailures[] = "delta-update-failures"; | 18 const char kPrefsDeltaUpdateFailures[] = "delta-update-failures"; |
| 19 const char kPrefsLastActivePingDay[] = "last-active-ping-day"; | 19 const char kPrefsLastActivePingDay[] = "last-active-ping-day"; |
| 20 const char kPrefsLastRollCallPingDay[] = "last-roll-call-ping-day"; | 20 const char kPrefsLastRollCallPingDay[] = "last-roll-call-ping-day"; |
| 21 const char kPrefsManifestMetadataSize[] = "manifest-metadata-size"; |
| 22 const char kPrefsUpdateCheckResponseHash[] = "update-check-response-hash"; |
| 23 const char kPrefsUpdateStateNextDataOffset[] = "update-state-next-data-offset"; |
| 24 const char kPrefsUpdateStateNextOperation[] = "update-state-next-operation"; |
| 25 const char kPrefsUpdateStateSignedSHA256Context[] = |
| 26 "update-state-signed-sha-256-context"; |
| 21 | 27 |
| 22 bool Prefs::Init(const FilePath& prefs_dir) { | 28 bool Prefs::Init(const FilePath& prefs_dir) { |
| 23 prefs_dir_ = prefs_dir; | 29 prefs_dir_ = prefs_dir; |
| 24 return true; | 30 return true; |
| 25 } | 31 } |
| 26 | 32 |
| 27 bool Prefs::GetString(const string& key, string* value) { | 33 bool Prefs::GetString(const string& key, string* value) { |
| 28 LOG(INFO) << "Getting key \"" << key << "\""; | |
| 29 FilePath filename; | 34 FilePath filename; |
| 30 TEST_AND_RETURN_FALSE(GetFileNameForKey(key, &filename)); | 35 TEST_AND_RETURN_FALSE(GetFileNameForKey(key, &filename)); |
| 31 TEST_AND_RETURN_FALSE(file_util::ReadFileToString(filename, value)); | 36 TEST_AND_RETURN_FALSE(file_util::ReadFileToString(filename, value)); |
| 32 LOG(INFO) << "Key \"" << key << "\" value \"" << *value << "\""; | |
| 33 return true; | 37 return true; |
| 34 } | 38 } |
| 35 | 39 |
| 36 bool Prefs::SetString(const std::string& key, const std::string& value) { | 40 bool Prefs::SetString(const std::string& key, const std::string& value) { |
| 37 LOG(INFO) << "Setting key \"" << key << "\" value \"" << value << "\""; | |
| 38 FilePath filename; | 41 FilePath filename; |
| 39 TEST_AND_RETURN_FALSE(GetFileNameForKey(key, &filename)); | 42 TEST_AND_RETURN_FALSE(GetFileNameForKey(key, &filename)); |
| 40 TEST_AND_RETURN_FALSE(file_util::CreateDirectory(filename.DirName())); | 43 TEST_AND_RETURN_FALSE(file_util::CreateDirectory(filename.DirName())); |
| 41 TEST_AND_RETURN_FALSE( | 44 TEST_AND_RETURN_FALSE( |
| 42 file_util::WriteFile(filename, value.data(), value.size()) == | 45 file_util::WriteFile(filename, value.data(), value.size()) == |
| 43 static_cast<int>(value.size())); | 46 static_cast<int>(value.size())); |
| 44 return true; | 47 return true; |
| 45 } | 48 } |
| 46 | 49 |
| 47 bool Prefs::GetInt64(const string& key, int64_t* value) { | 50 bool Prefs::GetInt64(const string& key, int64_t* value) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 62 for (size_t i = 0; i < key.size(); ++i) { | 65 for (size_t i = 0; i < key.size(); ++i) { |
| 63 char c = key.at(i); | 66 char c = key.at(i); |
| 64 TEST_AND_RETURN_FALSE(IsAsciiAlpha(c) || IsAsciiDigit(c) || | 67 TEST_AND_RETURN_FALSE(IsAsciiAlpha(c) || IsAsciiDigit(c) || |
| 65 c == '_' || c == '-'); | 68 c == '_' || c == '-'); |
| 66 } | 69 } |
| 67 *filename = prefs_dir_.Append(key); | 70 *filename = prefs_dir_.Append(key); |
| 68 return true; | 71 return true; |
| 69 } | 72 } |
| 70 | 73 |
| 71 } // namespace chromeos_update_engine | 74 } // namespace chromeos_update_engine |
| OLD | NEW |