| 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 #ifndef CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_FILE_SYSTEM_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_FILE_SYSTEM_API_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_FILE_SYSTEM_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_FILE_SYSTEM_API_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/files/file.h" | 12 #include "base/files/file.h" |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/task_scheduler/post_task.h" |
| 16 #include "base/values.h" | 17 #include "base/values.h" |
| 17 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 18 #include "chrome/browser/extensions/chrome_extension_function.h" | 19 #include "chrome/browser/extensions/chrome_extension_function.h" |
| 19 #include "chrome/browser/extensions/chrome_extension_function_details.h" | 20 #include "chrome/browser/extensions/chrome_extension_function_details.h" |
| 20 #include "chrome/common/extensions/api/file_system.h" | 21 #include "chrome/common/extensions/api/file_system.h" |
| 21 #include "extensions/browser/extension_function.h" | 22 #include "extensions/browser/extension_function.h" |
| 22 #include "ui/base/ui_base_types.h" | 23 #include "ui/base/ui_base_types.h" |
| 23 #include "ui/shell_dialogs/select_file_dialog.h" | 24 #include "ui/shell_dialogs/select_file_dialog.h" |
| 24 | 25 |
| 25 #if defined(OS_CHROMEOS) | 26 #if defined(OS_CHROMEOS) |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 151 |
| 151 protected: | 152 protected: |
| 152 ~FileSystemGetDisplayPathFunction() override {} | 153 ~FileSystemGetDisplayPathFunction() override {} |
| 153 ResponseAction Run() override; | 154 ResponseAction Run() override; |
| 154 }; | 155 }; |
| 155 | 156 |
| 156 class FileSystemEntryFunction : public ChromeAsyncExtensionFunction { | 157 class FileSystemEntryFunction : public ChromeAsyncExtensionFunction { |
| 157 protected: | 158 protected: |
| 158 FileSystemEntryFunction(); | 159 FileSystemEntryFunction(); |
| 159 | 160 |
| 160 ~FileSystemEntryFunction() override {} | 161 ~FileSystemEntryFunction() override; |
| 161 | 162 |
| 162 // This is called when writable file entries are being returned. The function | 163 // This is called when writable file entries are being returned. The function |
| 163 // will ensure the files exist, creating them if necessary, and also check | 164 // will ensure the files exist, creating them if necessary, and also check |
| 164 // that none of the files are links. If it succeeds it proceeds to | 165 // that none of the files are links. If it succeeds it proceeds to |
| 165 // RegisterFileSystemsAndSendResponse, otherwise to HandleWritableFileError. | 166 // RegisterFileSystemsAndSendResponse, otherwise to HandleWritableFileError. |
| 166 void PrepareFilesForWritableApp(const std::vector<base::FilePath>& path); | 167 void PrepareFilesForWritableApp(const std::vector<base::FilePath>& path); |
| 167 | 168 |
| 168 // This will finish the choose file process. This is either called directly | 169 // This will finish the choose file process. This is either called directly |
| 169 // from FilesSelected, or from WritableFileChecker. It is called on the UI | 170 // from FilesSelected, or from WritableFileChecker. It is called on the UI |
| 170 // thread. | 171 // thread. |
| 171 void RegisterFileSystemsAndSendResponse( | 172 void RegisterFileSystemsAndSendResponse( |
| 172 const std::vector<base::FilePath>& path); | 173 const std::vector<base::FilePath>& path); |
| 173 | 174 |
| 174 // Creates a result dictionary. | 175 // Creates a result dictionary. |
| 175 std::unique_ptr<base::DictionaryValue> CreateResult(); | 176 std::unique_ptr<base::DictionaryValue> CreateResult(); |
| 176 | 177 |
| 177 // Adds an entry to the result dictionary. | 178 // Adds an entry to the result dictionary. |
| 178 void AddEntryToResult(const base::FilePath& path, | 179 void AddEntryToResult(const base::FilePath& path, |
| 179 const std::string& id_override, | 180 const std::string& id_override, |
| 180 base::DictionaryValue* result); | 181 base::DictionaryValue* result); |
| 181 | 182 |
| 182 // called on the UI thread if there is a problem checking a writable file. | 183 // called on the UI thread if there is a problem checking a writable file. |
| 183 void HandleWritableFileError(const base::FilePath& error_path); | 184 void HandleWritableFileError(const base::FilePath& error_path); |
| 184 | 185 |
| 185 // Whether multiple entries have been requested. | 186 // Whether multiple entries have been requested. |
| 186 bool multiple_; | 187 bool multiple_; |
| 187 | 188 |
| 188 // Whether a directory has been requested. | 189 // Whether a directory has been requested. |
| 189 bool is_directory_; | 190 bool is_directory_; |
| 191 |
| 192 // The task runner used to do file operations. |
| 193 const scoped_refptr<base::SequencedTaskRunner> task_runner_ = |
| 194 base::CreateSequencedTaskRunnerWithTraits( |
| 195 {base::MayBlock(), base::TaskPriority::BACKGROUND}); |
| 190 }; | 196 }; |
| 191 | 197 |
| 192 class FileSystemGetWritableEntryFunction : public FileSystemEntryFunction { | 198 class FileSystemGetWritableEntryFunction : public FileSystemEntryFunction { |
| 193 public: | 199 public: |
| 194 DECLARE_EXTENSION_FUNCTION("fileSystem.getWritableEntry", | 200 DECLARE_EXTENSION_FUNCTION("fileSystem.getWritableEntry", |
| 195 FILESYSTEM_GETWRITABLEENTRY) | 201 FILESYSTEM_GETWRITABLEENTRY) |
| 196 | 202 |
| 197 protected: | 203 protected: |
| 198 ~FileSystemGetWritableEntryFunction() override {} | 204 ~FileSystemGetWritableEntryFunction() override {} |
| 199 bool RunAsync() override; | 205 bool RunAsync() override; |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 ExtensionFunction::ResponseAction Run() override; | 418 ExtensionFunction::ResponseAction Run() override; |
| 413 | 419 |
| 414 private: | 420 private: |
| 415 ChromeExtensionFunctionDetails chrome_details_; | 421 ChromeExtensionFunctionDetails chrome_details_; |
| 416 }; | 422 }; |
| 417 #endif | 423 #endif |
| 418 | 424 |
| 419 } // namespace extensions | 425 } // namespace extensions |
| 420 | 426 |
| 421 #endif // CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_FILE_SYSTEM_API_H_ | 427 #endif // CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_FILE_SYSTEM_API_H_ |
| OLD | NEW |