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

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

Issue 2613223002: Remove ScopedVector from base::JSONValueConverter (Closed)
Patch Set: Rebase and address comments from mmenke@ 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/sync_engine_initializer. h" 5 #include "chrome/browser/sync_file_system/drive_backend/sync_engine_initializer. h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/files/scoped_temp_dir.h" 12 #include "base/files/scoped_temp_dir.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ptr_util.h"
14 #include "base/run_loop.h" 15 #include "base/run_loop.h"
15 #include "base/threading/thread_task_runner_handle.h" 16 #include "base/threading/thread_task_runner_handle.h"
16 #include "chrome/browser/sync_file_system/drive_backend/drive_backend_constants. h" 17 #include "chrome/browser/sync_file_system/drive_backend/drive_backend_constants. h"
17 #include "chrome/browser/sync_file_system/drive_backend/drive_backend_test_util. h" 18 #include "chrome/browser/sync_file_system/drive_backend/drive_backend_test_util. h"
18 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.h" 19 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.h"
19 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.pb.h" 20 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.pb.h"
20 #include "chrome/browser/sync_file_system/drive_backend/sync_engine_context.h" 21 #include "chrome/browser/sync_file_system/drive_backend/sync_engine_context.h"
21 #include "chrome/browser/sync_file_system/drive_backend/sync_task_manager.h" 22 #include "chrome/browser/sync_file_system/drive_backend/sync_task_manager.h"
22 #include "chrome/browser/sync_file_system/sync_file_system_test_util.h" 23 #include "chrome/browser/sync_file_system/sync_file_system_test_util.h"
23 #include "components/drive/drive_api_util.h" 24 #include "components/drive/drive_api_util.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 SyncStatusCode PopulateDatabase( 108 SyncStatusCode PopulateDatabase(
108 const google_apis::FileResource& sync_root, 109 const google_apis::FileResource& sync_root,
109 const google_apis::FileResource** app_roots, 110 const google_apis::FileResource** app_roots,
110 size_t app_roots_count) { 111 size_t app_roots_count) {
111 SyncStatusCode status = SYNC_STATUS_UNKNOWN; 112 SyncStatusCode status = SYNC_STATUS_UNKNOWN;
112 std::unique_ptr<MetadataDatabase> database = MetadataDatabase::Create( 113 std::unique_ptr<MetadataDatabase> database = MetadataDatabase::Create(
113 database_path(), in_memory_env_.get(), &status); 114 database_path(), in_memory_env_.get(), &status);
114 if (status != SYNC_STATUS_OK) 115 if (status != SYNC_STATUS_OK)
115 return status; 116 return status;
116 117
117 // |app_root_list| must not own the resources here. Be sure to call 118 // |app_root_list| must not own the resources here. Be sure to release
118 // weak_clear later. 119 // ownership of all elements later.
119 ScopedVector<google_apis::FileResource> app_root_list; 120 // TODO(leonhsl) Need follow up: having two owners for a pointer is a
121 // dangerous pattern that we don't want to keep around.
122 std::vector<std::unique_ptr<google_apis::FileResource>> app_root_list;
120 for (size_t i = 0; i < app_roots_count; ++i) { 123 for (size_t i = 0; i < app_roots_count; ++i) {
121 app_root_list.push_back( 124 app_root_list.push_back(base::WrapUnique(
122 const_cast<google_apis::FileResource*>(app_roots[i])); 125 const_cast<google_apis::FileResource*>(app_roots[i])));
123 } 126 }
124 127
125 status = database->PopulateInitialData( 128 status = database->PopulateInitialData(
126 kInitialLargestChangeID, sync_root, app_root_list); 129 kInitialLargestChangeID, sync_root, app_root_list);
127 130
128 app_root_list.weak_clear(); 131 for_each(app_root_list.begin(), app_root_list.end(),
132 [](std::unique_ptr<google_apis::FileResource>& entry) {
133 entry.release();
134 });
135 app_root_list.clear();
129 return status; 136 return status;
130 } 137 }
131 138
132 std::unique_ptr<google_apis::FileResource> CreateRemoteFolder( 139 std::unique_ptr<google_apis::FileResource> CreateRemoteFolder(
133 const std::string& parent_folder_id, 140 const std::string& parent_folder_id,
134 const std::string& title) { 141 const std::string& title) {
135 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; 142 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR;
136 std::unique_ptr<google_apis::FileResource> entry; 143 std::unique_ptr<google_apis::FileResource> entry;
137 drive::AddNewDirectoryOptions options; 144 drive::AddNewDirectoryOptions options;
138 options.visibility = google_apis::drive::FILE_VISIBILITY_PRIVATE; 145 options.visibility = google_apis::drive::FILE_VISIBILITY_PRIVATE;
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 364
358 EXPECT_EQ(0u, CountTrackersForFile(sync_root->file_id())); 365 EXPECT_EQ(0u, CountTrackersForFile(sync_root->file_id()));
359 EXPECT_FALSE(HasNoParent(sync_root->file_id())); 366 EXPECT_FALSE(HasNoParent(sync_root->file_id()));
360 367
361 EXPECT_EQ(1u, CountFileMetadata()); 368 EXPECT_EQ(1u, CountFileMetadata());
362 EXPECT_EQ(1u, CountFileTracker()); 369 EXPECT_EQ(1u, CountFileTracker());
363 } 370 }
364 371
365 } // namespace drive_backend 372 } // namespace drive_backend
366 } // namespace sync_file_system 373 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698