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 <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/platform_file.h" | 12 #include "base/platform_file.h" |
13 #include "chrome/common/extensions/extension.h" | 13 #include "chrome/common/extensions/extension.h" |
14 #include "extensions/common/url_pattern_set.h" | 14 #include "extensions/common/url_pattern_set.h" |
15 | 15 |
16 class Browser; | 16 class Browser; |
17 class FileBrowserHandler; | 17 class FileBrowserHandler; |
18 class GURL; | 18 class GURL; |
19 class Profile; | 19 class Profile; |
20 | 20 |
21 namespace extensions { | 21 namespace extensions { |
22 class Extension; | 22 class Extension; |
23 } // namespace extensions | 23 } // namespace extensions |
24 | 24 |
| 25 namespace fileapi { |
| 26 class FileSystemURL; |
| 27 } |
| 28 |
25 namespace file_handler_util { | 29 namespace file_handler_util { |
26 | 30 |
27 // Specifies the task type for a task id that represents some file action, Drive | 31 // Specifies the task type for a task id that represents some file action, Drive |
28 // action, or Web Intent action. | 32 // action, or Web Intent action. |
29 extern const char kTaskFile[]; | 33 extern const char kTaskFile[]; |
30 extern const char kTaskDrive[]; | 34 extern const char kTaskDrive[]; |
31 extern const char kTaskWebIntent[]; | 35 extern const char kTaskWebIntent[]; |
32 extern const char kTaskApp[]; | 36 extern const char kTaskApp[]; |
33 | 37 |
34 void UpdateFileHandlerUsageStats(Profile* profile, const std::string& task_id); | 38 void UpdateFileHandlerUsageStats(Profile* profile, const std::string& task_id); |
(...skipping 28 matching lines...) Expand all Loading... |
63 // |target_extension_id| or |action_id| are allowed to be NULL if caller isn't | 67 // |target_extension_id| or |action_id| are allowed to be NULL if caller isn't |
64 // interested in those values. Returns false on failure to parse. | 68 // interested in those values. Returns false on failure to parse. |
65 bool CrackTaskID(const std::string& task_id, | 69 bool CrackTaskID(const std::string& task_id, |
66 std::string* target_extension_id, | 70 std::string* target_extension_id, |
67 std::string* task_type, | 71 std::string* task_type, |
68 std::string* action_id); | 72 std::string* action_id); |
69 | 73 |
70 // This generates a list of default tasks (tasks set as default by the user in | 74 // This generates a list of default tasks (tasks set as default by the user in |
71 // prefs) from the |common_tasks|. | 75 // prefs) from the |common_tasks|. |
72 void FindDefaultTasks(Profile* profile, | 76 void FindDefaultTasks(Profile* profile, |
73 const std::vector<GURL>& files_list, | 77 const std::vector<FilePath>& files_list, |
74 const std::set<const FileBrowserHandler*>& common_tasks, | 78 const std::set<const FileBrowserHandler*>& common_tasks, |
75 std::set<const FileBrowserHandler*>* default_tasks); | 79 std::set<const FileBrowserHandler*>* default_tasks); |
76 | 80 |
77 // This generates list of tasks common for all files in |file_list|. | 81 // This generates list of tasks common for all files in |file_list|. |
78 bool FindCommonTasks(Profile* profile, | 82 bool FindCommonTasks(Profile* profile, |
79 const std::vector<GURL>& files_list, | 83 const std::vector<GURL>& files_list, |
80 std::set<const FileBrowserHandler*>* common_tasks); | 84 std::set<const FileBrowserHandler*>* common_tasks); |
81 | 85 |
82 // Finds a task for a file whose URL is |url|. | 86 // Finds a task for a file whose URL is |url| and whose path is |path|. |
83 // Returns default task if one is defined (The default task is the task that is | 87 // Returns default task if one is defined (The default task is the task that is |
84 // assigned to file browser task button by default). If default task is not | 88 // assigned to file browser task button by default). If default task is not |
85 // found, tries to match the url with one of the builtin tasks. | 89 // found, tries to match the url with one of the builtin tasks. |
86 bool GetTaskForURL(Profile* profile, | 90 bool GetTaskForURLAndPath(Profile* profile, |
87 const GURL& url, | 91 const GURL& url, |
88 const FileBrowserHandler** handler); | 92 const FilePath& path, |
| 93 const FileBrowserHandler** handler); |
89 | 94 |
90 // Used for returning success or failure from task executions. | 95 // Used for returning success or failure from task executions. |
91 typedef base::Callback<void(bool)> FileTaskFinishedCallback; | 96 typedef base::Callback<void(bool)> FileTaskFinishedCallback; |
92 | 97 |
93 // Helper class for executing file browser file action. | 98 // Helper class for executing file browser file action. |
94 class FileTaskExecutor : public base::RefCountedThreadSafe<FileTaskExecutor> { | 99 class FileTaskExecutor : public base::RefCountedThreadSafe<FileTaskExecutor> { |
95 public: | 100 public: |
96 // Creates the appropriate FileTaskExecutor for the given |extension_id|. | 101 // Creates the appropriate FileTaskExecutor for the given |extension_id|. |
97 static FileTaskExecutor* Create(Profile* profile, | 102 static FileTaskExecutor* Create(Profile* profile, |
98 const GURL& source_url, | 103 const GURL& source_url, |
99 const std::string& file_browser_id, | 104 const std::string& file_browser_id, |
100 int32 tab_id, | 105 int32 tab_id, |
101 const std::string& extension_id, | 106 const std::string& extension_id, |
102 const std::string& task_type, | 107 const std::string& task_type, |
103 const std::string& action_id); | 108 const std::string& action_id); |
104 | 109 |
105 // Same as ExecuteAndNotify, but no notification is performed. | 110 // Same as ExecuteAndNotify, but no notification is performed. |
106 virtual bool Execute(const std::vector<GURL>& file_urls); | 111 virtual bool Execute(const std::vector<fileapi::FileSystemURL>& file_urls); |
107 | 112 |
108 // Initiates execution of file handler task for each element of |file_urls|. | 113 // Initiates execution of file handler task for each element of |file_urls|. |
109 // Return |false| if the execution cannot be initiated. Otherwise returns | 114 // Return |false| if the execution cannot be initiated. Otherwise returns |
110 // |true| and then eventually calls |done| when all the files have | 115 // |true| and then eventually calls |done| when all the files have |
111 // been handled. If there is an error during processing the list of files, the | 116 // been handled. If there is an error during processing the list of files, the |
112 // caller will be informed of the failure via |done|, and the rest of | 117 // caller will be informed of the failure via |done|, and the rest of |
113 // the files will not be processed. | 118 // the files will not be processed. |
114 virtual bool ExecuteAndNotify(const std::vector<GURL>& file_urls, | 119 virtual bool ExecuteAndNotify( |
115 const FileTaskFinishedCallback& done) = 0; | 120 const std::vector<fileapi::FileSystemURL>& file_urls, |
| 121 const FileTaskFinishedCallback& done) = 0; |
116 | 122 |
117 protected: | 123 protected: |
118 explicit FileTaskExecutor(Profile* profile, | 124 explicit FileTaskExecutor(Profile* profile, |
119 const GURL& source_url, | 125 const GURL& source_url, |
120 const std::string& file_browser_id, | 126 const std::string& file_browser_id, |
121 const std::string& extension_id); | 127 const std::string& extension_id); |
122 virtual ~FileTaskExecutor(); | 128 virtual ~FileTaskExecutor(); |
123 | 129 |
124 // Checks if the file browser extension had file access permissions for the | 130 // Checks if the file browser extension had file access permissions for the |
125 // list of files. | 131 // list of files. |
126 bool FileBrowserHasAccessPermissionForFiles(const std::vector<GURL>& files); | 132 bool FileBrowserHasAccessPermissionForFiles( |
| 133 const std::vector<fileapi::FileSystemURL>& files); |
127 | 134 |
128 // Returns the profile that this task was created with. | 135 // Returns the profile that this task was created with. |
129 Profile* profile() { return profile_; } | 136 Profile* profile() { return profile_; } |
130 | 137 |
131 // Returns a browser to use for the current browser. | 138 // Returns a browser to use for the current browser. |
132 Browser* GetBrowser() const; | 139 Browser* GetBrowser() const; |
133 | 140 |
134 // Returns the extension for this profile. | 141 // Returns the extension for this profile. |
135 const extensions::Extension* GetExtension(); | 142 const extensions::Extension* GetExtension(); |
136 | 143 |
137 // Returns the extension ID set for this FileTaskExecutor. | 144 // Returns the extension ID set for this FileTaskExecutor. |
138 const std::string& extension_id() { return extension_id_; } | 145 const std::string& extension_id() { return extension_id_; } |
139 | 146 |
140 private: | 147 private: |
141 friend class base::RefCountedThreadSafe<FileTaskExecutor>; | 148 friend class base::RefCountedThreadSafe<FileTaskExecutor>; |
142 | 149 |
143 Profile* profile_; | 150 Profile* profile_; |
144 const GURL source_url_; | 151 const GURL source_url_; |
145 const std::string file_browser_id_; | 152 const std::string file_browser_id_; |
146 const std::string extension_id_; | 153 const std::string extension_id_; |
147 }; | 154 }; |
148 | 155 |
149 } // namespace file_handler_util | 156 } // namespace file_handler_util |
150 | 157 |
151 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_HANDLER_UTIL_H_ | 158 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_HANDLER_UTIL_H_ |
OLD | NEW |