Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: chrome/browser/sync_file_system/drive_backend/metadata_database_index.cc

Issue 2613223002: Remove ScopedVector from base::JSONValueConverter (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "chrome/browser/sync_file_system/drive_backend/metadata_database_index. h" 5 #include "chrome/browser/sync_file_system/drive_backend/metadata_database_index. h"
6 6
7 #include <tuple> 7 #include <tuple>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 91
92 std::string file_id; 92 std::string file_id;
93 if (RemovePrefix(key, kFileMetadataKeyPrefix, &file_id)) { 93 if (RemovePrefix(key, kFileMetadataKeyPrefix, &file_id)) {
94 std::unique_ptr<FileMetadata> metadata(new FileMetadata); 94 std::unique_ptr<FileMetadata> metadata(new FileMetadata);
95 if (!metadata->ParseFromString(itr->value().ToString())) { 95 if (!metadata->ParseFromString(itr->value().ToString())) {
96 util::Log(logging::LOG_WARNING, FROM_HERE, 96 util::Log(logging::LOG_WARNING, FROM_HERE,
97 "Failed to parse a FileMetadata"); 97 "Failed to parse a FileMetadata");
98 continue; 98 continue;
99 } 99 }
100 100
101 contents->file_metadata.push_back(metadata.release()); 101 contents->file_metadata.push_back(std::move(metadata));
102 continue; 102 continue;
103 } 103 }
104 104
105 std::string tracker_id_str; 105 std::string tracker_id_str;
106 if (RemovePrefix(key, kFileTrackerKeyPrefix, &tracker_id_str)) { 106 if (RemovePrefix(key, kFileTrackerKeyPrefix, &tracker_id_str)) {
107 int64_t tracker_id = 0; 107 int64_t tracker_id = 0;
108 if (!base::StringToInt64(tracker_id_str, &tracker_id)) { 108 if (!base::StringToInt64(tracker_id_str, &tracker_id)) {
109 util::Log(logging::LOG_WARNING, FROM_HERE, 109 util::Log(logging::LOG_WARNING, FROM_HERE,
110 "Failed to parse TrackerID"); 110 "Failed to parse TrackerID");
111 continue; 111 continue;
112 } 112 }
113 113
114 std::unique_ptr<FileTracker> tracker(new FileTracker); 114 std::unique_ptr<FileTracker> tracker(new FileTracker);
115 if (!tracker->ParseFromString(itr->value().ToString())) { 115 if (!tracker->ParseFromString(itr->value().ToString())) {
116 util::Log(logging::LOG_WARNING, FROM_HERE, 116 util::Log(logging::LOG_WARNING, FROM_HERE,
117 "Failed to parse a Tracker"); 117 "Failed to parse a Tracker");
118 continue; 118 continue;
119 } 119 }
120 contents->file_trackers.push_back(tracker.release()); 120 contents->file_trackers.push_back(std::move(tracker));
121 continue; 121 continue;
122 } 122 }
123 } 123 }
124 } 124 }
125 125
126 void RemoveUnreachableItemsFromDB(DatabaseContents* contents, 126 void RemoveUnreachableItemsFromDB(DatabaseContents* contents,
127 int64_t sync_root_tracker_id, 127 int64_t sync_root_tracker_id,
128 LevelDBWrapper* db) { 128 LevelDBWrapper* db) {
129 typedef std::map<int64_t, std::set<int64_t>> ChildTrackersByParent; 129 typedef std::map<int64_t, std::set<int64_t>> ChildTrackersByParent;
130 ChildTrackersByParent trackers_by_parent; 130 ChildTrackersByParent trackers_by_parent;
(...skipping 30 matching lines...) Expand all
161 NOTREACHED(); 161 NOTREACHED();
162 continue; 162 continue;
163 } 163 }
164 164
165 AppendContents( 165 AppendContents(
166 LookUpMap(trackers_by_parent, tracker_id, std::set<int64_t>()), 166 LookUpMap(trackers_by_parent, tracker_id, std::set<int64_t>()),
167 &pending); 167 &pending);
168 } 168 }
169 169
170 // Delete all unreachable trackers. 170 // Delete all unreachable trackers.
171 ScopedVector<FileTracker> reachable_trackers; 171 std::vector<std::unique_ptr<FileTracker>> reachable_trackers;
172 for (size_t i = 0; i < contents->file_trackers.size(); ++i) { 172 for (size_t i = 0; i < contents->file_trackers.size(); ++i) {
173 FileTracker* tracker = contents->file_trackers[i]; 173 FileTracker* tracker = contents->file_trackers[i].get();
174 if (base::ContainsKey(visited_trackers, tracker->tracker_id())) { 174 if (base::ContainsKey(visited_trackers, tracker->tracker_id())) {
175 reachable_trackers.push_back(tracker); 175 reachable_trackers.push_back(base::WrapUnique(tracker));
176 contents->file_trackers[i] = nullptr; 176 contents->file_trackers[i].release();
Avi (use Gerrit) 2017/01/09 17:18:29 Wrapping an existing unique_ptr and then releasing
leonhsl(Using Gerrit) 2017/01/10 04:39:36 Done.
177 } else { 177 } else {
178 PutFileTrackerDeletionToDB(tracker->tracker_id(), db); 178 PutFileTrackerDeletionToDB(tracker->tracker_id(), db);
179 } 179 }
180 } 180 }
181 contents->file_trackers = std::move(reachable_trackers); 181 contents->file_trackers = std::move(reachable_trackers);
182 182
183 // List all |file_id| referred by a tracker. 183 // List all |file_id| referred by a tracker.
184 base::hash_set<std::string> referred_file_ids; 184 base::hash_set<std::string> referred_file_ids;
185 for (size_t i = 0; i < contents->file_trackers.size(); ++i) 185 for (size_t i = 0; i < contents->file_trackers.size(); ++i)
186 referred_file_ids.insert(contents->file_trackers[i]->file_id()); 186 referred_file_ids.insert(contents->file_trackers[i]->file_id());
187 187
188 // Delete all unreferred metadata. 188 // Delete all unreferred metadata.
189 ScopedVector<FileMetadata> referred_file_metadata; 189 std::vector<std::unique_ptr<FileMetadata>> referred_file_metadata;
190 for (size_t i = 0; i < contents->file_metadata.size(); ++i) { 190 for (size_t i = 0; i < contents->file_metadata.size(); ++i) {
191 FileMetadata* metadata = contents->file_metadata[i]; 191 FileMetadata* metadata = contents->file_metadata[i].get();
192 if (base::ContainsKey(referred_file_ids, metadata->file_id())) { 192 if (base::ContainsKey(referred_file_ids, metadata->file_id())) {
193 referred_file_metadata.push_back(metadata); 193 referred_file_metadata.push_back(base::WrapUnique(metadata));
194 contents->file_metadata[i] = nullptr; 194 contents->file_metadata[i].release();
Avi (use Gerrit) 2017/01/09 17:18:29 Same here.
leonhsl(Using Gerrit) 2017/01/10 04:39:36 Done.
195 } else { 195 } else {
196 PutFileMetadataDeletionToDB(metadata->file_id(), db); 196 PutFileMetadataDeletionToDB(metadata->file_id(), db);
197 } 197 }
198 } 198 }
199 contents->file_metadata = std::move(referred_file_metadata); 199 contents->file_metadata = std::move(referred_file_metadata);
200 } 200 }
201 201
202 } // namespace 202 } // namespace
203 203
204 // static 204 // static
(...skipping 26 matching lines...) Expand all
231 index->Initialize(base::WrapUnique(new ServiceMetadata), contents); 231 index->Initialize(base::WrapUnique(new ServiceMetadata), contents);
232 return index; 232 return index;
233 } 233 }
234 234
235 void MetadataDatabaseIndex::Initialize( 235 void MetadataDatabaseIndex::Initialize(
236 std::unique_ptr<ServiceMetadata> service_metadata, 236 std::unique_ptr<ServiceMetadata> service_metadata,
237 DatabaseContents* contents) { 237 DatabaseContents* contents) {
238 service_metadata_ = std::move(service_metadata); 238 service_metadata_ = std::move(service_metadata);
239 239
240 for (size_t i = 0; i < contents->file_metadata.size(); ++i) 240 for (size_t i = 0; i < contents->file_metadata.size(); ++i)
241 StoreFileMetadata(base::WrapUnique(contents->file_metadata[i])); 241 StoreFileMetadata(std::move(contents->file_metadata[i]));
242 contents->file_metadata.weak_clear(); 242 contents->file_metadata.clear();
243 243
244 for (size_t i = 0; i < contents->file_trackers.size(); ++i) 244 for (size_t i = 0; i < contents->file_trackers.size(); ++i)
245 StoreFileTracker(base::WrapUnique(contents->file_trackers[i])); 245 StoreFileTracker(std::move(contents->file_trackers[i]));
246 contents->file_trackers.weak_clear(); 246 contents->file_trackers.clear();
247 247
248 UMA_HISTOGRAM_COUNTS("SyncFileSystem.MetadataNumber", metadata_by_id_.size()); 248 UMA_HISTOGRAM_COUNTS("SyncFileSystem.MetadataNumber", metadata_by_id_.size());
249 UMA_HISTOGRAM_COUNTS("SyncFileSystem.TrackerNumber", tracker_by_id_.size()); 249 UMA_HISTOGRAM_COUNTS("SyncFileSystem.TrackerNumber", tracker_by_id_.size());
250 UMA_HISTOGRAM_COUNTS_100("SyncFileSystem.RegisteredAppNumber", 250 UMA_HISTOGRAM_COUNTS_100("SyncFileSystem.RegisteredAppNumber",
251 app_root_by_app_id_.size()); 251 app_root_by_app_id_.size());
252 } 252 }
253 253
254 MetadataDatabaseIndex::MetadataDatabaseIndex(LevelDBWrapper* db) : db_(db) {} 254 MetadataDatabaseIndex::MetadataDatabaseIndex(LevelDBWrapper* db) : db_(db) {}
255 MetadataDatabaseIndex::~MetadataDatabaseIndex() {} 255 MetadataDatabaseIndex::~MetadataDatabaseIndex() {}
256 256
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 766
767 DVLOG(3) << " Remove from dirty_trackers_: " << tracker_id; 767 DVLOG(3) << " Remove from dirty_trackers_: " << tracker_id;
768 dirty_trackers_.erase(tracker_id); 768 dirty_trackers_.erase(tracker_id);
769 769
770 demoted_dirty_trackers_.erase(tracker_id); 770 demoted_dirty_trackers_.erase(tracker_id);
771 } 771 }
772 } 772 }
773 773
774 } // namespace drive_backend 774 } // namespace drive_backend
775 } // namespace sync_file_system 775 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698