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 21 matching lines...) Expand all Loading... | |
32 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
33 #include "content/public/browser/notification_details.h" | 33 #include "content/public/browser/notification_details.h" |
34 | 34 |
35 using content::BrowserThread; | 35 using content::BrowserThread; |
36 | 36 |
37 namespace drive { | 37 namespace drive { |
38 namespace { | 38 namespace { |
39 | 39 |
40 //================================ Helper functions ============================ | 40 //================================ Helper functions ============================ |
41 | 41 |
42 // Helper function for binding |path| to GetResourceEntryWithFilePathCallback | |
43 // and create GetResourceEntryCallback. | |
44 void RunGetResourceEntryWithFilePathCallback( | |
45 const GetResourceEntryWithFilePathCallback& callback, | |
46 const base::FilePath& path, | |
47 FileError error, | |
48 scoped_ptr<ResourceEntry> entry) { | |
49 DCHECK(!callback.is_null()); | |
50 callback.Run(error, path, entry.Pass()); | |
51 } | |
52 | |
53 // Callback for ResourceMetadata::GetLargestChangestamp. | 42 // Callback for ResourceMetadata::GetLargestChangestamp. |
54 // |callback| must not be null. | 43 // |callback| must not be null. |
55 void OnGetLargestChangestamp( | 44 void OnGetLargestChangestamp( |
56 FileSystemMetadata metadata, // Will be modified. | 45 FileSystemMetadata metadata, // Will be modified. |
57 const GetFilesystemMetadataCallback& callback, | 46 const GetFilesystemMetadataCallback& callback, |
58 int64 largest_changestamp) { | 47 int64 largest_changestamp) { |
59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
60 DCHECK(!callback.is_null()); | 49 DCHECK(!callback.is_null()); |
61 | 50 |
62 metadata.largest_changestamp = largest_changestamp; | 51 metadata.largest_changestamp = largest_changestamp; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 observers_.AddObserver(observer); | 161 observers_.AddObserver(observer); |
173 } | 162 } |
174 | 163 |
175 void FileSystem::RemoveObserver(FileSystemObserver* observer) { | 164 void FileSystem::RemoveObserver(FileSystemObserver* observer) { |
176 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
177 observers_.RemoveObserver(observer); | 166 observers_.RemoveObserver(observer); |
178 } | 167 } |
179 | 168 |
180 void FileSystem::GetResourceEntryById( | 169 void FileSystem::GetResourceEntryById( |
181 const std::string& resource_id, | 170 const std::string& resource_id, |
182 const GetResourceEntryWithFilePathCallback& callback) { | 171 const GetResourceEntryCallback& callback) { |
183 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 172 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
184 DCHECK(!resource_id.empty()); | 173 DCHECK(!resource_id.empty()); |
185 DCHECK(!callback.is_null()); | 174 DCHECK(!callback.is_null()); |
186 | 175 |
187 resource_metadata_->GetResourceEntryByIdOnUIThread( | 176 resource_metadata_->GetResourceEntryByIdOnUIThread( |
188 resource_id, | 177 resource_id, |
189 base::Bind(&FileSystem::GetResourceEntryByIdAfterGetEntry, | 178 base::Bind(&FileSystem::GetResourceEntryByIdAfterGetEntry, |
190 weak_ptr_factory_.GetWeakPtr(), | 179 weak_ptr_factory_.GetWeakPtr(), |
191 callback)); | 180 callback)); |
192 } | 181 } |
193 | 182 |
194 void FileSystem::GetResourceEntryByIdAfterGetEntry( | 183 void FileSystem::GetResourceEntryByIdAfterGetEntry( |
195 const GetResourceEntryWithFilePathCallback& callback, | 184 const GetResourceEntryCallback& callback, |
196 FileError error, | 185 FileError error, |
197 const base::FilePath& file_path, | |
198 scoped_ptr<ResourceEntry> entry) { | 186 scoped_ptr<ResourceEntry> entry) { |
199 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 187 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
200 DCHECK(!callback.is_null()); | 188 DCHECK(!callback.is_null()); |
201 | 189 |
202 if (error != FILE_ERROR_OK) { | 190 if (error != FILE_ERROR_OK) { |
203 callback.Run(error, base::FilePath(), scoped_ptr<ResourceEntry>()); | 191 callback.Run(error, scoped_ptr<ResourceEntry>()); |
204 return; | 192 return; |
205 } | 193 } |
206 DCHECK(entry.get()); | 194 DCHECK(entry.get()); |
207 | 195 |
208 CheckLocalModificationAndRun( | 196 CheckLocalModificationAndRun(entry.Pass(), callback); |
209 entry.Pass(), | |
210 base::Bind(&RunGetResourceEntryWithFilePathCallback, | |
211 callback, | |
212 file_path)); | |
213 } | 197 } |
214 | 198 |
215 void FileSystem::TransferFileFromRemoteToLocal( | 199 void FileSystem::TransferFileFromRemoteToLocal( |
216 const base::FilePath& remote_src_file_path, | 200 const base::FilePath& remote_src_file_path, |
217 const base::FilePath& local_dest_file_path, | 201 const base::FilePath& local_dest_file_path, |
218 const FileOperationCallback& callback) { | 202 const FileOperationCallback& callback) { |
219 | 203 |
220 operations_.TransferFileFromRemoteToLocal(remote_src_file_path, | 204 operations_.TransferFileFromRemoteToLocal(remote_src_file_path, |
221 local_dest_file_path, | 205 local_dest_file_path, |
222 callback); | 206 callback); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
391 | 375 |
392 void FileSystem::GetFileByResourceId( | 376 void FileSystem::GetFileByResourceId( |
393 const std::string& resource_id, | 377 const std::string& resource_id, |
394 const DriveClientContext& context, | 378 const DriveClientContext& context, |
395 const GetFileCallback& get_file_callback, | 379 const GetFileCallback& get_file_callback, |
396 const google_apis::GetContentCallback& get_content_callback) { | 380 const google_apis::GetContentCallback& get_content_callback) { |
397 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 381 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
398 DCHECK(!resource_id.empty()); | 382 DCHECK(!resource_id.empty()); |
399 DCHECK(!get_file_callback.is_null()); | 383 DCHECK(!get_file_callback.is_null()); |
400 | 384 |
401 resource_metadata_->GetResourceEntryByIdOnUIThread( | 385 base::PostTaskAndReplyWithResult( |
402 resource_id, | 386 blocking_task_runner_, |
403 base::Bind(&FileSystem::GetFileByResourceIdAfterGetEntry, | 387 FROM_HERE, |
388 base::Bind(&internal::ResourceMetadata::GetFilePath, | |
satorux1
2013/05/29 06:07:03
This seems to be awkward. Why do we need to conver
| |
389 base::Unretained(resource_metadata_), | |
390 resource_id), | |
391 base::Bind(&FileSystem::GetFileByResourceIdAfterGetFilePath, | |
404 weak_ptr_factory_.GetWeakPtr(), | 392 weak_ptr_factory_.GetWeakPtr(), |
405 context, | 393 context, |
406 get_file_callback, | 394 get_file_callback, |
407 get_content_callback)); | 395 get_content_callback)); |
408 } | 396 } |
409 | 397 |
410 void FileSystem::GetFileByResourceIdAfterGetEntry( | 398 void FileSystem::GetFileByResourceIdAfterGetFilePath( |
411 const DriveClientContext& context, | 399 const DriveClientContext& context, |
412 const GetFileCallback& get_file_callback, | 400 const GetFileCallback& get_file_callback, |
413 const google_apis::GetContentCallback& get_content_callback, | 401 const google_apis::GetContentCallback& get_content_callback, |
414 FileError error, | 402 const base::FilePath& file_path) { |
415 const base::FilePath& file_path, | |
416 scoped_ptr<ResourceEntry> entry) { | |
417 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 403 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
418 DCHECK(!get_file_callback.is_null()); | 404 DCHECK(!get_file_callback.is_null()); |
419 | 405 |
420 if (error != FILE_ERROR_OK) { | 406 if (file_path.empty()) { |
421 get_file_callback.Run(FILE_ERROR_NOT_FOUND, base::FilePath(), | 407 get_file_callback.Run(FILE_ERROR_NOT_FOUND, base::FilePath(), |
422 scoped_ptr<ResourceEntry>()); | 408 scoped_ptr<ResourceEntry>()); |
423 return; | 409 return; |
424 } | 410 } |
425 | 411 |
426 operations_.EnsureFileDownloaded( | 412 operations_.EnsureFileDownloaded( |
427 file_path, | 413 file_path, |
satorux1
2013/05/29 06:07:03
My feeling is that this function taking |file_path
hashimoto
2013/05/30 03:45:03
Done.
hashimoto
2013/05/30 03:45:03
Done.
| |
428 context, | 414 context, |
429 GetFileContentInitializedCallback(), | 415 GetFileContentInitializedCallback(), |
430 get_content_callback, | 416 get_content_callback, |
431 get_file_callback); | 417 get_file_callback); |
432 } | 418 } |
433 | 419 |
434 void FileSystem::GetFileContentByPath( | 420 void FileSystem::GetFileContentByPath( |
435 const base::FilePath& file_path, | 421 const base::FilePath& file_path, |
436 const GetFileContentInitializedCallback& initialized_callback, | 422 const GetFileContentInitializedCallback& initialized_callback, |
437 const google_apis::GetContentCallback& get_content_callback, | 423 const google_apis::GetContentCallback& get_content_callback, |
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1132 return; | 1118 return; |
1133 } | 1119 } |
1134 | 1120 |
1135 PlatformFileInfoProto entry_file_info; | 1121 PlatformFileInfoProto entry_file_info; |
1136 util::ConvertPlatformFileInfoToResourceEntry(*file_info, &entry_file_info); | 1122 util::ConvertPlatformFileInfoToResourceEntry(*file_info, &entry_file_info); |
1137 *entry->mutable_file_info() = entry_file_info; | 1123 *entry->mutable_file_info() = entry_file_info; |
1138 callback.Run(FILE_ERROR_OK, entry.Pass()); | 1124 callback.Run(FILE_ERROR_OK, entry.Pass()); |
1139 } | 1125 } |
1140 | 1126 |
1141 } // namespace drive | 1127 } // namespace drive |
OLD | NEW |