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