| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/chromeos/drive/fake_file_system.h" | 5 #include "chrome/browser/chromeos/drive/fake_file_system.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 FakeFileSystem::FakeFileSystem(DriveServiceInterface* drive_service) | 26 FakeFileSystem::FakeFileSystem(DriveServiceInterface* drive_service) |
| 27 : drive_service_(drive_service), | 27 : drive_service_(drive_service), |
| 28 weak_ptr_factory_(this) { | 28 weak_ptr_factory_(this) { |
| 29 CHECK(cache_dir_.CreateUniqueTempDir()); | 29 CHECK(cache_dir_.CreateUniqueTempDir()); |
| 30 } | 30 } |
| 31 | 31 |
| 32 FakeFileSystem::~FakeFileSystem() { | 32 FakeFileSystem::~FakeFileSystem() { |
| 33 } | 33 } |
| 34 | 34 |
| 35 void FakeFileSystem::AddObserver(FileSystemObserver* observer) { | 35 void FakeFileSystem::AddObserver(FileSystemObserver* observer) { |
| 36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 36 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 37 } | 37 } |
| 38 | 38 |
| 39 void FakeFileSystem::RemoveObserver(FileSystemObserver* observer) { | 39 void FakeFileSystem::RemoveObserver(FileSystemObserver* observer) { |
| 40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 40 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 41 } | 41 } |
| 42 | 42 |
| 43 void FakeFileSystem::CheckForUpdates() { | 43 void FakeFileSystem::CheckForUpdates() { |
| 44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 44 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void FakeFileSystem::TransferFileFromLocalToRemote( | 47 void FakeFileSystem::TransferFileFromLocalToRemote( |
| 48 const base::FilePath& local_src_file_path, | 48 const base::FilePath& local_src_file_path, |
| 49 const base::FilePath& remote_dest_file_path, | 49 const base::FilePath& remote_dest_file_path, |
| 50 const FileOperationCallback& callback) { | 50 const FileOperationCallback& callback) { |
| 51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 51 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 52 } | 52 } |
| 53 | 53 |
| 54 void FakeFileSystem::OpenFile(const base::FilePath& file_path, | 54 void FakeFileSystem::OpenFile(const base::FilePath& file_path, |
| 55 OpenMode open_mode, | 55 OpenMode open_mode, |
| 56 const std::string& mime_type, | 56 const std::string& mime_type, |
| 57 const OpenFileCallback& callback) { | 57 const OpenFileCallback& callback) { |
| 58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 58 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void FakeFileSystem::Copy(const base::FilePath& src_file_path, | 61 void FakeFileSystem::Copy(const base::FilePath& src_file_path, |
| 62 const base::FilePath& dest_file_path, | 62 const base::FilePath& dest_file_path, |
| 63 bool preserve_last_modified, | 63 bool preserve_last_modified, |
| 64 const FileOperationCallback& callback) { | 64 const FileOperationCallback& callback) { |
| 65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 65 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void FakeFileSystem::Move(const base::FilePath& src_file_path, | 68 void FakeFileSystem::Move(const base::FilePath& src_file_path, |
| 69 const base::FilePath& dest_file_path, | 69 const base::FilePath& dest_file_path, |
| 70 const FileOperationCallback& callback) { | 70 const FileOperationCallback& callback) { |
| 71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 71 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 72 } | 72 } |
| 73 | 73 |
| 74 void FakeFileSystem::Remove(const base::FilePath& file_path, | 74 void FakeFileSystem::Remove(const base::FilePath& file_path, |
| 75 bool is_recursive, | 75 bool is_recursive, |
| 76 const FileOperationCallback& callback) { | 76 const FileOperationCallback& callback) { |
| 77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 77 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 78 } | 78 } |
| 79 | 79 |
| 80 void FakeFileSystem::CreateDirectory( | 80 void FakeFileSystem::CreateDirectory( |
| 81 const base::FilePath& directory_path, | 81 const base::FilePath& directory_path, |
| 82 bool is_exclusive, | 82 bool is_exclusive, |
| 83 bool is_recursive, | 83 bool is_recursive, |
| 84 const FileOperationCallback& callback) { | 84 const FileOperationCallback& callback) { |
| 85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 85 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 86 } | 86 } |
| 87 | 87 |
| 88 void FakeFileSystem::CreateFile(const base::FilePath& file_path, | 88 void FakeFileSystem::CreateFile(const base::FilePath& file_path, |
| 89 bool is_exclusive, | 89 bool is_exclusive, |
| 90 const std::string& mime_type, | 90 const std::string& mime_type, |
| 91 const FileOperationCallback& callback) { | 91 const FileOperationCallback& callback) { |
| 92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 92 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 93 } | 93 } |
| 94 | 94 |
| 95 void FakeFileSystem::TouchFile(const base::FilePath& file_path, | 95 void FakeFileSystem::TouchFile(const base::FilePath& file_path, |
| 96 const base::Time& last_access_time, | 96 const base::Time& last_access_time, |
| 97 const base::Time& last_modified_time, | 97 const base::Time& last_modified_time, |
| 98 const FileOperationCallback& callback) { | 98 const FileOperationCallback& callback) { |
| 99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 99 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 100 } | 100 } |
| 101 | 101 |
| 102 void FakeFileSystem::TruncateFile(const base::FilePath& file_path, | 102 void FakeFileSystem::TruncateFile(const base::FilePath& file_path, |
| 103 int64 length, | 103 int64 length, |
| 104 const FileOperationCallback& callback) { | 104 const FileOperationCallback& callback) { |
| 105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 105 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 106 } | 106 } |
| 107 | 107 |
| 108 void FakeFileSystem::Pin(const base::FilePath& file_path, | 108 void FakeFileSystem::Pin(const base::FilePath& file_path, |
| 109 const FileOperationCallback& callback) { | 109 const FileOperationCallback& callback) { |
| 110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 110 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 111 } | 111 } |
| 112 | 112 |
| 113 void FakeFileSystem::Unpin(const base::FilePath& file_path, | 113 void FakeFileSystem::Unpin(const base::FilePath& file_path, |
| 114 const FileOperationCallback& callback) { | 114 const FileOperationCallback& callback) { |
| 115 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 115 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 116 } | 116 } |
| 117 | 117 |
| 118 void FakeFileSystem::GetFile(const base::FilePath& file_path, | 118 void FakeFileSystem::GetFile(const base::FilePath& file_path, |
| 119 const GetFileCallback& callback) { | 119 const GetFileCallback& callback) { |
| 120 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 120 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 121 } | 121 } |
| 122 | 122 |
| 123 void FakeFileSystem::GetFileForSaving(const base::FilePath& file_path, | 123 void FakeFileSystem::GetFileForSaving(const base::FilePath& file_path, |
| 124 const GetFileCallback& callback) { | 124 const GetFileCallback& callback) { |
| 125 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 125 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 126 } | 126 } |
| 127 | 127 |
| 128 base::Closure FakeFileSystem::GetFileContent( | 128 base::Closure FakeFileSystem::GetFileContent( |
| 129 const base::FilePath& file_path, | 129 const base::FilePath& file_path, |
| 130 const GetFileContentInitializedCallback& initialized_callback, | 130 const GetFileContentInitializedCallback& initialized_callback, |
| 131 const google_apis::GetContentCallback& get_content_callback, | 131 const google_apis::GetContentCallback& get_content_callback, |
| 132 const FileOperationCallback& completion_callback) { | 132 const FileOperationCallback& completion_callback) { |
| 133 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 133 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 134 | 134 |
| 135 GetResourceEntry( | 135 GetResourceEntry( |
| 136 file_path, | 136 file_path, |
| 137 base::Bind(&FakeFileSystem::GetFileContentAfterGetResourceEntry, | 137 base::Bind(&FakeFileSystem::GetFileContentAfterGetResourceEntry, |
| 138 weak_ptr_factory_.GetWeakPtr(), | 138 weak_ptr_factory_.GetWeakPtr(), |
| 139 initialized_callback, get_content_callback, | 139 initialized_callback, get_content_callback, |
| 140 completion_callback)); | 140 completion_callback)); |
| 141 return base::Bind(&base::DoNothing); | 141 return base::Bind(&base::DoNothing); |
| 142 } | 142 } |
| 143 | 143 |
| 144 void FakeFileSystem::GetResourceEntry( | 144 void FakeFileSystem::GetResourceEntry( |
| 145 const base::FilePath& file_path, | 145 const base::FilePath& file_path, |
| 146 const GetResourceEntryCallback& callback) { | 146 const GetResourceEntryCallback& callback) { |
| 147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 147 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 148 | 148 |
| 149 if (file_path == util::GetDriveMyDriveRootPath()) { | 149 if (file_path == util::GetDriveMyDriveRootPath()) { |
| 150 // Specialized for the root entry. | 150 // Specialized for the root entry. |
| 151 drive_service_->GetAboutResource( | 151 drive_service_->GetAboutResource( |
| 152 base::Bind( | 152 base::Bind( |
| 153 &FakeFileSystem::GetResourceEntryAfterGetAboutResource, | 153 &FakeFileSystem::GetResourceEntryAfterGetAboutResource, |
| 154 weak_ptr_factory_.GetWeakPtr(), callback)); | 154 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 155 return; | 155 return; |
| 156 } | 156 } |
| 157 | 157 |
| 158 // Now, we only support files under my drive. | 158 // Now, we only support files under my drive. |
| 159 DCHECK(util::GetDriveMyDriveRootPath().IsParent(file_path)); | 159 DCHECK(util::GetDriveMyDriveRootPath().IsParent(file_path)); |
| 160 GetResourceEntry( | 160 GetResourceEntry( |
| 161 file_path.DirName(), | 161 file_path.DirName(), |
| 162 base::Bind( | 162 base::Bind( |
| 163 &FakeFileSystem::GetResourceEntryAfterGetParentEntryInfo, | 163 &FakeFileSystem::GetResourceEntryAfterGetParentEntryInfo, |
| 164 weak_ptr_factory_.GetWeakPtr(), file_path.BaseName(), callback)); | 164 weak_ptr_factory_.GetWeakPtr(), file_path.BaseName(), callback)); |
| 165 } | 165 } |
| 166 | 166 |
| 167 void FakeFileSystem::ReadDirectory( | 167 void FakeFileSystem::ReadDirectory( |
| 168 const base::FilePath& file_path, | 168 const base::FilePath& file_path, |
| 169 const ReadDirectoryEntriesCallback& entries_callback, | 169 const ReadDirectoryEntriesCallback& entries_callback, |
| 170 const FileOperationCallback& completion_callback) { | 170 const FileOperationCallback& completion_callback) { |
| 171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 171 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 172 } | 172 } |
| 173 | 173 |
| 174 void FakeFileSystem::Search(const std::string& search_query, | 174 void FakeFileSystem::Search(const std::string& search_query, |
| 175 const GURL& next_link, | 175 const GURL& next_link, |
| 176 const SearchCallback& callback) { | 176 const SearchCallback& callback) { |
| 177 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 177 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 178 } | 178 } |
| 179 | 179 |
| 180 void FakeFileSystem::SearchMetadata( | 180 void FakeFileSystem::SearchMetadata( |
| 181 const std::string& query, | 181 const std::string& query, |
| 182 int options, | 182 int options, |
| 183 int at_most_num_matches, | 183 int at_most_num_matches, |
| 184 const SearchMetadataCallback& callback) { | 184 const SearchMetadataCallback& callback) { |
| 185 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 185 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 186 } | 186 } |
| 187 | 187 |
| 188 void FakeFileSystem::SearchByHashes(const std::set<std::string>& hashes, | 188 void FakeFileSystem::SearchByHashes(const std::set<std::string>& hashes, |
| 189 const SearchByHashesCallback& callback) { | 189 const SearchByHashesCallback& callback) { |
| 190 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 190 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 191 } | 191 } |
| 192 | 192 |
| 193 void FakeFileSystem::GetAvailableSpace( | 193 void FakeFileSystem::GetAvailableSpace( |
| 194 const GetAvailableSpaceCallback& callback) { | 194 const GetAvailableSpaceCallback& callback) { |
| 195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 195 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 196 } | 196 } |
| 197 | 197 |
| 198 void FakeFileSystem::GetShareUrl( | 198 void FakeFileSystem::GetShareUrl( |
| 199 const base::FilePath& file_path, | 199 const base::FilePath& file_path, |
| 200 const GURL& embed_origin, | 200 const GURL& embed_origin, |
| 201 const GetShareUrlCallback& callback) { | 201 const GetShareUrlCallback& callback) { |
| 202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 202 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 203 } | 203 } |
| 204 | 204 |
| 205 void FakeFileSystem::GetMetadata( | 205 void FakeFileSystem::GetMetadata( |
| 206 const GetFilesystemMetadataCallback& callback) { | 206 const GetFilesystemMetadataCallback& callback) { |
| 207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 207 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 208 } | 208 } |
| 209 | 209 |
| 210 void FakeFileSystem::MarkCacheFileAsMounted( | 210 void FakeFileSystem::MarkCacheFileAsMounted( |
| 211 const base::FilePath& drive_file_path, | 211 const base::FilePath& drive_file_path, |
| 212 const MarkMountedCallback& callback) { | 212 const MarkMountedCallback& callback) { |
| 213 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 213 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 214 } | 214 } |
| 215 | 215 |
| 216 void FakeFileSystem::MarkCacheFileAsUnmounted( | 216 void FakeFileSystem::MarkCacheFileAsUnmounted( |
| 217 const base::FilePath& cache_file_path, | 217 const base::FilePath& cache_file_path, |
| 218 const FileOperationCallback& callback) { | 218 const FileOperationCallback& callback) { |
| 219 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 219 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 220 } | 220 } |
| 221 | 221 |
| 222 void FakeFileSystem::AddPermission(const base::FilePath& drive_file_path, | 222 void FakeFileSystem::AddPermission(const base::FilePath& drive_file_path, |
| 223 const std::string& email, | 223 const std::string& email, |
| 224 google_apis::drive::PermissionRole role, | 224 google_apis::drive::PermissionRole role, |
| 225 const FileOperationCallback& callback) { | 225 const FileOperationCallback& callback) { |
| 226 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 226 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 227 } | 227 } |
| 228 | 228 |
| 229 void FakeFileSystem::SetProperty( | 229 void FakeFileSystem::SetProperty( |
| 230 const base::FilePath& drive_file_path, | 230 const base::FilePath& drive_file_path, |
| 231 google_apis::drive::Property::Visibility visibility, | 231 google_apis::drive::Property::Visibility visibility, |
| 232 const std::string& key, | 232 const std::string& key, |
| 233 const std::string& value, | 233 const std::string& value, |
| 234 const FileOperationCallback& callback) { | 234 const FileOperationCallback& callback) { |
| 235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 235 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 236 } | 236 } |
| 237 | 237 |
| 238 void FakeFileSystem::Reset(const FileOperationCallback& callback) { | 238 void FakeFileSystem::Reset(const FileOperationCallback& callback) { |
| 239 } | 239 } |
| 240 | 240 |
| 241 void FakeFileSystem::GetPathFromResourceId( | 241 void FakeFileSystem::GetPathFromResourceId( |
| 242 const std::string& resource_id, | 242 const std::string& resource_id, |
| 243 const GetFilePathCallback& callback) { | 243 const GetFilePathCallback& callback) { |
| 244 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 244 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 245 } | 245 } |
| 246 | 246 |
| 247 void FakeFileSystem::FreeDiskSpaceIfNeededFor( | 247 void FakeFileSystem::FreeDiskSpaceIfNeededFor( |
| 248 int64 num_bytes, | 248 int64 num_bytes, |
| 249 const FreeDiskSpaceCallback& callback) { | 249 const FreeDiskSpaceCallback& callback) { |
| 250 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 250 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 251 } | 251 } |
| 252 | 252 |
| 253 // Implementation of GetFileContent. | 253 // Implementation of GetFileContent. |
| 254 void FakeFileSystem::GetFileContentAfterGetResourceEntry( | 254 void FakeFileSystem::GetFileContentAfterGetResourceEntry( |
| 255 const GetFileContentInitializedCallback& initialized_callback, | 255 const GetFileContentInitializedCallback& initialized_callback, |
| 256 const google_apis::GetContentCallback& get_content_callback, | 256 const google_apis::GetContentCallback& get_content_callback, |
| 257 const FileOperationCallback& completion_callback, | 257 const FileOperationCallback& completion_callback, |
| 258 FileError error, | 258 FileError error, |
| 259 scoped_ptr<ResourceEntry> entry) { | 259 scoped_ptr<ResourceEntry> entry) { |
| 260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 260 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 261 | 261 |
| 262 if (error != FILE_ERROR_OK) { | 262 if (error != FILE_ERROR_OK) { |
| 263 completion_callback.Run(error); | 263 completion_callback.Run(error); |
| 264 return; | 264 return; |
| 265 } | 265 } |
| 266 DCHECK(entry); | 266 DCHECK(entry); |
| 267 | 267 |
| 268 // We're only interested in a file. | 268 // We're only interested in a file. |
| 269 if (entry->file_info().is_directory()) { | 269 if (entry->file_info().is_directory()) { |
| 270 completion_callback.Run(FILE_ERROR_NOT_A_FILE); | 270 completion_callback.Run(FILE_ERROR_NOT_A_FILE); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 281 get_content_callback, | 281 get_content_callback, |
| 282 completion_callback)); | 282 completion_callback)); |
| 283 } | 283 } |
| 284 | 284 |
| 285 void FakeFileSystem::GetFileContentAfterGetFileResource( | 285 void FakeFileSystem::GetFileContentAfterGetFileResource( |
| 286 const GetFileContentInitializedCallback& initialized_callback, | 286 const GetFileContentInitializedCallback& initialized_callback, |
| 287 const google_apis::GetContentCallback& get_content_callback, | 287 const google_apis::GetContentCallback& get_content_callback, |
| 288 const FileOperationCallback& completion_callback, | 288 const FileOperationCallback& completion_callback, |
| 289 google_apis::DriveApiErrorCode gdata_error, | 289 google_apis::DriveApiErrorCode gdata_error, |
| 290 scoped_ptr<google_apis::FileResource> gdata_entry) { | 290 scoped_ptr<google_apis::FileResource> gdata_entry) { |
| 291 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 291 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 292 | 292 |
| 293 FileError error = GDataToFileError(gdata_error); | 293 FileError error = GDataToFileError(gdata_error); |
| 294 if (error != FILE_ERROR_OK) { | 294 if (error != FILE_ERROR_OK) { |
| 295 completion_callback.Run(error); | 295 completion_callback.Run(error); |
| 296 return; | 296 return; |
| 297 } | 297 } |
| 298 DCHECK(gdata_entry); | 298 DCHECK(gdata_entry); |
| 299 | 299 |
| 300 scoped_ptr<ResourceEntry> entry(new ResourceEntry); | 300 scoped_ptr<ResourceEntry> entry(new ResourceEntry); |
| 301 std::string parent_resource_id; | 301 std::string parent_resource_id; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 326 weak_ptr_factory_.GetWeakPtr(), | 326 weak_ptr_factory_.GetWeakPtr(), |
| 327 completion_callback), | 327 completion_callback), |
| 328 get_content_callback, | 328 get_content_callback, |
| 329 google_apis::ProgressCallback()); | 329 google_apis::ProgressCallback()); |
| 330 } | 330 } |
| 331 | 331 |
| 332 void FakeFileSystem::GetFileContentAfterDownloadFile( | 332 void FakeFileSystem::GetFileContentAfterDownloadFile( |
| 333 const FileOperationCallback& completion_callback, | 333 const FileOperationCallback& completion_callback, |
| 334 google_apis::DriveApiErrorCode gdata_error, | 334 google_apis::DriveApiErrorCode gdata_error, |
| 335 const base::FilePath& temp_file) { | 335 const base::FilePath& temp_file) { |
| 336 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 336 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 337 completion_callback.Run(GDataToFileError(gdata_error)); | 337 completion_callback.Run(GDataToFileError(gdata_error)); |
| 338 } | 338 } |
| 339 | 339 |
| 340 // Implementation of GetResourceEntry. | 340 // Implementation of GetResourceEntry. |
| 341 void FakeFileSystem::GetResourceEntryAfterGetAboutResource( | 341 void FakeFileSystem::GetResourceEntryAfterGetAboutResource( |
| 342 const GetResourceEntryCallback& callback, | 342 const GetResourceEntryCallback& callback, |
| 343 google_apis::DriveApiErrorCode gdata_error, | 343 google_apis::DriveApiErrorCode gdata_error, |
| 344 scoped_ptr<google_apis::AboutResource> about_resource) { | 344 scoped_ptr<google_apis::AboutResource> about_resource) { |
| 345 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 345 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 346 | 346 |
| 347 FileError error = GDataToFileError(gdata_error); | 347 FileError error = GDataToFileError(gdata_error); |
| 348 if (error != FILE_ERROR_OK) { | 348 if (error != FILE_ERROR_OK) { |
| 349 callback.Run(error, scoped_ptr<ResourceEntry>()); | 349 callback.Run(error, scoped_ptr<ResourceEntry>()); |
| 350 return; | 350 return; |
| 351 } | 351 } |
| 352 | 352 |
| 353 DCHECK(about_resource); | 353 DCHECK(about_resource); |
| 354 scoped_ptr<ResourceEntry> root(new ResourceEntry); | 354 scoped_ptr<ResourceEntry> root(new ResourceEntry); |
| 355 root->mutable_file_info()->set_is_directory(true); | 355 root->mutable_file_info()->set_is_directory(true); |
| 356 root->set_resource_id(about_resource->root_folder_id()); | 356 root->set_resource_id(about_resource->root_folder_id()); |
| 357 root->set_title(util::kDriveMyDriveRootDirName); | 357 root->set_title(util::kDriveMyDriveRootDirName); |
| 358 callback.Run(error, root.Pass()); | 358 callback.Run(error, root.Pass()); |
| 359 } | 359 } |
| 360 | 360 |
| 361 void FakeFileSystem::GetResourceEntryAfterGetParentEntryInfo( | 361 void FakeFileSystem::GetResourceEntryAfterGetParentEntryInfo( |
| 362 const base::FilePath& base_name, | 362 const base::FilePath& base_name, |
| 363 const GetResourceEntryCallback& callback, | 363 const GetResourceEntryCallback& callback, |
| 364 FileError error, | 364 FileError error, |
| 365 scoped_ptr<ResourceEntry> parent_entry) { | 365 scoped_ptr<ResourceEntry> parent_entry) { |
| 366 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 366 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 367 | 367 |
| 368 if (error != FILE_ERROR_OK) { | 368 if (error != FILE_ERROR_OK) { |
| 369 callback.Run(error, scoped_ptr<ResourceEntry>()); | 369 callback.Run(error, scoped_ptr<ResourceEntry>()); |
| 370 return; | 370 return; |
| 371 } | 371 } |
| 372 | 372 |
| 373 DCHECK(parent_entry); | 373 DCHECK(parent_entry); |
| 374 drive_service_->GetFileListInDirectory( | 374 drive_service_->GetFileListInDirectory( |
| 375 parent_entry->resource_id(), | 375 parent_entry->resource_id(), |
| 376 base::Bind( | 376 base::Bind( |
| 377 &FakeFileSystem::GetResourceEntryAfterGetFileList, | 377 &FakeFileSystem::GetResourceEntryAfterGetFileList, |
| 378 weak_ptr_factory_.GetWeakPtr(), base_name, callback)); | 378 weak_ptr_factory_.GetWeakPtr(), base_name, callback)); |
| 379 } | 379 } |
| 380 | 380 |
| 381 void FakeFileSystem::GetResourceEntryAfterGetFileList( | 381 void FakeFileSystem::GetResourceEntryAfterGetFileList( |
| 382 const base::FilePath& base_name, | 382 const base::FilePath& base_name, |
| 383 const GetResourceEntryCallback& callback, | 383 const GetResourceEntryCallback& callback, |
| 384 google_apis::DriveApiErrorCode gdata_error, | 384 google_apis::DriveApiErrorCode gdata_error, |
| 385 scoped_ptr<google_apis::FileList> file_list) { | 385 scoped_ptr<google_apis::FileList> file_list) { |
| 386 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 386 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 387 | 387 |
| 388 FileError error = GDataToFileError(gdata_error); | 388 FileError error = GDataToFileError(gdata_error); |
| 389 if (error != FILE_ERROR_OK) { | 389 if (error != FILE_ERROR_OK) { |
| 390 callback.Run(error, scoped_ptr<ResourceEntry>()); | 390 callback.Run(error, scoped_ptr<ResourceEntry>()); |
| 391 return; | 391 return; |
| 392 } | 392 } |
| 393 | 393 |
| 394 DCHECK(file_list); | 394 DCHECK(file_list); |
| 395 const ScopedVector<google_apis::FileResource>& entries = file_list->items(); | 395 const ScopedVector<google_apis::FileResource>& entries = file_list->items(); |
| 396 for (size_t i = 0; i < entries.size(); ++i) { | 396 for (size_t i = 0; i < entries.size(); ++i) { |
| 397 scoped_ptr<ResourceEntry> entry(new ResourceEntry); | 397 scoped_ptr<ResourceEntry> entry(new ResourceEntry); |
| 398 std::string parent_resource_id; | 398 std::string parent_resource_id; |
| 399 bool converted = ConvertFileResourceToResourceEntry( | 399 bool converted = ConvertFileResourceToResourceEntry( |
| 400 *entries[i], entry.get(), &parent_resource_id); | 400 *entries[i], entry.get(), &parent_resource_id); |
| 401 DCHECK(converted); | 401 DCHECK(converted); |
| 402 entry->set_parent_local_id(parent_resource_id); | 402 entry->set_parent_local_id(parent_resource_id); |
| 403 | 403 |
| 404 if (entry->base_name() == base_name.AsUTF8Unsafe()) { | 404 if (entry->base_name() == base_name.AsUTF8Unsafe()) { |
| 405 // Found the target entry. | 405 // Found the target entry. |
| 406 callback.Run(FILE_ERROR_OK, entry.Pass()); | 406 callback.Run(FILE_ERROR_OK, entry.Pass()); |
| 407 return; | 407 return; |
| 408 } | 408 } |
| 409 } | 409 } |
| 410 | 410 |
| 411 callback.Run(FILE_ERROR_NOT_FOUND, scoped_ptr<ResourceEntry>()); | 411 callback.Run(FILE_ERROR_NOT_FOUND, scoped_ptr<ResourceEntry>()); |
| 412 } | 412 } |
| 413 | 413 |
| 414 } // namespace test_util | 414 } // namespace test_util |
| 415 } // namespace drive | 415 } // namespace drive |
| OLD | NEW |