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 // TrackedDictionary wraps base::DictionaryValue, but forces all mutations to go |
| 18 // through TrackedDictionary's Set methods. This allows tracking of changes |
| 19 // accumulated since the last call to ResetChangeTracking. |
| 20 class TEST_RUNNER_EXPORT TrackedDictionary { |
| 21 public: |
| 22 TrackedDictionary(); |
| 23 |
| 24 // Current value of the tracked dictionary. |
| 25 const base::DictionaryValue& current_values() const { |
| 26 return current_values_; |
| 27 } |
| 28 |
| 29 // Subset of |current_values| that have been changed (i.e. via Set method) |
| 30 // since the last call to ResetChangeTracking. |
| 31 const base::DictionaryValue& changed_values() const { |
| 32 return changed_values_; |
| 33 } |
| 34 |
| 35 // Clears out |changed_values|. |
| 36 void ResetChangeTracking(); |
| 37 |
| 38 // Overwrites |current_values| with values present in |new_changes|. |
| 39 // The new values are not present in |changed_values| afterwards. |
| 40 void ApplyUntrackedChanges(const base::DictionaryValue& new_changes); |
| 41 |
| 42 // Sets a value in |current_values| and tracks the change in |changed_values|. |
| 43 void Set(const std::string& path, scoped_ptr<base::Value> new_value); |
| 44 |
| 45 // Type-specific setter for convenience. |
| 46 void SetBoolean(const std::string& path, bool new_value); |
| 47 |
| 48 private: |
| 49 base::DictionaryValue current_values_; |
| 50 base::DictionaryValue changed_values_; |
| 51 |
| 52 DISALLOW_COPY_AND_ASSIGN(TrackedDictionary); |
| 53 }; |
| 54 |
| 55 } // namespace test_runner |
| 56 |
| 57 #endif // COMPONENTS_TEST_RUNNER_TRACKED_DICTIONARY_H_ |
OLD | NEW |