OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/media_galleries/fileapi/picasa/picasa_file_util.h" | 5 #include "chrome/browser/media_galleries/fileapi/picasa/picasa_file_util.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
14 #include "base/strings/sys_string_conversions.h" | 14 #include "base/strings/sys_string_conversions.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" | 16 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" |
17 #include "chrome/browser/media_galleries/fileapi/picasa/picasa_data_provider.h" | 17 #include "chrome/browser/media_galleries/fileapi/picasa/picasa_data_provider.h" |
18 #include "chrome/browser/media_galleries/imported_media_gallery_registry.h" | 18 #include "chrome/browser/media_galleries/imported_media_gallery_registry.h" |
19 #include "chrome/common/media_galleries/picasa_types.h" | 19 #include "chrome/common/media_galleries/picasa_types.h" |
| 20 #include "content/public/browser/browser_thread.h" |
20 #include "webkit/browser/fileapi/file_system_operation_context.h" | 21 #include "webkit/browser/fileapi/file_system_operation_context.h" |
21 #include "webkit/browser/fileapi/file_system_url.h" | 22 #include "webkit/browser/fileapi/file_system_url.h" |
22 #include "webkit/common/fileapi/file_system_util.h" | 23 #include "webkit/common/fileapi/file_system_util.h" |
23 | 24 |
24 using base::FilePath; | 25 using base::FilePath; |
25 using fileapi::DirectoryEntry; | 26 using fileapi::DirectoryEntry; |
26 using fileapi::FileSystemOperationContext; | 27 using fileapi::FileSystemOperationContext; |
27 using fileapi::FileSystemURL; | 28 using fileapi::FileSystemURL; |
28 | 29 |
29 namespace picasa { | 30 namespace picasa { |
(...skipping 28 matching lines...) Expand all Loading... |
58 weak_factory_(this) { | 59 weak_factory_(this) { |
59 } | 60 } |
60 | 61 |
61 PicasaFileUtil::~PicasaFileUtil() {} | 62 PicasaFileUtil::~PicasaFileUtil() {} |
62 | 63 |
63 void PicasaFileUtil::GetFileInfoOnTaskRunnerThread( | 64 void PicasaFileUtil::GetFileInfoOnTaskRunnerThread( |
64 scoped_ptr<fileapi::FileSystemOperationContext> context, | 65 scoped_ptr<fileapi::FileSystemOperationContext> context, |
65 const fileapi::FileSystemURL& url, | 66 const fileapi::FileSystemURL& url, |
66 const GetFileInfoCallback& callback) { | 67 const GetFileInfoCallback& callback) { |
67 GetDataProvider()->RefreshData( | 68 GetDataProvider()->RefreshData( |
| 69 PicasaDataProvider::LIST_OF_ALBUMS_AND_FOLDERS_DATA, |
68 base::Bind(&PicasaFileUtil::GetFileInfoWithFreshDataProvider, | 70 base::Bind(&PicasaFileUtil::GetFileInfoWithFreshDataProvider, |
69 weak_factory_.GetWeakPtr(), base::Passed(&context), url, | 71 weak_factory_.GetWeakPtr(), |
| 72 base::Passed(&context), |
| 73 url, |
70 callback)); | 74 callback)); |
71 } | 75 } |
72 | 76 |
73 void PicasaFileUtil::ReadDirectoryOnTaskRunnerThread( | 77 void PicasaFileUtil::ReadDirectoryOnTaskRunnerThread( |
74 scoped_ptr<fileapi::FileSystemOperationContext> context, | 78 scoped_ptr<fileapi::FileSystemOperationContext> context, |
75 const fileapi::FileSystemURL& url, | 79 const fileapi::FileSystemURL& url, |
76 const ReadDirectoryCallback& callback) { | 80 const ReadDirectoryCallback& callback) { |
77 GetDataProvider()->RefreshData( | 81 GetDataProvider()->RefreshData( |
| 82 PicasaDataProvider::LIST_OF_ALBUMS_AND_FOLDERS_DATA, |
78 base::Bind(&PicasaFileUtil::ReadDirectoryWithFreshDataProvider, | 83 base::Bind(&PicasaFileUtil::ReadDirectoryWithFreshDataProvider, |
79 weak_factory_.GetWeakPtr(), base::Passed(&context), url, | 84 weak_factory_.GetWeakPtr(), |
| 85 base::Passed(&context), |
| 86 url, |
80 callback)); | 87 callback)); |
81 } | 88 } |
82 | 89 |
83 base::PlatformFileError PicasaFileUtil::GetFileInfoSync( | 90 base::PlatformFileError PicasaFileUtil::GetFileInfoSync( |
84 FileSystemOperationContext* context, const FileSystemURL& url, | 91 FileSystemOperationContext* context, const FileSystemURL& url, |
85 base::PlatformFileInfo* file_info, base::FilePath* platform_path) { | 92 base::PlatformFileInfo* file_info, base::FilePath* platform_path) { |
86 DCHECK(context); | 93 DCHECK(context); |
87 DCHECK(file_info); | 94 DCHECK(file_info); |
88 DCHECK(platform_path); | 95 DCHECK(platform_path); |
89 | 96 |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 | 282 |
276 // All other cases don't have a local path. The valid cases should be | 283 // All other cases don't have a local path. The valid cases should be |
277 // intercepted by GetFileInfo()/CreateFileEnumerator(). Invalid cases | 284 // intercepted by GetFileInfo()/CreateFileEnumerator(). Invalid cases |
278 // return a NOT_FOUND error. | 285 // return a NOT_FOUND error. |
279 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 286 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
280 } | 287 } |
281 | 288 |
282 void PicasaFileUtil::GetFileInfoWithFreshDataProvider( | 289 void PicasaFileUtil::GetFileInfoWithFreshDataProvider( |
283 scoped_ptr<fileapi::FileSystemOperationContext> context, | 290 scoped_ptr<fileapi::FileSystemOperationContext> context, |
284 const fileapi::FileSystemURL& url, | 291 const fileapi::FileSystemURL& url, |
285 const GetFileInfoCallback& callback) { | 292 const GetFileInfoCallback& callback, |
286 NativeMediaFileUtil::GetFileInfoOnTaskRunnerThread(context.Pass(), url, | 293 bool success) { |
287 callback); | 294 if (!success) { |
| 295 content::BrowserThread::PostTask( |
| 296 content::BrowserThread::IO, |
| 297 FROM_HERE, |
| 298 base::Bind( |
| 299 callback, base::PLATFORM_FILE_ERROR_IO, base::PlatformFileInfo())); |
| 300 return; |
| 301 } |
| 302 NativeMediaFileUtil::GetFileInfoOnTaskRunnerThread( |
| 303 context.Pass(), url, callback); |
288 } | 304 } |
289 | 305 |
290 void PicasaFileUtil::ReadDirectoryWithFreshDataProvider( | 306 void PicasaFileUtil::ReadDirectoryWithFreshDataProvider( |
291 scoped_ptr<fileapi::FileSystemOperationContext> context, | 307 scoped_ptr<fileapi::FileSystemOperationContext> context, |
292 const fileapi::FileSystemURL& url, | 308 const fileapi::FileSystemURL& url, |
293 const ReadDirectoryCallback& callback) { | 309 const ReadDirectoryCallback& callback, |
294 NativeMediaFileUtil::ReadDirectoryOnTaskRunnerThread(context.Pass(), url, | 310 bool success) { |
295 callback); | 311 if (!success) { |
| 312 content::BrowserThread::PostTask( |
| 313 content::BrowserThread::IO, |
| 314 FROM_HERE, |
| 315 base::Bind(callback, base::PLATFORM_FILE_ERROR_IO, EntryList(), false)); |
| 316 return; |
| 317 } |
| 318 NativeMediaFileUtil::ReadDirectoryOnTaskRunnerThread( |
| 319 context.Pass(), url, callback); |
296 } | 320 } |
297 | 321 |
298 PicasaDataProvider* PicasaFileUtil::GetDataProvider() { | 322 PicasaDataProvider* PicasaFileUtil::GetDataProvider() { |
299 return chrome::ImportedMediaGalleryRegistry::PicasaDataProvider(); | 323 return chrome::ImportedMediaGalleryRegistry::PicasaDataProvider(); |
300 } | 324 } |
301 | 325 |
302 } // namespace picasa | 326 } // namespace picasa |
OLD | NEW |