| 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_CHROMEOS_EXTENSIONS_FILE_HANDLER_UTIL_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_HANDLER_UTIL_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_HANDLER_UTIL_H_ | 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_HANDLER_UTIL_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/platform_file.h" | 11 #include "base/platform_file.h" |
| 12 #include "chrome/common/extensions/extension.h" | 12 #include "chrome/common/extensions/extension.h" |
| 13 #include "chrome/common/extensions/url_pattern_set.h" | 13 #include "chrome/common/extensions/url_pattern_set.h" |
| 14 | 14 |
| 15 class Browser; | 15 class Browser; |
| 16 class FileBrowserHandler; | 16 class FileBrowserHandler; |
| 17 class GURL; | 17 class GURL; |
| 18 class Profile; | 18 class Profile; |
| 19 | 19 |
| 20 namespace file_handler_util { | 20 namespace file_handler_util { |
| 21 | 21 |
| 22 // Specifies the task type for a task id that represents some file action, Drive |
| 23 // action, or Web Intent action. |
| 24 enum TaskType { |
| 25 TASK_FILE = 1, |
| 26 TASK_DRIVE, |
| 27 TASK_WEBINTENT |
| 28 }; |
| 29 |
| 22 void UpdateFileHandlerUsageStats(Profile* profile, const std::string& task_id); | 30 void UpdateFileHandlerUsageStats(Profile* profile, const std::string& task_id); |
| 23 | 31 |
| 24 // Gets read-write file access permission flags. | 32 // Gets read-write file access permission flags. |
| 25 int GetReadWritePermissions(); | 33 int GetReadWritePermissions(); |
| 26 // Gets read-only file access permission flags. | 34 // Gets read-only file access permission flags. |
| 27 int GetReadOnlyPermissions(); | 35 int GetReadOnlyPermissions(); |
| 28 | 36 |
| 29 // Generates file task id for the file action specified by the extension. | 37 // Generates task id for the action specified by the extension. |
| 30 std::string MakeTaskID(const std::string& extension_id, | 38 std::string MakeTaskID(const std::string& extension_id, |
| 39 TaskType task_type, |
| 31 const std::string& action_id); | 40 const std::string& action_id); |
| 32 | 41 |
| 33 // Make a task id specific to drive apps instead of extensions. | 42 // Extracts action, type and extension id bound to the task. |
| 34 std::string MakeDriveTaskID(const std::string& app_id, | |
| 35 const std::string& action_id); | |
| 36 | |
| 37 // Extracts action and extension id bound to the file task. | |
| 38 bool CrackTaskID(const std::string& task_id, | 43 bool CrackTaskID(const std::string& task_id, |
| 39 std::string* target_extension_id, | 44 std::string* target_extension_id, |
| 45 TaskType* task_type, |
| 40 std::string* action_id); | 46 std::string* action_id); |
| 41 | 47 |
| 42 // Struct that keeps track of when a handler was `last used. | 48 // Struct that keeps track of when a handler was `last used. |
| 43 // It is used to determine default file action for a file. | 49 // It is used to determine default file action for a file. |
| 44 struct LastUsedHandler { | 50 struct LastUsedHandler { |
| 45 LastUsedHandler(int t, const FileBrowserHandler* h, URLPatternSet p) | 51 LastUsedHandler(int t, const FileBrowserHandler* h, URLPatternSet p) |
| 46 : timestamp(t), | 52 : timestamp(t), |
| 47 handler(h), | 53 handler(h), |
| 48 patterns(p) { | 54 patterns(p) { |
| 49 } | 55 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 66 bool GetDefaultTask(Profile* profile, | 72 bool GetDefaultTask(Profile* profile, |
| 67 const GURL& url, | 73 const GURL& url, |
| 68 const FileBrowserHandler** handler); | 74 const FileBrowserHandler** handler); |
| 69 | 75 |
| 70 // Used for returning success or failure from task executions. | 76 // Used for returning success or failure from task executions. |
| 71 typedef base::Callback<void(bool)> FileTaskFinishedCallback; | 77 typedef base::Callback<void(bool)> FileTaskFinishedCallback; |
| 72 | 78 |
| 73 // Helper class for executing file browser file action. | 79 // Helper class for executing file browser file action. |
| 74 class FileTaskExecutor : public base::RefCountedThreadSafe<FileTaskExecutor> { | 80 class FileTaskExecutor : public base::RefCountedThreadSafe<FileTaskExecutor> { |
| 75 public: | 81 public: |
| 76 static const char kDriveTaskExtensionPrefix[]; | |
| 77 static const size_t kDriveTaskExtensionPrefixLength; | |
| 78 | |
| 79 // Creates the appropriate FileTaskExecutor for the given |extension_id|. | 82 // Creates the appropriate FileTaskExecutor for the given |extension_id|. |
| 80 static FileTaskExecutor* Create(Profile* profile, | 83 static FileTaskExecutor* Create(Profile* profile, |
| 81 const GURL source_url, | 84 const GURL source_url, |
| 82 const std::string& extension_id, | 85 const std::string& extension_id, |
| 86 TaskType task_type, |
| 83 const std::string& action_id); | 87 const std::string& action_id); |
| 84 | 88 |
| 85 // Same as ExecuteAndNotify, but no notification is performed. | 89 // Same as ExecuteAndNotify, but no notification is performed. |
| 86 virtual bool Execute(const std::vector<GURL>& file_urls); | 90 virtual bool Execute(const std::vector<GURL>& file_urls); |
| 87 | 91 |
| 88 // Initiates execution of file handler task for each element of |file_urls|. | 92 // Initiates execution of file handler task for each element of |file_urls|. |
| 89 // Return |false| if the execution cannot be initiated. Otherwise returns | 93 // Return |false| if the execution cannot be initiated. Otherwise returns |
| 90 // |true| and then eventually calls |done| when all the files have | 94 // |true| and then eventually calls |done| when all the files have |
| 91 // been handled. If there is an error during processing the list of files, the | 95 // been handled. If there is an error during processing the list of files, the |
| 92 // caller will be informed of the failure via |done|, and the rest of | 96 // caller will be informed of the failure via |done|, and the rest of |
| (...skipping 12 matching lines...) Expand all Loading... |
| 105 Browser* GetBrowser() const; | 109 Browser* GetBrowser() const; |
| 106 private: | 110 private: |
| 107 friend class base::RefCountedThreadSafe<FileTaskExecutor>; | 111 friend class base::RefCountedThreadSafe<FileTaskExecutor>; |
| 108 | 112 |
| 109 Profile* profile_; | 113 Profile* profile_; |
| 110 }; | 114 }; |
| 111 | 115 |
| 112 } // namespace file_handler_util | 116 } // namespace file_handler_util |
| 113 | 117 |
| 114 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_HANDLER_UTIL_H_ | 118 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_HANDLER_UTIL_H_ |
| OLD | NEW |