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

Side by Side Diff: chrome/browser/sync_file_system/drive_backend/fake_drive_service_helper.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/fake_drive_service_helpe r.h" 5 #include "chrome/browser/sync_file_system/drive_backend/fake_drive_service_helpe r.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 std::string* sync_root_folder_id) { 210 std::string* sync_root_folder_id) {
211 DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; 211 DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR;
212 std::unique_ptr<FileList> resource_list; 212 std::unique_ptr<FileList> resource_list;
213 fake_drive_service_->SearchByTitle( 213 fake_drive_service_->SearchByTitle(
214 sync_root_folder_title_, std::string(), 214 sync_root_folder_title_, std::string(),
215 CreateResultReceiver(&error, &resource_list)); 215 CreateResultReceiver(&error, &resource_list));
216 base::RunLoop().RunUntilIdle(); 216 base::RunLoop().RunUntilIdle();
217 if (error != google_apis::HTTP_SUCCESS) 217 if (error != google_apis::HTTP_SUCCESS)
218 return error; 218 return error;
219 219
220 const ScopedVector<FileResource>& items = resource_list->items(); 220 const std::vector<std::unique_ptr<FileResource>>& items =
221 for (ScopedVector<FileResource>::const_iterator itr = items.begin(); 221 resource_list->items();
222 itr != items.end(); ++itr) { 222 for (const auto& item : items) {
223 const FileResource& item = **itr; 223 if (item->parents().empty()) {
224 if (item.parents().empty()) { 224 *sync_root_folder_id = item->file_id();
225 *sync_root_folder_id = item.file_id();
226 return google_apis::HTTP_SUCCESS; 225 return google_apis::HTTP_SUCCESS;
227 } 226 }
228 } 227 }
229 return google_apis::HTTP_NOT_FOUND; 228 return google_apis::HTTP_NOT_FOUND;
230 } 229 }
231 230
232 DriveApiErrorCode FakeDriveServiceHelper::ListFilesInFolder( 231 DriveApiErrorCode FakeDriveServiceHelper::ListFilesInFolder(
233 const std::string& folder_id, 232 const std::string& folder_id,
234 ScopedVector<FileResource>* entries) { 233 std::vector<std::unique_ptr<FileResource>>* entries) {
235 DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; 234 DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR;
236 std::unique_ptr<FileList> list; 235 std::unique_ptr<FileList> list;
237 fake_drive_service_->GetFileListInDirectory( 236 fake_drive_service_->GetFileListInDirectory(
238 folder_id, 237 folder_id,
239 CreateResultReceiver(&error, &list)); 238 CreateResultReceiver(&error, &list));
240 base::RunLoop().RunUntilIdle(); 239 base::RunLoop().RunUntilIdle();
241 if (error != google_apis::HTTP_SUCCESS) 240 if (error != google_apis::HTTP_SUCCESS)
242 return error; 241 return error;
243 242
244 return CompleteListing(std::move(list), entries); 243 return CompleteListing(std::move(list), entries);
245 } 244 }
246 245
247 DriveApiErrorCode FakeDriveServiceHelper::SearchByTitle( 246 DriveApiErrorCode FakeDriveServiceHelper::SearchByTitle(
248 const std::string& folder_id, 247 const std::string& folder_id,
249 const std::string& title, 248 const std::string& title,
250 ScopedVector<FileResource>* entries) { 249 std::vector<std::unique_ptr<FileResource>>* entries) {
251 DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; 250 DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR;
252 std::unique_ptr<FileList> list; 251 std::unique_ptr<FileList> list;
253 fake_drive_service_->SearchByTitle( 252 fake_drive_service_->SearchByTitle(
254 title, folder_id, 253 title, folder_id,
255 CreateResultReceiver(&error, &list)); 254 CreateResultReceiver(&error, &list));
256 base::RunLoop().RunUntilIdle(); 255 base::RunLoop().RunUntilIdle();
257 if (error != google_apis::HTTP_SUCCESS) 256 if (error != google_apis::HTTP_SUCCESS)
258 return error; 257 return error;
259 258
260 return CompleteListing(std::move(list), entries); 259 return CompleteListing(std::move(list), entries);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 std::unique_ptr<AboutResource>* about_resource) { 308 std::unique_ptr<AboutResource>* about_resource) {
310 DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; 309 DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR;
311 fake_drive_service_->GetAboutResource( 310 fake_drive_service_->GetAboutResource(
312 CreateResultReceiver(&error, about_resource)); 311 CreateResultReceiver(&error, about_resource));
313 base::RunLoop().RunUntilIdle(); 312 base::RunLoop().RunUntilIdle();
314 return error; 313 return error;
315 } 314 }
316 315
317 DriveApiErrorCode FakeDriveServiceHelper::CompleteListing( 316 DriveApiErrorCode FakeDriveServiceHelper::CompleteListing(
318 std::unique_ptr<FileList> list, 317 std::unique_ptr<FileList> list,
319 ScopedVector<FileResource>* entries) { 318 std::vector<std::unique_ptr<FileResource>>* entries) {
320 while (true) { 319 while (true) {
321 entries->reserve(entries->size() + list->items().size()); 320 entries->reserve(entries->size() + list->items().size());
322 std::vector<FileResource*> tmp; 321 std::move(list->mutable_items()->begin(), list->mutable_items()->end(),
323 list->mutable_items()->release(&tmp); 322 std::back_inserter(*entries));
Avi (use Gerrit) 2017/01/09 17:18:29 Yay move to a back_inserter!
324 for (std::vector<FileResource*>::const_iterator itr = 323 list->mutable_items()->clear();
325 tmp.begin(); itr != tmp.end(); ++itr) {
326 entries->push_back(*itr);
327 }
328 324
329 GURL next_feed = list->next_link(); 325 GURL next_feed = list->next_link();
330 if (next_feed.is_empty()) 326 if (next_feed.is_empty())
331 return google_apis::HTTP_SUCCESS; 327 return google_apis::HTTP_SUCCESS;
332 328
333 DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; 329 DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR;
334 list.reset(); 330 list.reset();
335 fake_drive_service_->GetRemainingFileList( 331 fake_drive_service_->GetRemainingFileList(
336 next_feed, 332 next_feed,
337 CreateResultReceiver(&error, &list)); 333 CreateResultReceiver(&error, &list));
(...skipping 13 matching lines...) Expand all
351 const std::string& content) { 347 const std::string& content) {
352 base::FilePath temp_file; 348 base::FilePath temp_file;
353 EXPECT_TRUE(base::CreateTemporaryFileInDir(temp_dir_, &temp_file)); 349 EXPECT_TRUE(base::CreateTemporaryFileInDir(temp_dir_, &temp_file));
354 EXPECT_EQ(static_cast<int>(content.size()), 350 EXPECT_EQ(static_cast<int>(content.size()),
355 base::WriteFile(temp_file, content.data(), content.size())); 351 base::WriteFile(temp_file, content.data(), content.size()));
356 return temp_file; 352 return temp_file;
357 } 353 }
358 354
359 } // namespace drive_backend 355 } // namespace drive_backend
360 } // namespace sync_file_system 356 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698