file_manager: Move FindPreferredIcon() to drive_app_registry.h
[chromium-blink-merge.git] / chrome / browser / chromeos / extensions / file_manager / private_api_tasks.h
blob80fd87b308ef5fc0a09f88831b348fc5c8ad0007
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 //
5 // This file provides task related API functions.
7 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_TASKS_H_
8 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_TASKS_H_
10 #include <map>
11 #include <set>
12 #include <string>
13 #include <vector>
15 #include "chrome/browser/chromeos/extensions/file_manager/private_api_base.h"
16 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h"
18 namespace drive {
19 class DriveAppRegistry;
22 namespace file_manager {
24 // Implements the chrome.fileBrowserPrivate.executeTask method.
25 class ExecuteTaskFunction : public LoggedAsyncExtensionFunction {
26 public:
27 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.executeTask",
28 FILEBROWSERPRIVATE_EXECUTETASK)
30 ExecuteTaskFunction();
32 protected:
33 virtual ~ExecuteTaskFunction();
35 // AsyncExtensionFunction overrides.
36 virtual bool RunImpl() OVERRIDE;
38 void OnTaskExecuted(bool success);
41 // Implements the chrome.fileBrowserPrivate.getFileTasks method.
42 class GetFileTasksFunction : public LoggedAsyncExtensionFunction {
43 public:
44 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getFileTasks",
45 FILEBROWSERPRIVATE_GETFILETASKS)
47 GetFileTasksFunction();
49 protected:
50 virtual ~GetFileTasksFunction();
52 // AsyncExtensionFunction overrides.
53 virtual bool RunImpl() OVERRIDE;
55 private:
56 typedef extensions::app_file_handler_util::PathAndMimeTypeSet
57 PathAndMimeTypeSet;
59 // Holds fields to build a task result.
60 struct TaskInfo;
62 // Map from a task id to TaskInfo.
63 typedef std::map<std::string, TaskInfo> TaskInfoMap;
65 // Looks up available apps for each file in |path_mime_set| in the
66 // |registry|, and returns the intersection of all available apps as a
67 // map from task id to TaskInfo.
68 static void GetAvailableDriveTasks(drive::DriveAppRegistry* registry,
69 const PathAndMimeTypeSet& path_mime_set,
70 TaskInfoMap* task_info_map);
72 // Looks in the preferences and finds any of the available apps that are
73 // also listed as default apps for any of the files in the info list.
74 void FindDefaultDriveTasks(const PathAndMimeTypeSet& path_mime_set,
75 const TaskInfoMap& task_info_map,
76 std::set<std::string>* default_tasks);
78 // Creates a list of each task in |task_info_map| and stores the result into
79 // |result_list|. If a default task is set in the result list,
80 // |default_already_set| is set to true.
81 static void CreateDriveTasks(const TaskInfoMap& task_info_map,
82 const std::set<std::string>& default_tasks,
83 ListValue* result_list,
84 bool* default_already_set);
86 // Finds the drive app tasks that can be used with the given files, and
87 // append them to the |result_list|. |*default_already_set| indicates if
88 // the |result_list| already contains the default task. If the value is
89 // false, the function will find the default task and set the value to true
90 // if found.
92 // "taskId" field in |result_list| will look like
93 // "<drive-app-id>|drive|open-with" (See also file_tasks.h).
94 // "driveApp" field in |result_list| will be set to "true".
95 void FindDriveAppTasks(const PathAndMimeTypeSet& path_mime_set,
96 ListValue* result_list,
97 bool* default_already_set);
99 // Find the file handler tasks (apps declaring "file_handlers" in
100 // manifest.json) that can be used with the given files, appending them to
101 // the |result_list|. See the comment at FindDriveAppTasks() about
102 // |default_already_set|
103 void FindFileHandlerTasks(const PathAndMimeTypeSet& path_mime_set,
104 ListValue* result_list,
105 bool* default_already_set);
107 // Find the file browser handler tasks (app/extensions declaring
108 // "file_browser_handlers" in manifest.json) that can be used with the
109 // given files, appending them to the |result_list|. See the comment at
110 // FindDriveAppTasks() about |default_already_set|
111 void FindFileBrowserHandlerTasks(
112 const std::vector<GURL>& file_urls,
113 const std::vector<base::FilePath>& file_paths,
114 ListValue* result_list,
115 bool* default_already_set);
118 // Implements the chrome.fileBrowserPrivate.setDefaultTask method.
119 class SetDefaultTaskFunction : public SyncExtensionFunction {
120 public:
121 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.setDefaultTask",
122 FILEBROWSERPRIVATE_SETDEFAULTTASK)
124 SetDefaultTaskFunction();
126 protected:
127 virtual ~SetDefaultTaskFunction();
129 // SyncExtensionFunction overrides.
130 virtual bool RunImpl() OVERRIDE;
133 } // namespace file_manager
135 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_TASKS_H_