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.
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_
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"
19 class DriveAppRegistry
;
22 namespace file_manager
{
24 // Implements the chrome.fileBrowserPrivate.executeTask method.
25 class ExecuteTaskFunction
: public LoggedAsyncExtensionFunction
{
27 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.executeTask",
28 FILEBROWSERPRIVATE_EXECUTETASK
)
30 ExecuteTaskFunction();
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
{
44 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getFileTasks",
45 FILEBROWSERPRIVATE_GETFILETASKS
)
47 GetFileTasksFunction();
50 virtual ~GetFileTasksFunction();
52 // AsyncExtensionFunction overrides.
53 virtual bool RunImpl() OVERRIDE
;
56 typedef extensions::app_file_handler_util::PathAndMimeTypeSet
59 // Holds fields to build a task result.
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
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
{
121 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.setDefaultTask",
122 FILEBROWSERPRIVATE_SETDEFAULTTASK
)
124 SetDefaultTaskFunction();
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_