OLD | NEW |
---|---|
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 Loading... | |
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. |
Avi (use Gerrit)
2017/01/09 17:18:29
This code is scaring me, because we should be enfo
| |
119 ScopedVector<google_apis::FileResource> app_root_list; | 120 std::vector<std::unique_ptr<google_apis::FileResource>> app_root_list; |
120 for (size_t i = 0; i < app_roots_count; ++i) { | 121 for (size_t i = 0; i < app_roots_count; ++i) { |
121 app_root_list.push_back( | 122 app_root_list.push_back(base::WrapUnique( |
122 const_cast<google_apis::FileResource*>(app_roots[i])); | 123 const_cast<google_apis::FileResource*>(app_roots[i]))); |
123 } | 124 } |
124 | 125 |
125 status = database->PopulateInitialData( | 126 status = database->PopulateInitialData( |
126 kInitialLargestChangeID, sync_root, app_root_list); | 127 kInitialLargestChangeID, sync_root, app_root_list); |
127 | 128 |
128 app_root_list.weak_clear(); | 129 for_each(app_root_list.begin(), app_root_list.end(), |
130 [](std::unique_ptr<google_apis::FileResource>& entry) { | |
131 entry.release(); | |
132 }); | |
Avi (use Gerrit)
2017/01/09 17:18:29
Yikes, I see what's going on here. We're temporari
leonhsl(Using Gerrit)
2017/01/10 04:39:36
Yeah I understand the concern and I also felt a li
Avi (use Gerrit)
2017/01/10 04:48:40
:\
Can you at least put a TODO(you) there to make
leonhsl(Using Gerrit)
2017/01/10 05:00:39
Done and thank you. I'll start this work soon.
| |
133 app_root_list.clear(); | |
129 return status; | 134 return status; |
130 } | 135 } |
131 | 136 |
132 std::unique_ptr<google_apis::FileResource> CreateRemoteFolder( | 137 std::unique_ptr<google_apis::FileResource> CreateRemoteFolder( |
133 const std::string& parent_folder_id, | 138 const std::string& parent_folder_id, |
134 const std::string& title) { | 139 const std::string& title) { |
135 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; | 140 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; |
136 std::unique_ptr<google_apis::FileResource> entry; | 141 std::unique_ptr<google_apis::FileResource> entry; |
137 drive::AddNewDirectoryOptions options; | 142 drive::AddNewDirectoryOptions options; |
138 options.visibility = google_apis::drive::FILE_VISIBILITY_PRIVATE; | 143 options.visibility = google_apis::drive::FILE_VISIBILITY_PRIVATE; |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
357 | 362 |
358 EXPECT_EQ(0u, CountTrackersForFile(sync_root->file_id())); | 363 EXPECT_EQ(0u, CountTrackersForFile(sync_root->file_id())); |
359 EXPECT_FALSE(HasNoParent(sync_root->file_id())); | 364 EXPECT_FALSE(HasNoParent(sync_root->file_id())); |
360 | 365 |
361 EXPECT_EQ(1u, CountFileMetadata()); | 366 EXPECT_EQ(1u, CountFileMetadata()); |
362 EXPECT_EQ(1u, CountFileTracker()); | 367 EXPECT_EQ(1u, CountFileTracker()); |
363 } | 368 } |
364 | 369 |
365 } // namespace drive_backend | 370 } // namespace drive_backend |
366 } // namespace sync_file_system | 371 } // namespace sync_file_system |
OLD | NEW |