| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/file_manager/filesystem_api_util.h" | 5 #include "chrome/browser/chromeos/file_manager/filesystem_api_util.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "chrome/browser/chromeos/drive/file_errors.h" | 10 #include "chrome/browser/chromeos/drive/file_errors.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 scoped_ptr<drive::ResourceEntry> entry) { | 29 scoped_ptr<drive::ResourceEntry> entry) { |
| 30 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 30 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 31 | 31 |
| 32 if (error != drive::FILE_ERROR_OK || !entry->has_file_specific_info()) { | 32 if (error != drive::FILE_ERROR_OK || !entry->has_file_specific_info()) { |
| 33 callback.Run(false, std::string()); | 33 callback.Run(false, std::string()); |
| 34 return; | 34 return; |
| 35 } | 35 } |
| 36 callback.Run(true, entry->file_specific_info().content_mime_type()); | 36 callback.Run(true, entry->file_specific_info().content_mime_type()); |
| 37 } | 37 } |
| 38 | 38 |
| 39 void CheckDirectoryAfterDriveCheck(const base::Callback<void(bool)>& callback, | 39 // Helper function to converts a callback that takes boolean value to that takes |
| 40 drive::FileError error) { | 40 // File::Error, by regarding FILE_OK as the only successful value. |
| 41 void BoolCallbackAsFileErrorCallback( |
| 42 const base::Callback<void(bool)>& callback, |
| 43 base::File::Error error) { |
| 41 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 44 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 42 | 45 |
| 43 return callback.Run(error == drive::FILE_ERROR_OK); | 46 return callback.Run(error == base::File::FILE_OK); |
| 44 } | 47 } |
| 45 | 48 |
| 46 void CheckWritableAfterDriveCheck(const base::Callback<void(bool)>& callback, | 49 void CheckWritableAfterDriveCheck(const base::Callback<void(bool)>& callback, |
| 47 drive::FileError error, | 50 drive::FileError error, |
| 48 const base::FilePath& local_path) { | 51 const base::FilePath& local_path) { |
| 49 // This is called on the IO-allowed blocking pool. Call back to UI. | 52 // This is called on the IO-allowed blocking pool. Call back to UI. |
| 50 content::BrowserThread::PostTask( | 53 content::BrowserThread::PostTask( |
| 51 content::BrowserThread::UI, | 54 content::BrowserThread::UI, |
| 52 FROM_HERE, | 55 FROM_HERE, |
| 53 base::Bind(callback, error == drive::FILE_ERROR_OK)); | 56 base::Bind(callback, error == drive::FILE_ERROR_OK)); |
| 54 } | 57 } |
| 55 | 58 |
| 56 } // namespace | 59 } // namespace |
| 57 | 60 |
| 58 bool IsUnderNonNativeLocalPath(Profile* profile, | 61 bool IsUnderNonNativeLocalPath(Profile* profile, |
| 59 const base::FilePath& path) { | 62 const base::FilePath& path) { |
| 60 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 63 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 61 | 64 |
| 62 GURL url; | 65 GURL url; |
| 63 if (!util::ConvertAbsoluteFilePathToFileSystemUrl( | 66 if (!util::ConvertAbsoluteFilePathToFileSystemUrl( |
| 64 profile, path, kFileManagerAppId, &url)) { | 67 profile, path, kFileManagerAppId, &url)) { |
| 65 return false; | 68 return false; |
| 66 } | 69 } |
| 67 | 70 |
| 68 content::StoragePartition* partition = | 71 fileapi::FileSystemURL filesystem_url = |
| 69 content::BrowserContext::GetStoragePartitionForSite( | 72 GetFileSystemContextForExtensionId(profile, |
| 70 profile, | 73 kFileManagerAppId)->CrackURL(url); |
| 71 extensions::util::GetSiteForExtensionId(kFileManagerAppId, profile)); | |
| 72 fileapi::FileSystemContext* context = partition->GetFileSystemContext(); | |
| 73 | |
| 74 fileapi::FileSystemURL filesystem_url = context->CrackURL(url); | |
| 75 if (!filesystem_url.is_valid()) | 74 if (!filesystem_url.is_valid()) |
| 76 return false; | 75 return false; |
| 77 | 76 |
| 78 switch (filesystem_url.type()) { | 77 switch (filesystem_url.type()) { |
| 79 case fileapi::kFileSystemTypeNativeLocal: | 78 case fileapi::kFileSystemTypeNativeLocal: |
| 80 case fileapi::kFileSystemTypeRestrictedNativeLocal: | 79 case fileapi::kFileSystemTypeRestrictedNativeLocal: |
| 81 return false; | 80 return false; |
| 82 default: | 81 default: |
| 83 // The path indeed corresponds to a mount point not associated with a | 82 // The path indeed corresponds to a mount point not associated with a |
| 84 // native local path. | 83 // native local path. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 file_system->GetResourceEntry( | 115 file_system->GetResourceEntry( |
| 117 drive::util::ExtractDrivePath(path), | 116 drive::util::ExtractDrivePath(path), |
| 118 base::Bind(&GetMimeTypeAfterGetResourceEntry, callback)); | 117 base::Bind(&GetMimeTypeAfterGetResourceEntry, callback)); |
| 119 } | 118 } |
| 120 | 119 |
| 121 void IsNonNativeLocalPathDirectory( | 120 void IsNonNativeLocalPathDirectory( |
| 122 Profile* profile, | 121 Profile* profile, |
| 123 const base::FilePath& path, | 122 const base::FilePath& path, |
| 124 const base::Callback<void(bool)>& callback) { | 123 const base::Callback<void(bool)>& callback) { |
| 125 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 124 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 125 DCHECK(IsUnderNonNativeLocalPath(profile, path)); |
| 126 | 126 |
| 127 // TODO(kinaba): support other types of volumes besides Drive. | 127 GURL url; |
| 128 drive::util::CheckDirectoryExists( | 128 if (!util::ConvertAbsoluteFilePathToFileSystemUrl( |
| 129 profile, | 129 profile, path, kFileManagerAppId, &url)) { |
| 130 path, | 130 // Posting to the current thread, so that we always call back asynchronously |
| 131 base::Bind(&CheckDirectoryAfterDriveCheck, callback)); | 131 // independent from whether or not the operation succeeeds. |
| 132 content::BrowserThread::PostTask(content::BrowserThread::UI, |
| 133 FROM_HERE, |
| 134 base::Bind(callback, false)); |
| 135 return; |
| 136 } |
| 137 |
| 138 util::CheckIfDirectoryExists( |
| 139 GetFileSystemContextForExtensionId(profile, kFileManagerAppId), |
| 140 url, |
| 141 base::Bind(&BoolCallbackAsFileErrorCallback, callback)); |
| 132 } | 142 } |
| 133 | 143 |
| 134 void PrepareNonNativeLocalPathWritableFile( | 144 void PrepareNonNativeLocalPathWritableFile( |
| 135 Profile* profile, | 145 Profile* profile, |
| 136 const base::FilePath& path, | 146 const base::FilePath& path, |
| 137 const base::Callback<void(bool)>& callback) { | 147 const base::Callback<void(bool)>& callback) { |
| 138 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 148 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 139 | 149 |
| 140 // TODO(kinaba): support other types of volumes besides Drive. | 150 // TODO(kinaba): support other types of volumes besides Drive. |
| 141 drive::util::PrepareWritableFileAndRun( | 151 drive::util::PrepareWritableFileAndRun( |
| 142 profile, | 152 profile, |
| 143 path, | 153 path, |
| 144 base::Bind(&CheckWritableAfterDriveCheck, callback)); | 154 base::Bind(&CheckWritableAfterDriveCheck, callback)); |
| 145 } | 155 } |
| 146 | 156 |
| 147 } // namespace util | 157 } // namespace util |
| 148 } // namespace file_manager | 158 } // namespace file_manager |
| OLD | NEW |