OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/file_manager/filesystem_api_util.h" |
| 6 |
| 7 #include "base/callback.h" |
| 8 #include "base/files/file_path.h" |
| 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "chrome/browser/chromeos/drive/file_errors.h" |
| 11 #include "chrome/browser/chromeos/drive/file_system_interface.h" |
| 12 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 13 #include "content/public/browser/browser_thread.h" |
| 14 |
| 15 namespace file_manager { |
| 16 namespace util { |
| 17 |
| 18 namespace { |
| 19 |
| 20 void GetMimeTypeAfterGetResourceEntry( |
| 21 const base::Callback<void(bool, const std::string&)>& callback, |
| 22 drive::FileError error, |
| 23 scoped_ptr<drive::ResourceEntry> entry) { |
| 24 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 25 |
| 26 if (error != drive::FILE_ERROR_OK || !entry->has_file_specific_info()) { |
| 27 callback.Run(false, std::string()); |
| 28 return; |
| 29 } |
| 30 callback.Run(true, entry->file_specific_info().content_mime_type()); |
| 31 } |
| 32 |
| 33 void CheckDirectoryAfterDriveCheck(const base::Callback<void(bool)>& callback, |
| 34 drive::FileError error) { |
| 35 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 36 |
| 37 return callback.Run(error == drive::FILE_ERROR_OK); |
| 38 } |
| 39 |
| 40 void CheckWritableAfterDriveCheck(const base::Callback<void(bool)>& callback, |
| 41 drive::FileError error, |
| 42 const base::FilePath& local_path) { |
| 43 // This is called on the IO-allowed blocking pool. Call back to UI. |
| 44 content::BrowserThread::PostTask( |
| 45 content::BrowserThread::UI, |
| 46 FROM_HERE, |
| 47 base::Bind(callback, error == drive::FILE_ERROR_OK)); |
| 48 } |
| 49 |
| 50 } // namespace |
| 51 |
| 52 bool IsUnderNonNativeLocalPath(Profile* profile, |
| 53 const base::FilePath& path) { |
| 54 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 55 |
| 56 // TODO(kinaba): support other types of volumes besides Drive. |
| 57 return drive::util::IsUnderDriveMountPoint(path); |
| 58 } |
| 59 |
| 60 void GetNonNativeLocalPathMimeType( |
| 61 Profile* profile, |
| 62 const base::FilePath& path, |
| 63 const base::Callback<void(bool, const std::string&)>& callback) { |
| 64 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 65 |
| 66 // TODO(kinaba): support other types of volumes besides Drive. |
| 67 drive::FileSystemInterface* file_system = |
| 68 drive::util::GetFileSystemByProfile(profile); |
| 69 if (!file_system) { |
| 70 content::BrowserThread::PostTask( |
| 71 content::BrowserThread::UI, |
| 72 FROM_HERE, |
| 73 base::Bind(callback, false, std::string())); |
| 74 return; |
| 75 } |
| 76 |
| 77 file_system->GetResourceEntry( |
| 78 drive::util::ExtractDrivePath(path), |
| 79 base::Bind(&GetMimeTypeAfterGetResourceEntry, callback)); |
| 80 } |
| 81 |
| 82 void IsNonNativeLocalPathDirectory( |
| 83 Profile* profile, |
| 84 const base::FilePath& path, |
| 85 const base::Callback<void(bool)>& callback) { |
| 86 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 87 |
| 88 // TODO(kinaba): support other types of volumes besides Drive. |
| 89 drive::util::CheckDirectoryExists( |
| 90 profile, |
| 91 path, |
| 92 base::Bind(&CheckDirectoryAfterDriveCheck, callback)); |
| 93 } |
| 94 |
| 95 void PrepareNonNativeLocalPathWritableFile( |
| 96 Profile* profile, |
| 97 const base::FilePath& path, |
| 98 const base::Callback<void(bool)>& callback) { |
| 99 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 100 |
| 101 // TODO(kinaba): support other types of volumes besides Drive. |
| 102 drive::util::PrepareWritableFileAndRun( |
| 103 profile, |
| 104 path, |
| 105 base::Bind(&CheckWritableAfterDriveCheck, callback)); |
| 106 } |
| 107 |
| 108 } // namespace util |
| 109 } // namespace file_manager |
OLD | NEW |