Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(196)

Side by Side Diff: chrome/browser/chromeos/extensions/file_manager/file_tasks.h

Issue 23532010: file_manager: Introduce FullTaskDescriptor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/chromeos/extensions/file_manager/file_tasks.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // This file provides utility functions for "file tasks". 5 // This file provides utility functions for "file tasks".
6 // 6 //
7 // WHAT ARE FILE TASKS? 7 // WHAT ARE FILE TASKS?
8 // 8 //
9 // File tasks are representatiosn of actions that can be performed over the 9 // File tasks are representatiosn of actions that can be performed over the
10 // currently selected files from Files.app. A task can be either of: 10 // currently selected files from Files.app. A task can be either of:
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_FILE_TASKS_H_ 110 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_FILE_TASKS_H_
111 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_FILE_TASKS_H_ 111 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_FILE_TASKS_H_
112 112
113 #include <set> 113 #include <set>
114 #include <string> 114 #include <string>
115 #include <vector> 115 #include <vector>
116 116
117 #include "base/basictypes.h" 117 #include "base/basictypes.h"
118 #include "base/callback_forward.h" 118 #include "base/callback_forward.h"
119 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" 119 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h"
120 #include "url/gurl.h"
120 121
121 class GURL;
122 class PrefService; 122 class PrefService;
123 class Profile; 123 class Profile;
124 124
125 namespace drive { 125 namespace drive {
126 class DriveAppRegistry; 126 class DriveAppRegistry;
127 } 127 }
128 128
129 namespace fileapi { 129 namespace fileapi {
130 class FileSystemURL; 130 class FileSystemURL;
131 } 131 }
(...skipping 20 matching lines...) Expand all
152 action_id(in_action_id) { 152 action_id(in_action_id) {
153 } 153 }
154 TaskDescriptor() { 154 TaskDescriptor() {
155 } 155 }
156 156
157 std::string app_id; 157 std::string app_id;
158 TaskType task_type; 158 TaskType task_type;
159 std::string action_id; 159 std::string action_id;
160 }; 160 };
161 161
162 // Describes a task with extra information such as icon URL.
163 class FullTaskDescriptor {
164 public:
165 FullTaskDescriptor(const TaskDescriptor& task_descriptor,
166 const std::string& task_title,
167 const GURL& icon_url,
168 bool is_default);
169 // The icon URL for the task (ex. app icon)
170 const GURL& icon_url() const { return icon_url_; }
171
172 // True if this task is set as default.
173 bool is_default() const { return is_default_; }
174
175 // The title of the task.
176 const std::string& task_title() { return task_title_; }
177
178 // Returns a DictionaryValue representation, which looks like:
179 //
180 // {
181 // "driveApp": true,
182 // "iconUrl": "<app_icon_url>",
183 // "isDefault": false,
184 // "taskId": "<drive_app_id>|drive|open-with",
185 // "title": "Drive App Name (ex. Pixlr Editor)"
186 // },
187 //
188 // "iconUrl" is omitted if icon_url_ is empty.
189 //
190 // This representation will be used to send task info to the JavaScript.
191 scoped_ptr<base::DictionaryValue> AsDictionaryValue() const;
192
193 private:
194 TaskDescriptor task_descriptor_;
195 std::string task_title_;
196 GURL icon_url_;
197 bool is_default_;
198 };
199
162 // Update the default file handler for the given sets of suffixes and MIME 200 // Update the default file handler for the given sets of suffixes and MIME
163 // types. 201 // types.
164 void UpdateDefaultTask(PrefService* pref_service, 202 void UpdateDefaultTask(PrefService* pref_service,
165 const std::string& task_id, 203 const std::string& task_id,
166 const std::set<std::string>& suffixes, 204 const std::set<std::string>& suffixes,
167 const std::set<std::string>& mime_types); 205 const std::set<std::string>& mime_types);
168 206
169 // Returns the task ID of the default task for the given |mime_type|/|suffix| 207 // Returns the task ID of the default task for the given |mime_type|/|suffix|
170 // combination. If it finds a MIME type match, then it prefers that over a 208 // combination. If it finds a MIME type match, then it prefers that over a
171 // suffix match. If it a default can't be found, then it returns the empty 209 // suffix match. If it a default can't be found, then it returns the empty
172 // string. 210 // string.
173 std::string GetDefaultTaskIdFromPrefs(const PrefService& pref_service, 211 std::string GetDefaultTaskIdFromPrefs(const PrefService& pref_service,
174 const std::string& mime_type, 212 const std::string& mime_type,
175 const std::string& suffix); 213 const std::string& suffix);
176 214
177 // Generates task id for the task specified by |app_id|, |task_type| and 215 // Generates task id for the task specified by |app_id|, |task_type| and
178 // |action_id|. 216 // |action_id|.
179 // 217 //
180 // |app_id| is either of Chrome Extension/App ID or Drive App ID. 218 // |app_id| is either of Chrome Extension/App ID or Drive App ID.
181 // |action_id| is a free-form string ID for the action. 219 // |action_id| is a free-form string ID for the action.
182 std::string MakeTaskID(const std::string& extension_id, 220 std::string MakeTaskID(const std::string& app_id,
183 TaskType task_type, 221 TaskType task_type,
184 const std::string& action_id); 222 const std::string& action_id);
185 223
186 // Returns a task id for the Drive app with |app_id|. 224 // Returns a task id for the Drive app with |app_id|.
187 // TODO(gspencer): For now, the action id is always "open-with", but we 225 // TODO(gspencer): For now, the action id is always "open-with", but we
188 // could add any actions that the drive app supports. 226 // could add any actions that the drive app supports.
189 std::string MakeDriveAppTaskId(const std::string& app_id); 227 std::string MakeDriveAppTaskId(const std::string& app_id);
190 228
229 // Converts |task_descriptor| to a task ID.
230 std::string TaskDescriptorToId(const TaskDescriptor& task_descriptor);
231
191 // Parses the task ID and extracts app ID, task type, and action ID into 232 // Parses the task ID and extracts app ID, task type, and action ID into
192 // |task|. On failure, returns false, and the contents of |task| are 233 // |task|. On failure, returns false, and the contents of |task| are
193 // undefined. 234 // undefined.
194 // 235 //
195 // See also the comment at the beginning of the file for details for how 236 // See also the comment at the beginning of the file for details for how
196 // "task_id" looks like. 237 // "task_id" looks like.
197 bool ParseTaskID(const std::string& task_id, TaskDescriptor* task); 238 bool ParseTaskID(const std::string& task_id, TaskDescriptor* task);
198 239
199 // The callback is used for ExecuteFileTask(). Will be called with true if 240 // The callback is used for ExecuteFileTask(). Will be called with true if
200 // the file task execution is successful, or false if unsuccessful. 241 // the file task execution is successful, or false if unsuccessful.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 void FindDefaultDriveTasks(const PrefService& pref_service, 286 void FindDefaultDriveTasks(const PrefService& pref_service,
246 const PathAndMimeTypeSet& path_mime_set, 287 const PathAndMimeTypeSet& path_mime_set,
247 const TaskInfoMap& task_info_map, 288 const TaskInfoMap& task_info_map,
248 std::set<std::string>* default_tasks); 289 std::set<std::string>* default_tasks);
249 290
250 // Creates a list of each task in |task_info_map| and stores the result into 291 // Creates a list of each task in |task_info_map| and stores the result into
251 // |result_list|. If a default task is set in the result list, 292 // |result_list|. If a default task is set in the result list,
252 // |default_already_set| is set to true. 293 // |default_already_set| is set to true.
253 void CreateDriveTasks(const TaskInfoMap& task_info_map, 294 void CreateDriveTasks(const TaskInfoMap& task_info_map,
254 const std::set<std::string>& default_tasks, 295 const std::set<std::string>& default_tasks,
255 ListValue* result_list, 296 std::vector<FullTaskDescriptor>* result_list,
256 bool* default_already_set); 297 bool* default_already_set);
257 298
258 // Finds the drive app tasks that can be used with the given files, and 299 // Finds the drive app tasks that can be used with the given files, and
259 // append them to the |result_list|. |*default_already_set| indicates if 300 // append them to the |result_list|. |*default_already_set| indicates if
260 // the |result_list| already contains the default task. If the value is 301 // the |result_list| already contains the default task. If the value is
261 // false, the function will find the default task and set the value to true 302 // false, the function will find the default task and set the value to true
262 // if found. 303 // if found.
263 // 304 //
264 // "taskId" field in |result_list| will look like 305 // "taskId" field in |result_list| will look like
265 // "<drive-app-id>|drive|open-with" (See also file_tasks.h). 306 // "<drive-app-id>|drive|open-with" (See also file_tasks.h).
266 // "driveApp" field in |result_list| will be set to "true". 307 // "driveApp" field in |result_list| will be set to "true".
267 void FindDriveAppTasks(Profile* profile, 308 void FindDriveAppTasks(Profile* profile,
268 const PathAndMimeTypeSet& path_mime_set, 309 const PathAndMimeTypeSet& path_mime_set,
269 ListValue* result_list, 310 std::vector<FullTaskDescriptor>* result_list,
270 bool* default_already_set); 311 bool* default_already_set);
271 312
272 // Finds the file handler tasks (apps declaring "file_handlers" in 313 // Finds the file handler tasks (apps declaring "file_handlers" in
273 // manifest.json) that can be used with the given files, appending them to 314 // manifest.json) that can be used with the given files, appending them to
274 // the |result_list|. See the comment at FindDriveAppTasks() about 315 // the |result_list|. See the comment at FindDriveAppTasks() about
275 // |default_already_set| 316 // |default_already_set|
276 void FindFileHandlerTasks(Profile* profile, 317 void FindFileHandlerTasks(Profile* profile,
277 const PathAndMimeTypeSet& path_mime_set, 318 const PathAndMimeTypeSet& path_mime_set,
278 ListValue* result_list, 319 std::vector<FullTaskDescriptor>* result_list,
279 bool* default_already_set); 320 bool* default_already_set);
280 321
281 // Finds the file browser handler tasks (app/extensions declaring 322 // Finds the file browser handler tasks (app/extensions declaring
282 // "file_browser_handlers" in manifest.json) that can be used with the 323 // "file_browser_handlers" in manifest.json) that can be used with the
283 // given files, appending them to the |result_list|. See the comment at 324 // given files, appending them to the |result_list|. See the comment at
284 // FindDriveAppTasks() about |default_already_set| 325 // FindDriveAppTasks() about |default_already_set|
285 void FindFileBrowserHandlerTasks( 326 void FindFileBrowserHandlerTasks(
286 Profile* profile, 327 Profile* profile,
287 const std::vector<GURL>& file_urls, 328 const std::vector<GURL>& file_urls,
288 const std::vector<base::FilePath>& file_paths, 329 const std::vector<base::FilePath>& file_paths,
289 ListValue* result_list, 330 std::vector<FullTaskDescriptor>* result_list,
290 bool* default_already_set); 331 bool* default_already_set);
291 332
292 // Finds all types (drive, file handlers, file browser handlers) of 333 // Finds all types (drive, file handlers, file browser handlers) of
293 // tasks. See the comment at FindDriveAppTasks() about |result_list|. 334 // tasks. See the comment at FindDriveAppTasks() about |result_list|.
294 void FindAllTypesOfTasks( 335 void FindAllTypesOfTasks(
295 Profile* profile, 336 Profile* profile,
296 const PathAndMimeTypeSet& path_mime_set, 337 const PathAndMimeTypeSet& path_mime_set,
297 const std::vector<GURL>& file_urls, 338 const std::vector<GURL>& file_urls,
298 const std::vector<base::FilePath>& file_paths, 339 const std::vector<base::FilePath>& file_paths,
299 ListValue* result_list); 340 std::vector<FullTaskDescriptor>* result_list);
300 341
301 } // namespace file_tasks 342 } // namespace file_tasks
302 } // namespace file_manager 343 } // namespace file_manager
303 344
304 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_FILE_TASKS_H_ 345 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_FILE_TASKS_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/extensions/file_manager/file_tasks.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698