| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_UTILS_H__ | 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_UTILS_H__ |
| 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_UTILS_H__ | 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_UTILS_H__ |
| 7 | 7 |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <string> | 11 #include <string> |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 | 127 |
| 128 template<typename ValueType> | 128 template<typename ValueType> |
| 129 std::set<ValueType> SetWithValue(const ValueType& value) { | 129 std::set<ValueType> SetWithValue(const ValueType& value) { |
| 130 std::set<ValueType> ret; | 130 std::set<ValueType> ret; |
| 131 ret.insert(value); | 131 ret.insert(value); |
| 132 return ret; | 132 return ret; |
| 133 } | 133 } |
| 134 | 134 |
| 135 template<typename T> | 135 template<typename T> |
| 136 bool VectorContainsValue(const std::vector<T>& vect, const T& value) { | 136 bool VectorContainsValue(const std::vector<T>& vect, const T& value) { |
| 137 return std::find(vect.begin(), vect.end(), value) != vect.end(); | 137 return std::find(vect.begin(), vect.end(), value) != vect.end(); |
| 138 } | 138 } |
| 139 | 139 |
| 140 template<typename T> | 140 template<typename T> |
| 141 bool VectorIndexOf(const std::vector<T>& vect, const T& value, | 141 bool VectorIndexOf(const std::vector<T>& vect, const T& value, |
| 142 typename std::vector<T>::size_type* out_index) { | 142 typename std::vector<T>::size_type* out_index) { |
| 143 typename std::vector<T>::const_iterator it = std::find(vect.begin(), | 143 typename std::vector<T>::const_iterator it = std::find(vect.begin(), |
| 144 vect.end(), | 144 vect.end(), |
| 145 value); | 145 value); |
| 146 if (it == vect.end()) { | 146 if (it == vect.end()) { |
| 147 return false; | 147 return false; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 }; | 227 }; |
| 228 | 228 |
| 229 // A little object to call ActionComplete on the ActionProcessor when | 229 // A little object to call ActionComplete on the ActionProcessor when |
| 230 // it's destructed. | 230 // it's destructed. |
| 231 class ScopedActionCompleter { | 231 class ScopedActionCompleter { |
| 232 public: | 232 public: |
| 233 explicit ScopedActionCompleter(ActionProcessor* processor, | 233 explicit ScopedActionCompleter(ActionProcessor* processor, |
| 234 AbstractAction* action) | 234 AbstractAction* action) |
| 235 : processor_(processor), | 235 : processor_(processor), |
| 236 action_(action), | 236 action_(action), |
| 237 success_(false), | 237 code_(kActionCodeError), |
| 238 should_complete_(true) {} | 238 should_complete_(true) {} |
| 239 ~ScopedActionCompleter() { | 239 ~ScopedActionCompleter() { |
| 240 if (should_complete_) | 240 if (should_complete_) |
| 241 processor_->ActionComplete(action_, success_); | 241 processor_->ActionComplete(action_, code_); |
| 242 } | 242 } |
| 243 void set_success(bool success) { | 243 void set_code(ActionExitCode code) { code_ = code; } |
| 244 success_ = success; | |
| 245 } | |
| 246 void set_should_complete(bool should_complete) { | 244 void set_should_complete(bool should_complete) { |
| 247 should_complete_ = should_complete; | 245 should_complete_ = should_complete; |
| 248 } | 246 } |
| 247 |
| 249 private: | 248 private: |
| 250 ActionProcessor* processor_; | 249 ActionProcessor* processor_; |
| 251 AbstractAction* action_; | 250 AbstractAction* action_; |
| 252 bool success_; | 251 ActionExitCode code_; |
| 253 bool should_complete_; | 252 bool should_complete_; |
| 254 DISALLOW_COPY_AND_ASSIGN(ScopedActionCompleter); | 253 DISALLOW_COPY_AND_ASSIGN(ScopedActionCompleter); |
| 255 }; | 254 }; |
| 256 | 255 |
| 257 } // namespace chromeos_update_engine | 256 } // namespace chromeos_update_engine |
| 258 | 257 |
| 259 #define TEST_AND_RETURN_FALSE_ERRNO(_x) \ | 258 #define TEST_AND_RETURN_FALSE_ERRNO(_x) \ |
| 260 do { \ | 259 do { \ |
| 261 bool _success = (_x); \ | 260 bool _success = (_x); \ |
| 262 if (!_success) { \ | 261 if (!_success) { \ |
| (...skipping 29 matching lines...) Expand all Loading... |
| 292 bool _success = (_x); \ | 291 bool _success = (_x); \ |
| 293 if (!_success) { \ | 292 if (!_success) { \ |
| 294 LOG(ERROR) << #_x " failed."; \ | 293 LOG(ERROR) << #_x " failed."; \ |
| 295 return; \ | 294 return; \ |
| 296 } \ | 295 } \ |
| 297 } while (0) | 296 } while (0) |
| 298 | 297 |
| 299 | 298 |
| 300 | 299 |
| 301 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_UTILS_H__ | 300 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_UTILS_H__ |
| OLD | NEW |