| 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/file_browser_handler.h" | 13 #include "chrome/common/extensions/file_browser_handler.h" |
| 14 #include "chrome/common/extensions/url_pattern_set.h" | 14 #include "chrome/common/extensions/url_pattern_set.h" |
| 15 | 15 |
| 16 class Browser; | 16 class Browser; |
| 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 |
| 30 void UpdateFileHandlerUsageStats(Profile* profile, const std::string& task_id); |
| 31 |
| 22 // Update the default file handler for the given sets of suffixes and MIME | 32 // Update the default file handler for the given sets of suffixes and MIME |
| 23 // types. | 33 // types. |
| 24 void UpdateDefaultTask(Profile* profile, | 34 void UpdateDefaultTask(Profile* profile, |
| 25 const std::string& task_id, | 35 const std::string& task_id, |
| 26 const std::set<std::string>& suffixes, | 36 const std::set<std::string>& suffixes, |
| 27 const std::set<std::string>& mime_types); | 37 const std::set<std::string>& mime_types); |
| 28 | 38 |
| 29 // Returns the task ID of the default task for the given |mime_type|/|suffix| | 39 // Returns the task ID of the default task for the given |mime_type|/|suffix| |
| 30 // combination. If it finds a MIME type match, then it prefers that over a | 40 // combination. If it finds a MIME type match, then it prefers that over a |
| 31 // suffix match. If it a default can't be found, then it returns the empty | 41 // suffix match. If it a default can't be found, then it returns the empty |
| 32 // string. | 42 // string. |
| 33 std::string GetDefaultTaskIdFromPrefs(Profile* profile, | 43 std::string GetDefaultTaskIdFromPrefs(Profile* profile, |
| 34 const std::string& mime_type, | 44 const std::string& mime_type, |
| 35 const std::string& suffix); | 45 const std::string& suffix); |
| 36 | 46 |
| 37 // Gets read-write file access permission flags. | 47 // Gets read-write file access permission flags. |
| 38 int GetReadWritePermissions(); | 48 int GetReadWritePermissions(); |
| 39 // Gets read-only file access permission flags. | 49 // Gets read-only file access permission flags. |
| 40 int GetReadOnlyPermissions(); | 50 int GetReadOnlyPermissions(); |
| 41 | 51 |
| 42 // Generates file task id for the file action specified by the extension. | 52 // Generates task id for the action specified by the extension. |
| 43 std::string MakeTaskID(const std::string& extension_id, | 53 std::string MakeTaskID(const std::string& extension_id, |
| 54 TaskType task_type, |
| 44 const std::string& action_id); | 55 const std::string& action_id); |
| 45 | 56 |
| 46 // Make a task id specific to drive apps instead of extensions. | 57 // Extracts action, type and extension id bound to the file task. Either |
| 47 std::string MakeDriveTaskID(const std::string& app_id, | |
| 48 const std::string& action_id); | |
| 49 | |
| 50 // Returns the |target_id| and |action_id| of a drive app or extension, given | |
| 51 // the drive |task_id| created by MakeDriveTaskID. If the |task_id| is a drive | |
| 52 // task_id then it will return true. If not, or if parsing fails, will return | |
| 53 // false and not set |app_id| or |action_id|. | |
| 54 bool CrackDriveTaskID(const std::string& task_id, | |
| 55 std::string* app_id, | |
| 56 std::string* action_id); | |
| 57 | |
| 58 // Extracts action and extension id bound to the file task. Either | |
| 59 // |target_extension_id| or |action_id| are allowed to be NULL if caller isn't | 58 // |target_extension_id| or |action_id| are allowed to be NULL if caller isn't |
| 60 // interested in those values. Returns false on failure to parse. | 59 // interested in those values. Returns false on failure to parse. |
| 61 bool CrackTaskID(const std::string& task_id, | 60 bool CrackTaskID(const std::string& task_id, |
| 62 std::string* target_extension_id, | 61 std::string* target_extension_id, |
| 62 TaskType* task_type, |
| 63 std::string* action_id); | 63 std::string* action_id); |
| 64 | 64 |
| 65 // This generates a list of default tasks (tasks set as default by the user in | 65 // This generates a list of default tasks (tasks set as default by the user in |
| 66 // prefs) from the |common_tasks|. | 66 // prefs) from the |common_tasks|. |
| 67 void FindDefaultTasks(Profile* profile, | 67 void FindDefaultTasks(Profile* profile, |
| 68 const std::vector<GURL>& files_list, | 68 const std::vector<GURL>& files_list, |
| 69 const std::set<const FileBrowserHandler*>& common_tasks, | 69 const std::set<const FileBrowserHandler*>& common_tasks, |
| 70 std::set<const FileBrowserHandler*>* default_tasks); | 70 std::set<const FileBrowserHandler*>* default_tasks); |
| 71 | 71 |
| 72 // This generates list of tasks common for all files in |file_list|. | 72 // This generates list of tasks common for all files in |file_list|. |
| 73 bool FindCommonTasks(Profile* profile, | 73 bool FindCommonTasks(Profile* profile, |
| 74 const std::vector<GURL>& files_list, | 74 const std::vector<GURL>& files_list, |
| 75 std::set<const FileBrowserHandler*>* common_tasks); | 75 std::set<const FileBrowserHandler*>* common_tasks); |
| 76 | 76 |
| 77 // Find the default task for a file whose url is |url|. (The default task is the | 77 // Find the default task for a file whose url is |url|. (The default task is the |
| 78 // task that is assigned to file browser task button by default). | 78 // task that is assigned to file browser task button by default). |
| 79 bool GetDefaultTask(Profile* profile, | 79 bool GetDefaultTask(Profile* profile, |
| 80 const GURL& url, | 80 const GURL& url, |
| 81 const FileBrowserHandler** handler); | 81 const FileBrowserHandler** handler); |
| 82 | 82 |
| 83 // Used for returning success or failure from task executions. | 83 // Used for returning success or failure from task executions. |
| 84 typedef base::Callback<void(bool)> FileTaskFinishedCallback; | 84 typedef base::Callback<void(bool)> FileTaskFinishedCallback; |
| 85 | 85 |
| 86 // Helper class for executing file browser file action. | 86 // Helper class for executing file browser file action. |
| 87 class FileTaskExecutor : public base::RefCountedThreadSafe<FileTaskExecutor> { | 87 class FileTaskExecutor : public base::RefCountedThreadSafe<FileTaskExecutor> { |
| 88 public: | 88 public: |
| 89 static const char kDriveTaskExtensionPrefix[]; | |
| 90 static const size_t kDriveTaskExtensionPrefixLength; | |
| 91 | |
| 92 // Creates the appropriate FileTaskExecutor for the given |extension_id|. | 89 // Creates the appropriate FileTaskExecutor for the given |extension_id|. |
| 93 static FileTaskExecutor* Create(Profile* profile, | 90 static FileTaskExecutor* Create(Profile* profile, |
| 94 const GURL source_url, | 91 const GURL source_url, |
| 95 const std::string& extension_id, | 92 const std::string& extension_id, |
| 93 TaskType task_type, |
| 96 const std::string& action_id); | 94 const std::string& action_id); |
| 97 | 95 |
| 98 // Same as ExecuteAndNotify, but no notification is performed. | 96 // Same as ExecuteAndNotify, but no notification is performed. |
| 99 virtual bool Execute(const std::vector<GURL>& file_urls); | 97 virtual bool Execute(const std::vector<GURL>& file_urls); |
| 100 | 98 |
| 101 // Initiates execution of file handler task for each element of |file_urls|. | 99 // Initiates execution of file handler task for each element of |file_urls|. |
| 102 // Return |false| if the execution cannot be initiated. Otherwise returns | 100 // Return |false| if the execution cannot be initiated. Otherwise returns |
| 103 // |true| and then eventually calls |done| when all the files have | 101 // |true| and then eventually calls |done| when all the files have |
| 104 // been handled. If there is an error during processing the list of files, the | 102 // been handled. If there is an error during processing the list of files, the |
| 105 // caller will be informed of the failure via |done|, and the rest of | 103 // caller will be informed of the failure via |done|, and the rest of |
| (...skipping 12 matching lines...) Expand all Loading... |
| 118 Browser* GetBrowser() const; | 116 Browser* GetBrowser() const; |
| 119 private: | 117 private: |
| 120 friend class base::RefCountedThreadSafe<FileTaskExecutor>; | 118 friend class base::RefCountedThreadSafe<FileTaskExecutor>; |
| 121 | 119 |
| 122 Profile* profile_; | 120 Profile* profile_; |
| 123 }; | 121 }; |
| 124 | 122 |
| 125 } // namespace file_handler_util | 123 } // namespace file_handler_util |
| 126 | 124 |
| 127 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_HANDLER_UTIL_H_ | 125 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_HANDLER_UTIL_H_ |
| OLD | NEW |