OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/test/fake_server/fake_server.h" | 5 #include "sync/test/fake_server/fake_server.h" |
6 | 6 |
| 7 #include <stdint.h> |
| 8 |
7 #include <algorithm> | 9 #include <algorithm> |
8 #include <limits> | 10 #include <limits> |
9 #include <set> | 11 #include <set> |
10 #include <string> | 12 #include <string> |
11 #include <utility> | 13 #include <utility> |
12 #include <vector> | 14 #include <vector> |
13 | 15 |
14 #include "base/basictypes.h" | |
15 #include "base/guid.h" | 16 #include "base/guid.h" |
16 #include "base/logging.h" | 17 #include "base/logging.h" |
17 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
18 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
19 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
20 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
21 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
22 #include "base/synchronization/lock.h" | 23 #include "base/synchronization/lock.h" |
23 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
24 #include "net/http/http_status_code.h" | 25 #include "net/http/http_status_code.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 ~UpdateSieve() { } | 67 ~UpdateSieve() { } |
67 | 68 |
68 // Factory method for creating an UpdateSieve. | 69 // Factory method for creating an UpdateSieve. |
69 static scoped_ptr<UpdateSieve> Create( | 70 static scoped_ptr<UpdateSieve> Create( |
70 const sync_pb::GetUpdatesMessage& get_updates_message); | 71 const sync_pb::GetUpdatesMessage& get_updates_message); |
71 | 72 |
72 // Sets the progress markers in |get_updates_response| given the progress | 73 // Sets the progress markers in |get_updates_response| given the progress |
73 // markers from the original GetUpdatesMessage and |new_version| (the latest | 74 // markers from the original GetUpdatesMessage and |new_version| (the latest |
74 // version in the entries sent back). | 75 // version in the entries sent back). |
75 void UpdateProgressMarkers( | 76 void UpdateProgressMarkers( |
76 int64 new_version, | 77 int64_t new_version, |
77 sync_pb::GetUpdatesResponse* get_updates_response) const { | 78 sync_pb::GetUpdatesResponse* get_updates_response) const { |
78 ModelTypeToVersionMap::const_iterator it; | 79 ModelTypeToVersionMap::const_iterator it; |
79 for (it = request_from_version_.begin(); it != request_from_version_.end(); | 80 for (it = request_from_version_.begin(); it != request_from_version_.end(); |
80 ++it) { | 81 ++it) { |
81 sync_pb::DataTypeProgressMarker* new_marker = | 82 sync_pb::DataTypeProgressMarker* new_marker = |
82 get_updates_response->add_new_progress_marker(); | 83 get_updates_response->add_new_progress_marker(); |
83 new_marker->set_data_type_id( | 84 new_marker->set_data_type_id( |
84 GetSpecificsFieldNumberFromModelType(it->first)); | 85 GetSpecificsFieldNumberFromModelType(it->first)); |
85 | 86 |
86 int64 version = std::max(new_version, it->second); | 87 int64_t version = std::max(new_version, it->second); |
87 new_marker->set_token(base::Int64ToString(version)); | 88 new_marker->set_token(base::Int64ToString(version)); |
88 } | 89 } |
89 } | 90 } |
90 | 91 |
91 // Determines whether the server should send an |entity| to the client as | 92 // Determines whether the server should send an |entity| to the client as |
92 // part of a GetUpdatesResponse. | 93 // part of a GetUpdatesResponse. |
93 bool ClientWantsItem(const FakeServerEntity& entity) const { | 94 bool ClientWantsItem(const FakeServerEntity& entity) const { |
94 int64 version = entity.GetVersion(); | 95 int64_t version = entity.GetVersion(); |
95 if (version <= min_version_) { | 96 if (version <= min_version_) { |
96 return false; | 97 return false; |
97 } else if (entity.IsDeleted()) { | 98 } else if (entity.IsDeleted()) { |
98 return true; | 99 return true; |
99 } | 100 } |
100 | 101 |
101 ModelTypeToVersionMap::const_iterator it = | 102 ModelTypeToVersionMap::const_iterator it = |
102 request_from_version_.find(entity.GetModelType()); | 103 request_from_version_.find(entity.GetModelType()); |
103 | 104 |
104 return it == request_from_version_.end() ? false : it->second < version; | 105 return it == request_from_version_.end() ? false : it->second < version; |
105 } | 106 } |
106 | 107 |
107 // Returns the minimum version seen across all types. | 108 // Returns the minimum version seen across all types. |
108 int64 GetMinVersion() const { | 109 int64_t GetMinVersion() const { return min_version_; } |
109 return min_version_; | |
110 } | |
111 | 110 |
112 private: | 111 private: |
113 typedef std::map<ModelType, int64> ModelTypeToVersionMap; | 112 typedef std::map<ModelType, int64_t> ModelTypeToVersionMap; |
114 | 113 |
115 // Creates an UpdateSieve. | 114 // Creates an UpdateSieve. |
116 UpdateSieve(const ModelTypeToVersionMap request_from_version, | 115 UpdateSieve(const ModelTypeToVersionMap request_from_version, |
117 const int64 min_version) | 116 const int64_t min_version) |
118 : request_from_version_(request_from_version), | 117 : request_from_version_(request_from_version), |
119 min_version_(min_version) { } | 118 min_version_(min_version) {} |
120 | 119 |
121 // Maps data type IDs to the latest version seen for that type. | 120 // Maps data type IDs to the latest version seen for that type. |
122 const ModelTypeToVersionMap request_from_version_; | 121 const ModelTypeToVersionMap request_from_version_; |
123 | 122 |
124 // The minimum version seen among all data types. | 123 // The minimum version seen among all data types. |
125 const int min_version_; | 124 const int min_version_; |
126 }; | 125 }; |
127 | 126 |
128 scoped_ptr<UpdateSieve> UpdateSieve::Create( | 127 scoped_ptr<UpdateSieve> UpdateSieve::Create( |
129 const sync_pb::GetUpdatesMessage& get_updates_message) { | 128 const sync_pb::GetUpdatesMessage& get_updates_message) { |
130 CHECK_GT(get_updates_message.from_progress_marker_size(), 0) | 129 CHECK_GT(get_updates_message.from_progress_marker_size(), 0) |
131 << "A GetUpdates request must have at least one progress marker."; | 130 << "A GetUpdates request must have at least one progress marker."; |
132 | 131 |
133 UpdateSieve::ModelTypeToVersionMap request_from_version; | 132 UpdateSieve::ModelTypeToVersionMap request_from_version; |
134 int64 min_version = std::numeric_limits<int64>::max(); | 133 int64_t min_version = std::numeric_limits<int64_t>::max(); |
135 for (int i = 0; i < get_updates_message.from_progress_marker_size(); i++) { | 134 for (int i = 0; i < get_updates_message.from_progress_marker_size(); i++) { |
136 sync_pb::DataTypeProgressMarker marker = | 135 sync_pb::DataTypeProgressMarker marker = |
137 get_updates_message.from_progress_marker(i); | 136 get_updates_message.from_progress_marker(i); |
138 | 137 |
139 int64 version = 0; | 138 int64_t version = 0; |
140 // Let the version remain zero if there is no token or an empty token (the | 139 // Let the version remain zero if there is no token or an empty token (the |
141 // first request for this type). | 140 // first request for this type). |
142 if (marker.has_token() && !marker.token().empty()) { | 141 if (marker.has_token() && !marker.token().empty()) { |
143 bool parsed = base::StringToInt64(marker.token(), &version); | 142 bool parsed = base::StringToInt64(marker.token(), &version); |
144 CHECK(parsed) << "Unable to parse progress marker token."; | 143 CHECK(parsed) << "Unable to parse progress marker token."; |
145 } | 144 } |
146 | 145 |
147 ModelType model_type = syncer::GetModelTypeFromSpecificsFieldNumber( | 146 ModelType model_type = syncer::GetModelTypeFromSpecificsFieldNumber( |
148 marker.data_type_id()); | 147 marker.data_type_id()); |
149 request_from_version[model_type] = version; | 148 request_from_version[model_type] = version; |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 | 330 |
332 // This folder is called "Synced Bookmarks" by sync and is renamed | 331 // This folder is called "Synced Bookmarks" by sync and is renamed |
333 // "Mobile Bookmarks" by the mobile client UIs. | 332 // "Mobile Bookmarks" by the mobile client UIs. |
334 if (get_updates.create_mobile_bookmarks_folder() && | 333 if (get_updates.create_mobile_bookmarks_folder() && |
335 !CreatePermanentBookmarkFolder(kSyncedBookmarksFolderServerTag, | 334 !CreatePermanentBookmarkFolder(kSyncedBookmarksFolderServerTag, |
336 kSyncedBookmarksFolderName)) { | 335 kSyncedBookmarksFolderName)) { |
337 return false; | 336 return false; |
338 } | 337 } |
339 | 338 |
340 bool send_encryption_keys_based_on_nigori = false; | 339 bool send_encryption_keys_based_on_nigori = false; |
341 int64 max_response_version = 0; | 340 int64_t max_response_version = 0; |
342 for (EntityMap::const_iterator it = entities_.begin(); it != entities_.end(); | 341 for (EntityMap::const_iterator it = entities_.begin(); it != entities_.end(); |
343 ++it) { | 342 ++it) { |
344 const FakeServerEntity& entity = *it->second; | 343 const FakeServerEntity& entity = *it->second; |
345 if (sieve->ClientWantsItem(entity)) { | 344 if (sieve->ClientWantsItem(entity)) { |
346 sync_pb::SyncEntity* response_entity = response->add_entries(); | 345 sync_pb::SyncEntity* response_entity = response->add_entries(); |
347 entity.SerializeAsProto(response_entity); | 346 entity.SerializeAsProto(response_entity); |
348 | 347 |
349 max_response_version = std::max(max_response_version, | 348 max_response_version = std::max(max_response_version, |
350 response_entity->version()); | 349 response_entity->version()); |
351 | 350 |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 DCHECK(thread_checker_.CalledOnValidThread()); | 705 DCHECK(thread_checker_.CalledOnValidThread()); |
707 return weak_ptr_factory_.GetWeakPtr(); | 706 return weak_ptr_factory_.GetWeakPtr(); |
708 } | 707 } |
709 | 708 |
710 std::string FakeServer::GetStoreBirthday() const { | 709 std::string FakeServer::GetStoreBirthday() const { |
711 DCHECK(thread_checker_.CalledOnValidThread()); | 710 DCHECK(thread_checker_.CalledOnValidThread()); |
712 return base::Int64ToString(store_birthday_); | 711 return base::Int64ToString(store_birthday_); |
713 } | 712 } |
714 | 713 |
715 } // namespace fake_server | 714 } // namespace fake_server |
OLD | NEW |