| 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/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 void FakeFileSystem::RemoveObserver(FileSystemObserver* observer) { | 49 void FakeFileSystem::RemoveObserver(FileSystemObserver* observer) { |
| 50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void FakeFileSystem::CheckForUpdates() { | 53 void FakeFileSystem::CheckForUpdates() { |
| 54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void FakeFileSystem::GetResourceEntryById( | 57 void FakeFileSystem::GetResourceEntryById( |
| 58 const std::string& resource_id, | 58 const std::string& resource_id, |
| 59 const GetResourceEntryWithFilePathCallback& callback) { | 59 const GetResourceEntryCallback& callback) { |
| 60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 61 | 61 |
| 62 drive_service_->GetResourceEntry( | 62 drive_service_->GetResourceEntry( |
| 63 resource_id, | 63 resource_id, |
| 64 base::Bind( | 64 base::Bind( |
| 65 &FakeFileSystem::GetResourceEntryByIdAfterGetResourceEntry, | 65 &FakeFileSystem::GetResourceEntryByIdAfterGetResourceEntry, |
| 66 weak_ptr_factory_.GetWeakPtr(), callback)); | 66 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void FakeFileSystem::TransferFileFromRemoteToLocal( | 69 void FakeFileSystem::TransferFileFromRemoteToLocal( |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 void FakeFileSystem::GetCacheEntryByResourceId( | 249 void FakeFileSystem::GetCacheEntryByResourceId( |
| 250 const std::string& resource_id, | 250 const std::string& resource_id, |
| 251 const std::string& md5, | 251 const std::string& md5, |
| 252 const GetCacheEntryCallback& callback) { | 252 const GetCacheEntryCallback& callback) { |
| 253 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 253 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 254 } | 254 } |
| 255 | 255 |
| 256 void FakeFileSystem::Reload() { | 256 void FakeFileSystem::Reload() { |
| 257 } | 257 } |
| 258 | 258 |
| 259 // Implementation of GetFilePath. | |
| 260 void FakeFileSystem::GetFilePath(const std::string& resource_id, | |
| 261 const GetFilePathCallback& callback) { | |
| 262 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 263 | |
| 264 drive_service_->GetAboutResource( | |
| 265 base::Bind( | |
| 266 &FakeFileSystem::GetFilePathAfterGetAboutResource, | |
| 267 weak_ptr_factory_.GetWeakPtr(), resource_id, callback)); | |
| 268 } | |
| 269 | |
| 270 void FakeFileSystem::GetFilePathAfterGetAboutResource( | |
| 271 const std::string& resource_id, | |
| 272 const GetFilePathCallback& callback, | |
| 273 google_apis::GDataErrorCode error, | |
| 274 scoped_ptr<google_apis::AboutResource> about_resource) { | |
| 275 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 276 | |
| 277 // We assume the call always success for test. | |
| 278 DCHECK_EQ(util::GDataToFileError(error), FILE_ERROR_OK); | |
| 279 DCHECK(about_resource); | |
| 280 | |
| 281 GetFilePathInternal(about_resource->root_folder_id(), resource_id, | |
| 282 base::FilePath(), callback); | |
| 283 } | |
| 284 | |
| 285 void FakeFileSystem::GetFilePathInternal( | |
| 286 const std::string& root_resource_id, | |
| 287 const std::string& resource_id, | |
| 288 const base::FilePath& file_path, | |
| 289 const GetFilePathCallback& callback) { | |
| 290 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 291 | |
| 292 if (resource_id == root_resource_id) { | |
| 293 // Reached to the root. Append the drive root path, and run |callback|. | |
| 294 callback.Run(util::GetDriveMyDriveRootPath().Append(file_path)); | |
| 295 return; | |
| 296 } | |
| 297 | |
| 298 drive_service_->GetResourceEntry( | |
| 299 resource_id, | |
| 300 base::Bind( | |
| 301 &FakeFileSystem::GetFilePathAfterGetResourceEntry, | |
| 302 weak_ptr_factory_.GetWeakPtr(), | |
| 303 root_resource_id, file_path, callback)); | |
| 304 } | |
| 305 | |
| 306 void FakeFileSystem::GetFilePathAfterGetResourceEntry( | |
| 307 const std::string& root_resource_id, | |
| 308 const base::FilePath& remaining_file_path, | |
| 309 const GetFilePathCallback& callback, | |
| 310 google_apis::GDataErrorCode error_in, | |
| 311 scoped_ptr<google_apis::ResourceEntry> resource_entry) { | |
| 312 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 313 | |
| 314 // We assume the call always success for test. | |
| 315 DCHECK_EQ(util::GDataToFileError(error_in), FILE_ERROR_OK); | |
| 316 DCHECK(resource_entry); | |
| 317 | |
| 318 ResourceEntry entry = ConvertToResourceEntry(*resource_entry); | |
| 319 base::FilePath file_path = | |
| 320 base::FilePath::FromUTF8Unsafe(entry.base_name()).Append( | |
| 321 remaining_file_path); | |
| 322 | |
| 323 GetFilePathInternal(root_resource_id, entry.parent_resource_id(), | |
| 324 file_path, callback); | |
| 325 } | |
| 326 | |
| 327 // Implementation of GetResourceEntryById. | 259 // Implementation of GetResourceEntryById. |
| 328 void FakeFileSystem::GetResourceEntryByIdAfterGetResourceEntry( | 260 void FakeFileSystem::GetResourceEntryByIdAfterGetResourceEntry( |
| 329 const GetResourceEntryWithFilePathCallback& callback, | 261 const GetResourceEntryCallback& callback, |
| 330 google_apis::GDataErrorCode error_in, | 262 google_apis::GDataErrorCode error_in, |
| 331 scoped_ptr<google_apis::ResourceEntry> resource_entry) { | 263 scoped_ptr<google_apis::ResourceEntry> resource_entry) { |
| 332 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 264 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 333 | 265 |
| 334 FileError error = util::GDataToFileError(error_in); | 266 FileError error = util::GDataToFileError(error_in); |
| 335 if (error != FILE_ERROR_OK) { | 267 scoped_ptr<ResourceEntry> entry; |
| 336 callback.Run(error, base::FilePath(), scoped_ptr<ResourceEntry>()); | 268 if (error == FILE_ERROR_OK) { |
| 337 return; | 269 DCHECK(resource_entry); |
| 270 entry.reset(new ResourceEntry(ConvertToResourceEntry(*resource_entry))); |
| 338 } | 271 } |
| 339 | 272 callback.Run(error, entry.Pass()); |
| 340 DCHECK(resource_entry); | |
| 341 scoped_ptr<ResourceEntry> entry(new ResourceEntry( | |
| 342 ConvertToResourceEntry(*resource_entry))); | |
| 343 | |
| 344 const std::string parent_resource_id = entry->parent_resource_id(); | |
| 345 GetFilePath( | |
| 346 parent_resource_id, | |
| 347 base::Bind( | |
| 348 &FakeFileSystem::GetResourceEntryByIdAfterGetFilePath, | |
| 349 weak_ptr_factory_.GetWeakPtr(), | |
| 350 callback, error, base::Passed(&entry))); | |
| 351 } | |
| 352 | |
| 353 void FakeFileSystem::GetResourceEntryByIdAfterGetFilePath( | |
| 354 const GetResourceEntryWithFilePathCallback& callback, | |
| 355 FileError error, | |
| 356 scoped_ptr<ResourceEntry> entry, | |
| 357 const base::FilePath& parent_file_path) { | |
| 358 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 359 base::FilePath file_path = parent_file_path.Append( | |
| 360 base::FilePath::FromUTF8Unsafe(entry->base_name())); | |
| 361 callback.Run(error, file_path, entry.Pass()); | |
| 362 } | 273 } |
| 363 | 274 |
| 364 // Implementation of GetFileContentByPath. | 275 // Implementation of GetFileContentByPath. |
| 365 void FakeFileSystem::GetFileContentByPathAfterGetResourceEntry( | 276 void FakeFileSystem::GetFileContentByPathAfterGetResourceEntry( |
| 366 const base::FilePath& file_path, | 277 const base::FilePath& file_path, |
| 367 const GetFileContentInitializedCallback& initialized_callback, | 278 const GetFileContentInitializedCallback& initialized_callback, |
| 368 const google_apis::GetContentCallback& get_content_callback, | 279 const google_apis::GetContentCallback& get_content_callback, |
| 369 const FileOperationCallback& completion_callback, | 280 const FileOperationCallback& completion_callback, |
| 370 FileError error, | 281 FileError error, |
| 371 scoped_ptr<ResourceEntry> entry) { | 282 scoped_ptr<ResourceEntry> entry) { |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 callback.Run(FILE_ERROR_OK, entry.Pass()); | 421 callback.Run(FILE_ERROR_OK, entry.Pass()); |
| 511 return; | 422 return; |
| 512 } | 423 } |
| 513 } | 424 } |
| 514 | 425 |
| 515 callback.Run(FILE_ERROR_NOT_FOUND, scoped_ptr<ResourceEntry>()); | 426 callback.Run(FILE_ERROR_NOT_FOUND, scoped_ptr<ResourceEntry>()); |
| 516 } | 427 } |
| 517 | 428 |
| 518 } // namespace test_util | 429 } // namespace test_util |
| 519 } // namespace drive | 430 } // namespace drive |
| OLD | NEW |