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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 const std::string& md5) | 124 const std::string& md5) |
125 : callback(callback), | 125 : callback(callback), |
126 resource_id(resource_id), | 126 resource_id(resource_id), |
127 md5(md5) { | 127 md5(md5) { |
128 } | 128 } |
129 | 129 |
130 // FileSystem::GetResolvedFileParams struct implementation. | 130 // FileSystem::GetResolvedFileParams struct implementation. |
131 struct FileSystem::GetResolvedFileParams { | 131 struct FileSystem::GetResolvedFileParams { |
132 GetResolvedFileParams( | 132 GetResolvedFileParams( |
133 const base::FilePath& drive_file_path, | 133 const base::FilePath& drive_file_path, |
134 const DriveClientContext& context, | 134 const ClientContext& context, |
135 scoped_ptr<ResourceEntry> entry, | 135 scoped_ptr<ResourceEntry> entry, |
136 const GetFileContentInitializedCallback& initialized_callback, | 136 const GetFileContentInitializedCallback& initialized_callback, |
137 const GetFileCallback& get_file_callback, | 137 const GetFileCallback& get_file_callback, |
138 const google_apis::GetContentCallback& get_content_callback) | 138 const google_apis::GetContentCallback& get_content_callback) |
139 : drive_file_path(drive_file_path), | 139 : drive_file_path(drive_file_path), |
140 context(context), | 140 context(context), |
141 entry(entry.Pass()), | 141 entry(entry.Pass()), |
142 initialized_callback(initialized_callback), | 142 initialized_callback(initialized_callback), |
143 get_file_callback(get_file_callback), | 143 get_file_callback(get_file_callback), |
144 get_content_callback(get_content_callback) { | 144 get_content_callback(get_content_callback) { |
(...skipping 28 matching lines...) Expand all Loading... |
173 base::FilePath(), | 173 base::FilePath(), |
174 cancel_download_closure); | 174 cancel_download_closure); |
175 } | 175 } |
176 | 176 |
177 void OnComplete(const base::FilePath& local_file_path) { | 177 void OnComplete(const base::FilePath& local_file_path) { |
178 get_file_callback.Run(FILE_ERROR_OK, local_file_path, | 178 get_file_callback.Run(FILE_ERROR_OK, local_file_path, |
179 scoped_ptr<ResourceEntry>(new ResourceEntry(*entry))); | 179 scoped_ptr<ResourceEntry>(new ResourceEntry(*entry))); |
180 } | 180 } |
181 | 181 |
182 const base::FilePath drive_file_path; | 182 const base::FilePath drive_file_path; |
183 const DriveClientContext context; | 183 const ClientContext context; |
184 scoped_ptr<ResourceEntry> entry; | 184 scoped_ptr<ResourceEntry> entry; |
185 const GetFileContentInitializedCallback initialized_callback; | 185 const GetFileContentInitializedCallback initialized_callback; |
186 const GetFileCallback get_file_callback; | 186 const GetFileCallback get_file_callback; |
187 const google_apis::GetContentCallback get_content_callback; | 187 const google_apis::GetContentCallback get_content_callback; |
188 }; | 188 }; |
189 | 189 |
190 FileSystem::FileSystem( | 190 FileSystem::FileSystem( |
191 Profile* profile, | 191 Profile* profile, |
192 internal::FileCache* cache, | 192 internal::FileCache* cache, |
193 google_apis::DriveServiceInterface* drive_service, | 193 google_apis::DriveServiceInterface* drive_service, |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 | 512 |
513 if (error != FILE_ERROR_OK) { | 513 if (error != FILE_ERROR_OK) { |
514 callback.Run(error, base::FilePath(), scoped_ptr<ResourceEntry>()); | 514 callback.Run(error, base::FilePath(), scoped_ptr<ResourceEntry>()); |
515 return; | 515 return; |
516 } | 516 } |
517 DCHECK(entry); | 517 DCHECK(entry); |
518 | 518 |
519 GetResolvedFileByPath( | 519 GetResolvedFileByPath( |
520 make_scoped_ptr(new GetResolvedFileParams( | 520 make_scoped_ptr(new GetResolvedFileParams( |
521 file_path, | 521 file_path, |
522 DriveClientContext(USER_INITIATED), | 522 ClientContext(USER_INITIATED), |
523 entry.Pass(), | 523 entry.Pass(), |
524 GetFileContentInitializedCallback(), | 524 GetFileContentInitializedCallback(), |
525 callback, | 525 callback, |
526 google_apis::GetContentCallback()))); | 526 google_apis::GetContentCallback()))); |
527 } | 527 } |
528 | 528 |
529 void FileSystem::GetFileByResourceId( | 529 void FileSystem::GetFileByResourceId( |
530 const std::string& resource_id, | 530 const std::string& resource_id, |
531 const DriveClientContext& context, | 531 const ClientContext& context, |
532 const GetFileCallback& get_file_callback, | 532 const GetFileCallback& get_file_callback, |
533 const google_apis::GetContentCallback& get_content_callback) { | 533 const google_apis::GetContentCallback& get_content_callback) { |
534 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 534 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
535 DCHECK(!resource_id.empty()); | 535 DCHECK(!resource_id.empty()); |
536 DCHECK(!get_file_callback.is_null()); | 536 DCHECK(!get_file_callback.is_null()); |
537 | 537 |
538 resource_metadata_->GetResourceEntryByIdOnUIThread( | 538 resource_metadata_->GetResourceEntryByIdOnUIThread( |
539 resource_id, | 539 resource_id, |
540 base::Bind(&FileSystem::GetFileByResourceIdAfterGetEntry, | 540 base::Bind(&FileSystem::GetFileByResourceIdAfterGetEntry, |
541 weak_ptr_factory_.GetWeakPtr(), | 541 weak_ptr_factory_.GetWeakPtr(), |
542 context, | 542 context, |
543 get_file_callback, | 543 get_file_callback, |
544 get_content_callback)); | 544 get_content_callback)); |
545 } | 545 } |
546 | 546 |
547 void FileSystem::GetFileByResourceIdAfterGetEntry( | 547 void FileSystem::GetFileByResourceIdAfterGetEntry( |
548 const DriveClientContext& context, | 548 const ClientContext& context, |
549 const GetFileCallback& get_file_callback, | 549 const GetFileCallback& get_file_callback, |
550 const google_apis::GetContentCallback& get_content_callback, | 550 const google_apis::GetContentCallback& get_content_callback, |
551 FileError error, | 551 FileError error, |
552 const base::FilePath& file_path, | 552 const base::FilePath& file_path, |
553 scoped_ptr<ResourceEntry> entry) { | 553 scoped_ptr<ResourceEntry> entry) { |
554 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 554 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
555 DCHECK(!get_file_callback.is_null()); | 555 DCHECK(!get_file_callback.is_null()); |
556 | 556 |
557 if (error != FILE_ERROR_OK) { | 557 if (error != FILE_ERROR_OK) { |
558 get_file_callback.Run(FILE_ERROR_NOT_FOUND, base::FilePath(), | 558 get_file_callback.Run(FILE_ERROR_NOT_FOUND, base::FilePath(), |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 | 604 |
605 if (error != FILE_ERROR_OK) { | 605 if (error != FILE_ERROR_OK) { |
606 completion_callback.Run(error); | 606 completion_callback.Run(error); |
607 return; | 607 return; |
608 } | 608 } |
609 | 609 |
610 DCHECK(entry); | 610 DCHECK(entry); |
611 GetResolvedFileByPath( | 611 GetResolvedFileByPath( |
612 make_scoped_ptr(new GetResolvedFileParams( | 612 make_scoped_ptr(new GetResolvedFileParams( |
613 file_path, | 613 file_path, |
614 DriveClientContext(USER_INITIATED), | 614 ClientContext(USER_INITIATED), |
615 entry.Pass(), | 615 entry.Pass(), |
616 initialized_callback, | 616 initialized_callback, |
617 base::Bind(&GetFileCallbackToFileOperationCallbackAdapter, | 617 base::Bind(&GetFileCallbackToFileOperationCallbackAdapter, |
618 completion_callback), | 618 completion_callback), |
619 get_content_callback))); | 619 get_content_callback))); |
620 } | 620 } |
621 | 621 |
622 void FileSystem::GetResourceEntryByPath( | 622 void FileSystem::GetResourceEntryByPath( |
623 const base::FilePath& file_path, | 623 const base::FilePath& file_path, |
624 const GetResourceEntryCallback& callback) { | 624 const GetResourceEntryCallback& callback) { |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1142 return; | 1142 return; |
1143 } | 1143 } |
1144 | 1144 |
1145 change_list_loader_->LoadDirectoryFromServer( | 1145 change_list_loader_->LoadDirectoryFromServer( |
1146 entry->resource_id(), | 1146 entry->resource_id(), |
1147 callback); | 1147 callback); |
1148 } | 1148 } |
1149 | 1149 |
1150 void FileSystem::UpdateFileByResourceId( | 1150 void FileSystem::UpdateFileByResourceId( |
1151 const std::string& resource_id, | 1151 const std::string& resource_id, |
1152 const DriveClientContext& context, | 1152 const ClientContext& context, |
1153 const FileOperationCallback& callback) { | 1153 const FileOperationCallback& callback) { |
1154 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1154 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1155 DCHECK(!callback.is_null()); | 1155 DCHECK(!callback.is_null()); |
1156 | 1156 |
1157 drive_operations_.UpdateFileByResourceId(resource_id, context, callback); | 1157 drive_operations_.UpdateFileByResourceId(resource_id, context, callback); |
1158 } | 1158 } |
1159 | 1159 |
1160 void FileSystem::GetAvailableSpace( | 1160 void FileSystem::GetAvailableSpace( |
1161 const GetAvailableSpaceCallback& callback) { | 1161 const GetAvailableSpaceCallback& callback) { |
1162 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1162 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1402 callback.Run(error, base::FilePath()); | 1402 callback.Run(error, base::FilePath()); |
1403 return; | 1403 return; |
1404 } | 1404 } |
1405 | 1405 |
1406 DCHECK(!entry->resource_id().empty()); | 1406 DCHECK(!entry->resource_id().empty()); |
1407 // Extract a pointer before we call Pass() so we can use it below. | 1407 // Extract a pointer before we call Pass() so we can use it below. |
1408 ResourceEntry* entry_ptr = entry.get(); | 1408 ResourceEntry* entry_ptr = entry.get(); |
1409 GetResolvedFileByPath( | 1409 GetResolvedFileByPath( |
1410 make_scoped_ptr(new GetResolvedFileParams( | 1410 make_scoped_ptr(new GetResolvedFileParams( |
1411 file_path, | 1411 file_path, |
1412 DriveClientContext(USER_INITIATED), | 1412 ClientContext(USER_INITIATED), |
1413 entry.Pass(), | 1413 entry.Pass(), |
1414 GetFileContentInitializedCallback(), | 1414 GetFileContentInitializedCallback(), |
1415 base::Bind(&FileSystem::OnGetFileCompleteForOpenFile, | 1415 base::Bind(&FileSystem::OnGetFileCompleteForOpenFile, |
1416 weak_ptr_factory_.GetWeakPtr(), | 1416 weak_ptr_factory_.GetWeakPtr(), |
1417 GetFileCompleteForOpenParams( | 1417 GetFileCompleteForOpenParams( |
1418 callback, | 1418 callback, |
1419 entry_ptr->resource_id(), | 1419 entry_ptr->resource_id(), |
1420 entry_ptr->file_specific_info().file_md5())), | 1420 entry_ptr->file_specific_info().file_md5())), |
1421 google_apis::GetContentCallback()))); | 1421 google_apis::GetContentCallback()))); |
1422 } | 1422 } |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1645 util::ConvertPlatformFileInfoToResourceEntry(*file_info, &entry_file_info); | 1645 util::ConvertPlatformFileInfoToResourceEntry(*file_info, &entry_file_info); |
1646 *entry->mutable_file_info() = entry_file_info; | 1646 *entry->mutable_file_info() = entry_file_info; |
1647 callback.Run(FILE_ERROR_OK, entry.Pass()); | 1647 callback.Run(FILE_ERROR_OK, entry.Pass()); |
1648 } | 1648 } |
1649 | 1649 |
1650 void FileSystem::CancelJobInScheduler(JobID id) { | 1650 void FileSystem::CancelJobInScheduler(JobID id) { |
1651 scheduler_->CancelJob(id); | 1651 scheduler_->CancelJob(id); |
1652 } | 1652 } |
1653 | 1653 |
1654 } // namespace drive | 1654 } // namespace drive |
OLD | NEW |