Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_TEST_RUNNER_TRACKED_DICTIONARY_H_ | |
| 6 #define COMPONENTS_TEST_RUNNER_TRACKED_DICTIONARY_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/values.h" | |
| 13 #include "components/test_runner/test_runner_export.h" | |
| 14 | |
| 15 namespace test_runner { | |
| 16 | |
| 17 class TEST_RUNNER_EXPORT TrackedDictionary { | |
| 18 public: | |
| 19 TrackedDictionary(); | |
| 20 | |
| 21 // Current value of the tracked dictionary. | |
| 22 const base::DictionaryValue& current_values() const { | |
| 23 return current_values_; | |
| 24 } | |
| 25 | |
| 26 // Subset of |current_values| that have been changed (i.e. via Set method) | |
| 27 // since the last call to ResetChangeTracking. | |
| 28 const base::DictionaryValue& changed_values() const { | |
| 29 return changed_values_; | |
| 30 } | |
| 31 | |
| 32 // Clears out |changed_values|. | |
| 33 void ResetChangeTracking(); | |
| 34 | |
| 35 // Overwrites |current_values| with values present in |new_changes|. | |
| 36 // Application of the new values is not tracked - they will not appear in | |
| 37 // |changed_values|. | |
| 38 void ApplyUntrackedChanges(const base::DictionaryValue& new_changes); | |
| 39 | |
| 40 // Sets a value in |current_values| and tracks the change in |changed_values|. | |
| 41 void Set(const std::string& path, scoped_ptr<base::Value> new_value); | |
| 42 | |
| 43 // Type-specific setter for convenience. | |
| 44 void SetBoolean(const std::string& path, bool new_value); | |
| 45 | |
| 46 private: | |
| 47 base::DictionaryValue current_values_; | |
| 48 base::DictionaryValue changed_values_; | |
| 49 | |
| 50 DISALLOW_COPY_AND_ASSIGN(TrackedDictionary); | |
| 51 }; | |
| 52 | |
| 53 } // namespace test_runner | |
| 54 | |
| 55 #endif // COMPONENTS_TEST_RUNNER_TRACKED_DICTIONARY_H_ | |
|
Łukasz Anforowicz
2016/03/03 21:46:34
I like the TrackedDictionary approach:
- This avo
| |
| OLD | NEW |