| 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/chromeos/file_manager/fileapi_util.h" | 5 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 FileDefinitionListConverter(Profile* profile, | 68 FileDefinitionListConverter(Profile* profile, |
| 69 const std::string& extension_id, | 69 const std::string& extension_id, |
| 70 const FileDefinitionList& file_definition_list, | 70 const FileDefinitionList& file_definition_list, |
| 71 const EntryDefinitionListCallback& callback); | 71 const EntryDefinitionListCallback& callback); |
| 72 ~FileDefinitionListConverter() {} | 72 ~FileDefinitionListConverter() {} |
| 73 | 73 |
| 74 private: | 74 private: |
| 75 // Converts the element under the iterator to an entry. First, converts | 75 // Converts the element under the iterator to an entry. First, converts |
| 76 // the virtual path to an URL, and calls OnResolvedURL(). In case of error | 76 // the virtual path to an URL, and calls OnResolvedURL(). In case of error |
| 77 // calls OnIteratorConverted with an error entry definition. | 77 // calls OnIteratorConverted with an error entry definition. |
| 78 void ConvertNextIterator(scoped_ptr<FileDefinitionListConverter> self_deleter, | 78 void ConvertNextIterator( |
| 79 FileDefinitionList::const_iterator iterator); | 79 std::unique_ptr<FileDefinitionListConverter> self_deleter, |
| 80 FileDefinitionList::const_iterator iterator); |
| 80 | 81 |
| 81 // Creates an entry definition from the URL as well as the file definition. | 82 // Creates an entry definition from the URL as well as the file definition. |
| 82 // Then, calls OnIteratorConverted with the created entry definition. | 83 // Then, calls OnIteratorConverted with the created entry definition. |
| 83 void OnResolvedURL(scoped_ptr<FileDefinitionListConverter> self_deleter, | 84 void OnResolvedURL(std::unique_ptr<FileDefinitionListConverter> self_deleter, |
| 84 FileDefinitionList::const_iterator iterator, | 85 FileDefinitionList::const_iterator iterator, |
| 85 base::File::Error error, | 86 base::File::Error error, |
| 86 const storage::FileSystemInfo& info, | 87 const storage::FileSystemInfo& info, |
| 87 const base::FilePath& file_path, | 88 const base::FilePath& file_path, |
| 88 storage::FileSystemContext::ResolvedEntryType type); | 89 storage::FileSystemContext::ResolvedEntryType type); |
| 89 | 90 |
| 90 // Called when the iterator is converted. Adds the |entry_definition| to | 91 // Called when the iterator is converted. Adds the |entry_definition| to |
| 91 // |results_| and calls ConvertNextIterator() for the next element. | 92 // |results_| and calls ConvertNextIterator() for the next element. |
| 92 void OnIteratorConverted(scoped_ptr<FileDefinitionListConverter> self_deleter, | 93 void OnIteratorConverted( |
| 93 FileDefinitionList::const_iterator iterator, | 94 std::unique_ptr<FileDefinitionListConverter> self_deleter, |
| 94 const EntryDefinition& entry_definition); | 95 FileDefinitionList::const_iterator iterator, |
| 96 const EntryDefinition& entry_definition); |
| 95 | 97 |
| 96 scoped_refptr<storage::FileSystemContext> file_system_context_; | 98 scoped_refptr<storage::FileSystemContext> file_system_context_; |
| 97 const std::string extension_id_; | 99 const std::string extension_id_; |
| 98 const FileDefinitionList file_definition_list_; | 100 const FileDefinitionList file_definition_list_; |
| 99 const EntryDefinitionListCallback callback_; | 101 const EntryDefinitionListCallback callback_; |
| 100 scoped_ptr<EntryDefinitionList> result_; | 102 std::unique_ptr<EntryDefinitionList> result_; |
| 101 }; | 103 }; |
| 102 | 104 |
| 103 FileDefinitionListConverter::FileDefinitionListConverter( | 105 FileDefinitionListConverter::FileDefinitionListConverter( |
| 104 Profile* profile, | 106 Profile* profile, |
| 105 const std::string& extension_id, | 107 const std::string& extension_id, |
| 106 const FileDefinitionList& file_definition_list, | 108 const FileDefinitionList& file_definition_list, |
| 107 const EntryDefinitionListCallback& callback) | 109 const EntryDefinitionListCallback& callback) |
| 108 : extension_id_(extension_id), | 110 : extension_id_(extension_id), |
| 109 file_definition_list_(file_definition_list), | 111 file_definition_list_(file_definition_list), |
| 110 callback_(callback), | 112 callback_(callback), |
| 111 result_(new EntryDefinitionList) { | 113 result_(new EntryDefinitionList) { |
| 112 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 114 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 113 | 115 |
| 114 // File browser APIs are meant to be used only from extension context, so | 116 // File browser APIs are meant to be used only from extension context, so |
| 115 // the extension's site is the one in whose file system context the virtual | 117 // the extension's site is the one in whose file system context the virtual |
| 116 // path should be found. | 118 // path should be found. |
| 117 GURL site = extensions::util::GetSiteForExtensionId(extension_id_, profile); | 119 GURL site = extensions::util::GetSiteForExtensionId(extension_id_, profile); |
| 118 file_system_context_ = | 120 file_system_context_ = |
| 119 content::BrowserContext::GetStoragePartitionForSite( | 121 content::BrowserContext::GetStoragePartitionForSite( |
| 120 profile, site)->GetFileSystemContext(); | 122 profile, site)->GetFileSystemContext(); |
| 121 | 123 |
| 122 // Deletes the converter, once the scoped pointer gets out of scope. It is | 124 // Deletes the converter, once the scoped pointer gets out of scope. It is |
| 123 // either, if the conversion is finished, or ResolveURL() is terminated, and | 125 // either, if the conversion is finished, or ResolveURL() is terminated, and |
| 124 // the callback not called because of shutdown. | 126 // the callback not called because of shutdown. |
| 125 scoped_ptr<FileDefinitionListConverter> self_deleter(this); | 127 std::unique_ptr<FileDefinitionListConverter> self_deleter(this); |
| 126 ConvertNextIterator(std::move(self_deleter), file_definition_list_.begin()); | 128 ConvertNextIterator(std::move(self_deleter), file_definition_list_.begin()); |
| 127 } | 129 } |
| 128 | 130 |
| 129 void FileDefinitionListConverter::ConvertNextIterator( | 131 void FileDefinitionListConverter::ConvertNextIterator( |
| 130 scoped_ptr<FileDefinitionListConverter> self_deleter, | 132 std::unique_ptr<FileDefinitionListConverter> self_deleter, |
| 131 FileDefinitionList::const_iterator iterator) { | 133 FileDefinitionList::const_iterator iterator) { |
| 132 if (iterator == file_definition_list_.end()) { | 134 if (iterator == file_definition_list_.end()) { |
| 133 // The converter object will be destroyed since |self_deleter| gets out of | 135 // The converter object will be destroyed since |self_deleter| gets out of |
| 134 // scope. | 136 // scope. |
| 135 callback_.Run(std::move(result_)); | 137 callback_.Run(std::move(result_)); |
| 136 return; | 138 return; |
| 137 } | 139 } |
| 138 | 140 |
| 139 if (!file_system_context_.get()) { | 141 if (!file_system_context_.get()) { |
| 140 OnIteratorConverted(std::move(self_deleter), iterator, | 142 OnIteratorConverted(std::move(self_deleter), iterator, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 153 // of shutdown during ResolveURL(). | 155 // of shutdown during ResolveURL(). |
| 154 file_system_context_->ResolveURL( | 156 file_system_context_->ResolveURL( |
| 155 url, | 157 url, |
| 156 base::Bind(&FileDefinitionListConverter::OnResolvedURL, | 158 base::Bind(&FileDefinitionListConverter::OnResolvedURL, |
| 157 base::Unretained(this), | 159 base::Unretained(this), |
| 158 base::Passed(&self_deleter), | 160 base::Passed(&self_deleter), |
| 159 iterator)); | 161 iterator)); |
| 160 } | 162 } |
| 161 | 163 |
| 162 void FileDefinitionListConverter::OnResolvedURL( | 164 void FileDefinitionListConverter::OnResolvedURL( |
| 163 scoped_ptr<FileDefinitionListConverter> self_deleter, | 165 std::unique_ptr<FileDefinitionListConverter> self_deleter, |
| 164 FileDefinitionList::const_iterator iterator, | 166 FileDefinitionList::const_iterator iterator, |
| 165 base::File::Error error, | 167 base::File::Error error, |
| 166 const storage::FileSystemInfo& info, | 168 const storage::FileSystemInfo& info, |
| 167 const base::FilePath& file_path, | 169 const base::FilePath& file_path, |
| 168 storage::FileSystemContext::ResolvedEntryType type) { | 170 storage::FileSystemContext::ResolvedEntryType type) { |
| 169 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 171 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 170 | 172 |
| 171 if (error != base::File::FILE_OK) { | 173 if (error != base::File::FILE_OK) { |
| 172 OnIteratorConverted(std::move(self_deleter), iterator, | 174 OnIteratorConverted(std::move(self_deleter), iterator, |
| 173 CreateEntryDefinitionWithError(error)); | 175 CreateEntryDefinitionWithError(error)); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 197 DCHECK(root_virtual_path == iterator->virtual_path || | 199 DCHECK(root_virtual_path == iterator->virtual_path || |
| 198 root_virtual_path.IsParent(iterator->virtual_path)); | 200 root_virtual_path.IsParent(iterator->virtual_path)); |
| 199 base::FilePath full_path; | 201 base::FilePath full_path; |
| 200 root_virtual_path.AppendRelativePath(iterator->virtual_path, &full_path); | 202 root_virtual_path.AppendRelativePath(iterator->virtual_path, &full_path); |
| 201 entry_definition.full_path = full_path; | 203 entry_definition.full_path = full_path; |
| 202 | 204 |
| 203 OnIteratorConverted(std::move(self_deleter), iterator, entry_definition); | 205 OnIteratorConverted(std::move(self_deleter), iterator, entry_definition); |
| 204 } | 206 } |
| 205 | 207 |
| 206 void FileDefinitionListConverter::OnIteratorConverted( | 208 void FileDefinitionListConverter::OnIteratorConverted( |
| 207 scoped_ptr<FileDefinitionListConverter> self_deleter, | 209 std::unique_ptr<FileDefinitionListConverter> self_deleter, |
| 208 FileDefinitionList::const_iterator iterator, | 210 FileDefinitionList::const_iterator iterator, |
| 209 const EntryDefinition& entry_definition) { | 211 const EntryDefinition& entry_definition) { |
| 210 result_->push_back(entry_definition); | 212 result_->push_back(entry_definition); |
| 211 ConvertNextIterator(std::move(self_deleter), ++iterator); | 213 ConvertNextIterator(std::move(self_deleter), ++iterator); |
| 212 } | 214 } |
| 213 | 215 |
| 214 // Helper function to return the converted definition entry directly, without | 216 // Helper function to return the converted definition entry directly, without |
| 215 // the redundant container. | 217 // the redundant container. |
| 216 void OnConvertFileDefinitionDone( | 218 void OnConvertFileDefinitionDone( |
| 217 const EntryDefinitionCallback& callback, | 219 const EntryDefinitionCallback& callback, |
| 218 scoped_ptr<EntryDefinitionList> entry_definition_list) { | 220 std::unique_ptr<EntryDefinitionList> entry_definition_list) { |
| 219 DCHECK_EQ(1u, entry_definition_list->size()); | 221 DCHECK_EQ(1u, entry_definition_list->size()); |
| 220 callback.Run(entry_definition_list->at(0)); | 222 callback.Run(entry_definition_list->at(0)); |
| 221 } | 223 } |
| 222 | 224 |
| 223 // Checks if the |file_path| points non-native location or not. | 225 // Checks if the |file_path| points non-native location or not. |
| 224 bool IsUnderNonNativeLocalPath(const storage::FileSystemContext& context, | 226 bool IsUnderNonNativeLocalPath(const storage::FileSystemContext& context, |
| 225 const base::FilePath& file_path) { | 227 const base::FilePath& file_path) { |
| 226 base::FilePath virtual_path; | 228 base::FilePath virtual_path; |
| 227 if (!context.external_backend()->GetVirtualPath(file_path, &virtual_path)) | 229 if (!context.external_backend()->GetVirtualPath(file_path, &virtual_path)) |
| 228 return false; | 230 return false; |
| 229 | 231 |
| 230 const storage::FileSystemURL url = context.CreateCrackedFileSystemURL( | 232 const storage::FileSystemURL url = context.CreateCrackedFileSystemURL( |
| 231 GURL(), storage::kFileSystemTypeExternal, virtual_path); | 233 GURL(), storage::kFileSystemTypeExternal, virtual_path); |
| 232 if (!url.is_valid()) | 234 if (!url.is_valid()) |
| 233 return false; | 235 return false; |
| 234 | 236 |
| 235 return IsNonNativeFileSystemType(url.type()); | 237 return IsNonNativeFileSystemType(url.type()); |
| 236 } | 238 } |
| 237 | 239 |
| 238 // Helper class to convert SelectedFileInfoList into ChooserFileInfoList. | 240 // Helper class to convert SelectedFileInfoList into ChooserFileInfoList. |
| 239 class ConvertSelectedFileInfoListToFileChooserFileInfoListImpl { | 241 class ConvertSelectedFileInfoListToFileChooserFileInfoListImpl { |
| 240 public: | 242 public: |
| 241 // The scoped pointer to control lifetime of the instance itself. The pointer | 243 // The scoped pointer to control lifetime of the instance itself. The pointer |
| 242 // is passed to callback functions and binds the lifetime of the instance to | 244 // is passed to callback functions and binds the lifetime of the instance to |
| 243 // the callback's lifetime. | 245 // the callback's lifetime. |
| 244 typedef scoped_ptr<ConvertSelectedFileInfoListToFileChooserFileInfoListImpl> | 246 typedef std::unique_ptr< |
| 247 ConvertSelectedFileInfoListToFileChooserFileInfoListImpl> |
| 245 Lifetime; | 248 Lifetime; |
| 246 | 249 |
| 247 ConvertSelectedFileInfoListToFileChooserFileInfoListImpl( | 250 ConvertSelectedFileInfoListToFileChooserFileInfoListImpl( |
| 248 storage::FileSystemContext* context, | 251 storage::FileSystemContext* context, |
| 249 const GURL& origin, | 252 const GURL& origin, |
| 250 const SelectedFileInfoList& selected_info_list, | 253 const SelectedFileInfoList& selected_info_list, |
| 251 const FileChooserFileInfoListCallback& callback) | 254 const FileChooserFileInfoListCallback& callback) |
| 252 : context_(context), | 255 : context_(context), |
| 253 chooser_info_list_(new FileChooserFileInfoList), | 256 chooser_info_list_(new FileChooserFileInfoList), |
| 254 callback_(callback) { | 257 callback_(callback) { |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 chooser_info_list_.reset(); | 395 chooser_info_list_.reset(); |
| 393 } | 396 } |
| 394 | 397 |
| 395 // Returns an empty list to the |callback_|. | 398 // Returns an empty list to the |callback_|. |
| 396 void NotifyError(Lifetime /* lifetime */) { | 399 void NotifyError(Lifetime /* lifetime */) { |
| 397 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 400 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 398 callback_.Run(FileChooserFileInfoList()); | 401 callback_.Run(FileChooserFileInfoList()); |
| 399 } | 402 } |
| 400 | 403 |
| 401 scoped_refptr<storage::FileSystemContext> context_; | 404 scoped_refptr<storage::FileSystemContext> context_; |
| 402 scoped_ptr<FileChooserFileInfoList> chooser_info_list_; | 405 std::unique_ptr<FileChooserFileInfoList> chooser_info_list_; |
| 403 const FileChooserFileInfoListCallback callback_; | 406 const FileChooserFileInfoListCallback callback_; |
| 404 | 407 |
| 405 DISALLOW_COPY_AND_ASSIGN( | 408 DISALLOW_COPY_AND_ASSIGN( |
| 406 ConvertSelectedFileInfoListToFileChooserFileInfoListImpl); | 409 ConvertSelectedFileInfoListToFileChooserFileInfoListImpl); |
| 407 }; | 410 }; |
| 408 | 411 |
| 409 } // namespace | 412 } // namespace |
| 410 | 413 |
| 411 EntryDefinition::EntryDefinition() { | 414 EntryDefinition::EntryDefinition() { |
| 412 } | 415 } |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 const storage::FileSystemURL isolated_url = | 596 const storage::FileSystemURL isolated_url = |
| 594 context.CreateCrackedFileSystemURL( | 597 context.CreateCrackedFileSystemURL( |
| 595 origin, | 598 origin, |
| 596 storage::kFileSystemTypeIsolated, | 599 storage::kFileSystemTypeIsolated, |
| 597 base::FilePath(isolated_file_system_id).Append(register_name)); | 600 base::FilePath(isolated_file_system_id).Append(register_name)); |
| 598 return isolated_url; | 601 return isolated_url; |
| 599 } | 602 } |
| 600 | 603 |
| 601 } // namespace util | 604 } // namespace util |
| 602 } // namespace file_manager | 605 } // namespace file_manager |
| OLD | NEW |