| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/file_system.h" | 5 #include "chrome/browser/chromeos/drive/file_system.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 | 374 |
| 375 cache_->UnpinOnUIThread(entry->resource_id(), | 375 cache_->UnpinOnUIThread(entry->resource_id(), |
| 376 entry->file_specific_info().file_md5(), callback); | 376 entry->file_specific_info().file_md5(), callback); |
| 377 } | 377 } |
| 378 | 378 |
| 379 void FileSystem::GetFileByPath(const base::FilePath& file_path, | 379 void FileSystem::GetFileByPath(const base::FilePath& file_path, |
| 380 const GetFileCallback& callback) { | 380 const GetFileCallback& callback) { |
| 381 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 381 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 382 DCHECK(!callback.is_null()); | 382 DCHECK(!callback.is_null()); |
| 383 | 383 |
| 384 operations_.EnsureFileDownloaded( | 384 operations_.EnsureFileDownloadedByPath( |
| 385 file_path, | 385 file_path, |
| 386 ClientContext(USER_INITIATED), | 386 ClientContext(USER_INITIATED), |
| 387 GetFileContentInitializedCallback(), | 387 GetFileContentInitializedCallback(), |
| 388 google_apis::GetContentCallback(), | 388 google_apis::GetContentCallback(), |
| 389 callback); | 389 callback); |
| 390 } | 390 } |
| 391 | 391 |
| 392 void FileSystem::GetFileByResourceId( | 392 void FileSystem::GetFileByResourceId( |
| 393 const std::string& resource_id, | 393 const std::string& resource_id, |
| 394 const ClientContext& context, | 394 const ClientContext& context, |
| 395 const GetFileCallback& get_file_callback, | 395 const GetFileCallback& get_file_callback, |
| 396 const google_apis::GetContentCallback& get_content_callback) { | 396 const google_apis::GetContentCallback& get_content_callback) { |
| 397 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 397 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 398 DCHECK(!resource_id.empty()); | 398 DCHECK(!resource_id.empty()); |
| 399 DCHECK(!get_file_callback.is_null()); | 399 DCHECK(!get_file_callback.is_null()); |
| 400 | 400 |
| 401 resource_metadata_->GetResourceEntryByIdOnUIThread( | 401 operations_.EnsureFileDownloadedByResourceId( |
| 402 resource_id, | 402 resource_id, |
| 403 base::Bind(&FileSystem::GetFileByResourceIdAfterGetEntry, | |
| 404 weak_ptr_factory_.GetWeakPtr(), | |
| 405 context, | |
| 406 get_file_callback, | |
| 407 get_content_callback)); | |
| 408 } | |
| 409 | |
| 410 void FileSystem::GetFileByResourceIdAfterGetEntry( | |
| 411 const ClientContext& context, | |
| 412 const GetFileCallback& get_file_callback, | |
| 413 const google_apis::GetContentCallback& get_content_callback, | |
| 414 FileError error, | |
| 415 const base::FilePath& file_path, | |
| 416 scoped_ptr<ResourceEntry> entry) { | |
| 417 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 418 DCHECK(!get_file_callback.is_null()); | |
| 419 | |
| 420 if (error != FILE_ERROR_OK) { | |
| 421 get_file_callback.Run(FILE_ERROR_NOT_FOUND, base::FilePath(), | |
| 422 scoped_ptr<ResourceEntry>()); | |
| 423 return; | |
| 424 } | |
| 425 | |
| 426 operations_.EnsureFileDownloaded( | |
| 427 file_path, | |
| 428 context, | 403 context, |
| 429 GetFileContentInitializedCallback(), | 404 GetFileContentInitializedCallback(), |
| 430 get_content_callback, | 405 get_content_callback, |
| 431 get_file_callback); | 406 get_file_callback); |
| 432 } | 407 } |
| 433 | 408 |
| 434 void FileSystem::GetFileContentByPath( | 409 void FileSystem::GetFileContentByPath( |
| 435 const base::FilePath& file_path, | 410 const base::FilePath& file_path, |
| 436 const GetFileContentInitializedCallback& initialized_callback, | 411 const GetFileContentInitializedCallback& initialized_callback, |
| 437 const google_apis::GetContentCallback& get_content_callback, | 412 const google_apis::GetContentCallback& get_content_callback, |
| 438 const FileOperationCallback& completion_callback) { | 413 const FileOperationCallback& completion_callback) { |
| 439 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 414 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 440 DCHECK(!initialized_callback.is_null()); | 415 DCHECK(!initialized_callback.is_null()); |
| 441 DCHECK(!get_content_callback.is_null()); | 416 DCHECK(!get_content_callback.is_null()); |
| 442 DCHECK(!completion_callback.is_null()); | 417 DCHECK(!completion_callback.is_null()); |
| 443 | 418 |
| 444 operations_.EnsureFileDownloaded( | 419 operations_.EnsureFileDownloadedByPath( |
| 445 file_path, | 420 file_path, |
| 446 ClientContext(USER_INITIATED), | 421 ClientContext(USER_INITIATED), |
| 447 initialized_callback, | 422 initialized_callback, |
| 448 get_content_callback, | 423 get_content_callback, |
| 449 base::Bind(&GetFileCallbackToFileOperationCallbackAdapter, | 424 base::Bind(&GetFileCallbackToFileOperationCallbackAdapter, |
| 450 completion_callback)); | 425 completion_callback)); |
| 451 } | 426 } |
| 452 | 427 |
| 453 void FileSystem::GetResourceEntryByPath( | 428 void FileSystem::GetResourceEntryByPath( |
| 454 const base::FilePath& file_path, | 429 const base::FilePath& file_path, |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 881 // Open->Open->modify->Close->modify->Close; the second modify may not be | 856 // Open->Open->modify->Close->modify->Close; the second modify may not be |
| 882 // synchronized to the server since it is already Closed on the cache). | 857 // synchronized to the server since it is already Closed on the cache). |
| 883 if (open_files_.find(file_path) != open_files_.end()) { | 858 if (open_files_.find(file_path) != open_files_.end()) { |
| 884 base::MessageLoopProxy::current()->PostTask( | 859 base::MessageLoopProxy::current()->PostTask( |
| 885 FROM_HERE, | 860 FROM_HERE, |
| 886 base::Bind(callback, FILE_ERROR_IN_USE, base::FilePath())); | 861 base::Bind(callback, FILE_ERROR_IN_USE, base::FilePath())); |
| 887 return; | 862 return; |
| 888 } | 863 } |
| 889 open_files_.insert(file_path); | 864 open_files_.insert(file_path); |
| 890 | 865 |
| 891 operations_.EnsureFileDownloaded( | 866 operations_.EnsureFileDownloadedByPath( |
| 892 file_path, | 867 file_path, |
| 893 ClientContext(USER_INITIATED), | 868 ClientContext(USER_INITIATED), |
| 894 GetFileContentInitializedCallback(), | 869 GetFileContentInitializedCallback(), |
| 895 google_apis::GetContentCallback(), | 870 google_apis::GetContentCallback(), |
| 896 base::Bind(&FileSystem::OpenFileAfterFileDownloaded, | 871 base::Bind(&FileSystem::OpenFileAfterFileDownloaded, |
| 897 weak_ptr_factory_.GetWeakPtr(), | 872 weak_ptr_factory_.GetWeakPtr(), |
| 898 file_path, | 873 file_path, |
| 899 base::Bind(&FileSystem::OnOpenFileFinished, | 874 base::Bind(&FileSystem::OnOpenFileFinished, |
| 900 weak_ptr_factory_.GetWeakPtr(), | 875 weak_ptr_factory_.GetWeakPtr(), |
| 901 file_path, | 876 file_path, |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1132 return; | 1107 return; |
| 1133 } | 1108 } |
| 1134 | 1109 |
| 1135 PlatformFileInfoProto entry_file_info; | 1110 PlatformFileInfoProto entry_file_info; |
| 1136 util::ConvertPlatformFileInfoToResourceEntry(*file_info, &entry_file_info); | 1111 util::ConvertPlatformFileInfoToResourceEntry(*file_info, &entry_file_info); |
| 1137 *entry->mutable_file_info() = entry_file_info; | 1112 *entry->mutable_file_info() = entry_file_info; |
| 1138 callback.Run(FILE_ERROR_OK, entry.Pass()); | 1113 callback.Run(FILE_ERROR_OK, entry.Pass()); |
| 1139 } | 1114 } |
| 1140 | 1115 |
| 1141 } // namespace drive | 1116 } // namespace drive |
| OLD | NEW |