OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "sync/internal_api/public/base/model_type_invalidation_map.h" | 5 #include "sync/internal_api/public/base/model_type_invalidation_map.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/json/string_escape.h" | 10 #include "base/json/string_escape.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 ModelTypeSet types; | 28 ModelTypeSet types; |
29 for (ModelTypeInvalidationMap::const_iterator it = invalidation_map.begin(); | 29 for (ModelTypeInvalidationMap::const_iterator it = invalidation_map.begin(); |
30 it != invalidation_map.end(); ++it) { | 30 it != invalidation_map.end(); ++it) { |
31 types.Put(it->first); | 31 types.Put(it->first); |
32 } | 32 } |
33 return types; | 33 return types; |
34 } | 34 } |
35 | 35 |
36 std::string ModelTypeInvalidationMapToString( | 36 std::string ModelTypeInvalidationMapToString( |
37 const ModelTypeInvalidationMap& invalidation_map) { | 37 const ModelTypeInvalidationMap& invalidation_map) { |
38 scoped_ptr<DictionaryValue> value( | 38 scoped_ptr<base::DictionaryValue> value( |
39 ModelTypeInvalidationMapToValue(invalidation_map)); | 39 ModelTypeInvalidationMapToValue(invalidation_map)); |
40 std::string json; | 40 std::string json; |
41 base::JSONWriter::Write(value.get(), &json); | 41 base::JSONWriter::Write(value.get(), &json); |
42 return json; | 42 return json; |
43 } | 43 } |
44 | 44 |
45 DictionaryValue* ModelTypeInvalidationMapToValue( | 45 base::DictionaryValue* ModelTypeInvalidationMapToValue( |
46 const ModelTypeInvalidationMap& invalidation_map) { | 46 const ModelTypeInvalidationMap& invalidation_map) { |
47 DictionaryValue* value = new DictionaryValue(); | 47 base::DictionaryValue* value = new base::DictionaryValue(); |
48 for (ModelTypeInvalidationMap::const_iterator it = invalidation_map.begin(); | 48 for (ModelTypeInvalidationMap::const_iterator it = invalidation_map.begin(); |
49 it != invalidation_map.end(); ++it) { | 49 it != invalidation_map.end(); ++it) { |
50 std::string printable_payload; | 50 std::string printable_payload; |
51 base::JsonDoubleQuote(it->second.payload, | 51 base::JsonDoubleQuote(it->second.payload, |
52 false /* put_in_quotes */, | 52 false /* put_in_quotes */, |
53 &printable_payload); | 53 &printable_payload); |
54 value->SetString(ModelTypeToString(it->first), printable_payload); | 54 value->SetString(ModelTypeToString(it->first), printable_payload); |
55 } | 55 } |
56 return value; | 56 return value; |
57 } | 57 } |
(...skipping 11 matching lines...) Expand all Loading... |
69 (*original)[i->first] = i->second; | 69 (*original)[i->first] = i->second; |
70 } else if (i->second.payload.length() > 0) { | 70 } else if (i->second.payload.length() > 0) { |
71 // If this datatype is already in our map, we only overwrite the | 71 // If this datatype is already in our map, we only overwrite the |
72 // payload if the new one is non-empty. | 72 // payload if the new one is non-empty. |
73 (*original)[i->first].payload = i->second.payload; | 73 (*original)[i->first].payload = i->second.payload; |
74 } | 74 } |
75 } | 75 } |
76 } | 76 } |
77 | 77 |
78 } // namespace syncer | 78 } // namespace syncer |
OLD | NEW |