OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 task related API functions. | 5 // This file provides task related API functions. |
6 | 6 |
7 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_TASKS_H_ | 7 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_TASKS_H_ |
8 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_TASKS_H_ | 8 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_TASKS_H_ |
9 | 9 |
10 #include <map> | 10 #include <map> |
11 #include <set> | 11 #include <set> |
12 #include <string> | 12 #include <string> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "chrome/browser/chromeos/extensions/file_manager/private_api_base.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" | |
17 | 16 |
18 class PrefService; | 17 class PrefService; |
19 | 18 |
20 namespace drive { | 19 namespace drive { |
21 class DriveAppRegistry; | 20 class DriveAppRegistry; |
22 } | 21 } |
23 | 22 |
24 namespace file_manager { | 23 namespace file_manager { |
25 | 24 |
26 // Implements the chrome.fileBrowserPrivate.executeTask method. | 25 // Implements the chrome.fileBrowserPrivate.executeTask method. |
(...skipping 19 matching lines...) Expand all Loading... |
46 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getFileTasks", | 45 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getFileTasks", |
47 FILEBROWSERPRIVATE_GETFILETASKS) | 46 FILEBROWSERPRIVATE_GETFILETASKS) |
48 | 47 |
49 GetFileTasksFunction(); | 48 GetFileTasksFunction(); |
50 | 49 |
51 protected: | 50 protected: |
52 virtual ~GetFileTasksFunction(); | 51 virtual ~GetFileTasksFunction(); |
53 | 52 |
54 // AsyncExtensionFunction overrides. | 53 // AsyncExtensionFunction overrides. |
55 virtual bool RunImpl() OVERRIDE; | 54 virtual bool RunImpl() OVERRIDE; |
56 | |
57 private: | |
58 typedef extensions::app_file_handler_util::PathAndMimeTypeSet | |
59 PathAndMimeTypeSet; | |
60 | |
61 // Holds fields to build a task result. | |
62 struct TaskInfo; | |
63 | |
64 // Map from a task id to TaskInfo. | |
65 typedef std::map<std::string, TaskInfo> TaskInfoMap; | |
66 | |
67 // Looks up available apps for each file in |path_mime_set| in the | |
68 // |registry|, and returns the intersection of all available apps as a | |
69 // map from task id to TaskInfo. | |
70 static void GetAvailableDriveTasks(const drive::DriveAppRegistry& registry, | |
71 const PathAndMimeTypeSet& path_mime_set, | |
72 TaskInfoMap* task_info_map); | |
73 | |
74 // Looks in the preferences and finds any of the available apps that are | |
75 // also listed as default apps for any of the files in the info list. | |
76 static void FindDefaultDriveTasks(const PrefService& pref_service, | |
77 const PathAndMimeTypeSet& path_mime_set, | |
78 const TaskInfoMap& task_info_map, | |
79 std::set<std::string>* default_tasks); | |
80 | |
81 // Creates a list of each task in |task_info_map| and stores the result into | |
82 // |result_list|. If a default task is set in the result list, | |
83 // |default_already_set| is set to true. | |
84 static void CreateDriveTasks(const TaskInfoMap& task_info_map, | |
85 const std::set<std::string>& default_tasks, | |
86 ListValue* result_list, | |
87 bool* default_already_set); | |
88 | |
89 // Finds the drive app tasks that can be used with the given files, and | |
90 // append them to the |result_list|. |*default_already_set| indicates if | |
91 // the |result_list| already contains the default task. If the value is | |
92 // false, the function will find the default task and set the value to true | |
93 // if found. | |
94 // | |
95 // "taskId" field in |result_list| will look like | |
96 // "<drive-app-id>|drive|open-with" (See also file_tasks.h). | |
97 // "driveApp" field in |result_list| will be set to "true". | |
98 static void FindDriveAppTasks(Profile* profile, | |
99 const PathAndMimeTypeSet& path_mime_set, | |
100 ListValue* result_list, | |
101 bool* default_already_set); | |
102 | |
103 // Finds the file handler tasks (apps declaring "file_handlers" in | |
104 // manifest.json) that can be used with the given files, appending them to | |
105 // the |result_list|. See the comment at FindDriveAppTasks() about | |
106 // |default_already_set| | |
107 static void FindFileHandlerTasks(Profile* profile, | |
108 const PathAndMimeTypeSet& path_mime_set, | |
109 ListValue* result_list, | |
110 bool* default_already_set); | |
111 | |
112 // Finds the file browser handler tasks (app/extensions declaring | |
113 // "file_browser_handlers" in manifest.json) that can be used with the | |
114 // given files, appending them to the |result_list|. See the comment at | |
115 // FindDriveAppTasks() about |default_already_set| | |
116 static void FindFileBrowserHandlerTasks( | |
117 Profile* profile, | |
118 const std::vector<GURL>& file_urls, | |
119 const std::vector<base::FilePath>& file_paths, | |
120 ListValue* result_list, | |
121 bool* default_already_set); | |
122 | |
123 // Finds all types (drive, file handlers, file browser handlers) of | |
124 // tasks. See the comment at FindDriveAppTasks() about |result_list|. | |
125 static void FindAllTypesOfTasks( | |
126 Profile* profile, | |
127 const PathAndMimeTypeSet& path_mime_set, | |
128 const std::vector<GURL>& file_urls, | |
129 const std::vector<base::FilePath>& file_paths, | |
130 ListValue* result_list); | |
131 }; | 55 }; |
132 | 56 |
133 // Implements the chrome.fileBrowserPrivate.setDefaultTask method. | 57 // Implements the chrome.fileBrowserPrivate.setDefaultTask method. |
134 class SetDefaultTaskFunction : public SyncExtensionFunction { | 58 class SetDefaultTaskFunction : public SyncExtensionFunction { |
135 public: | 59 public: |
136 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.setDefaultTask", | 60 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.setDefaultTask", |
137 FILEBROWSERPRIVATE_SETDEFAULTTASK) | 61 FILEBROWSERPRIVATE_SETDEFAULTTASK) |
138 | 62 |
139 SetDefaultTaskFunction(); | 63 SetDefaultTaskFunction(); |
140 | 64 |
141 protected: | 65 protected: |
142 virtual ~SetDefaultTaskFunction(); | 66 virtual ~SetDefaultTaskFunction(); |
143 | 67 |
144 // SyncExtensionFunction overrides. | 68 // SyncExtensionFunction overrides. |
145 virtual bool RunImpl() OVERRIDE; | 69 virtual bool RunImpl() OVERRIDE; |
146 }; | 70 }; |
147 | 71 |
148 } // namespace file_manager | 72 } // namespace file_manager |
149 | 73 |
150 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_TASKS_H_ | 74 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_TASKS_H_ |
OLD | NEW |