1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
|
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_ASH_FILE_MANAGER_OFFICE_FILE_TASKS_H_
#define CHROME_BROWSER_ASH_FILE_MANAGER_OFFICE_FILE_TASKS_H_
#include <set>
#include <string>
#include <vector>
#include "base/files/file_path.h"
#include "base/time/time.h"
#include "chrome/browser/ui/webui/ash/cloud_upload/cloud_upload_util.h"
#include "chrome/browser/ui/webui/ash/office_fallback/office_fallback_dialog.h"
class Profile;
namespace ash::cloud_upload {
class CloudOpenMetrics;
}
namespace storage {
class FileSystemURL;
}
namespace user_prefs {
class PrefRegistrySyncable;
}
namespace file_manager::file_tasks {
struct TaskDescriptor;
inline constexpr char kActionIdQuickOffice[] = "/views/app.html";
inline constexpr char kActionIdWebDriveOfficeWord[] =
"open-web-drive-office-word";
inline constexpr char kActionIdWebDriveOfficeExcel[] =
"open-web-drive-office-excel";
inline constexpr char kActionIdWebDriveOfficePowerPoint[] =
"open-web-drive-office-powerpoint";
inline constexpr char kActionIdOpenInOffice[] = "open-in-office";
// UMA metric name that tracks the result of using a MS Office file outside
// of Drive.
inline constexpr char kUseOutsideDriveMetricName[] =
"FileBrowser.OfficeFiles.UseOutsideDrive";
// List of UMA enum values for file system operations that let a user use a
// MS Office file outside of Drive. The enum values must be kept in sync with
// OfficeFilesUseOutsideDriveHook in tools/metrics/histograms/enums.xml.
enum class OfficeFilesUseOutsideDriveHook {
FILE_PICKER_SELECTION = 0,
COPY = 1,
MOVE = 2,
ZIP = 3,
OPEN_FROM_FILES_APP = 4,
kMaxValue = OPEN_FROM_FILES_APP,
};
// UMA metric name that tracks the extension of Office files that are being
// opened with Drive web.
inline constexpr char kOfficeOpenExtensionDriveMetricName[] =
"FileBrowser.OfficeFiles.Open.FileType.GoogleDrive";
// UMA metric name that tracks the extension of Office files that are being
// opened with MS365.
inline constexpr char kOfficeOpenExtensionOneDriveMetricName[] =
"FileBrowser.OfficeFiles.Open.FileType.OneDrive";
// List of file extensions that are used when opening a file with the
// "open-in-office" task. The enum values must be kept in sync with
// OfficeOpenExtensions in tools/metrics/histograms/enums.xml.
enum class OfficeOpenExtensions {
kOther,
kDoc,
kDocm,
kDocx,
kDotm,
kDotx,
kOdp,
kOds,
kOdt,
kPot,
kPotm,
kPotx,
kPpam,
kPps,
kPpsm,
kPpsx,
kPpt,
kPptm,
kPptx,
kXls,
kXlsb,
kXlsm,
kXlsx,
kMaxValue = kXlsx,
};
// Registers profile prefs related to file_manager.
void RegisterOfficeProfilePrefs(user_prefs::PrefRegistrySyncable*);
void RecordOfficeOpenExtensionDriveMetric(
const storage::FileSystemURL& file_url);
void RecordOfficeOpenExtensionOneDriveMetric(
const storage::FileSystemURL& file_url);
// Open files with WebDrive.
bool ExecuteWebDriveOfficeTask(
Profile* profile,
const TaskDescriptor& task,
const std::vector<storage::FileSystemURL>& file_urls,
std::unique_ptr<ash::cloud_upload::CloudOpenMetrics> cloud_open_metrics);
// Open files with Office365.
bool ExecuteOpenInOfficeTask(
Profile* profile,
const TaskDescriptor& task,
const std::vector<storage::FileSystemURL>& file_urls,
std::unique_ptr<ash::cloud_upload::CloudOpenMetrics> cloud_open_metrics);
// Executes QuickOffice file handler for each element of |file_urls|.
void LaunchQuickOffice(Profile* profile,
const std::vector<storage::FileSystemURL>& file_urls);
void LogOneDriveMetricsAfterFallback(
ash::office_fallback::FallbackReason fallback_reason,
ash::cloud_upload::OfficeTaskResult task_result,
std::unique_ptr<ash::cloud_upload::CloudOpenMetrics> cloud_open_metrics);
void LogGoogleDriveMetricsAfterFallback(
ash::office_fallback::FallbackReason fallback_reason,
ash::cloud_upload::OfficeTaskResult task_result,
std::unique_ptr<ash::cloud_upload::CloudOpenMetrics> cloud_open_metrics);
// Executes appropriate task to open the selected `file_urls`.
// If user's `choice` is `kDialogChoiceQuickOffice`, launch QuickOffice.
// If user's `choice` is `kDialogChoiceTryAgain`, execute the `task`.
// If user's `choice` is `kDialogChoiceCancel`, do nothing.
void OnDialogChoiceReceived(
Profile* profile,
const TaskDescriptor& task,
const std::vector<storage::FileSystemURL>& file_urls,
ash::office_fallback::FallbackReason fallback_reason,
std::unique_ptr<ash::cloud_upload::CloudOpenMetrics> cloud_open_metrics,
std::optional<const std::string> choice);
// Shows a new dialog for users to choose what to do next. Returns True
// if a new dialog has been effectively created.
bool GetUserFallbackChoice(Profile* profile,
const TaskDescriptor& task,
const std::vector<storage::FileSystemURL>& file_urls,
ash::office_fallback::FallbackReason failure_reason,
ash::office_fallback::DialogChoiceCallback callback);
bool IsWebDriveOfficeTask(const TaskDescriptor& task);
bool IsOpenInOfficeTask(const TaskDescriptor& task);
bool IsQuickOfficeInstalled(Profile* profile);
// Returns whether |path| is a MS Office file according to its extension.
bool IsOfficeFile(const base::FilePath& path);
// Returns whether |mime_type| is a MS Office file mimetype.
bool IsOfficeFileMimeType(const std::string& mime_type);
// Returns the group of extensions we consider to be 'Word', 'Excel' or
// 'PowerPoint' files for the purpose of setting preferences. The extensions
// contain the '.' character at the start.
std::set<std::string> WordGroupExtensions();
std::set<std::string> ExcelGroupExtensions();
std::set<std::string> PowerPointGroupExtensions();
// The same as above but MIME types.
std::set<std::string> WordGroupMimeTypes();
std::set<std::string> ExcelGroupMimeTypes();
std::set<std::string> PowerPointGroupMimeTypes();
// Updates the default task for each of the office file types.
void SetWordFileHandler(Profile* profile,
const TaskDescriptor& task,
bool replace_existing = true);
void SetExcelFileHandler(Profile* profile,
const TaskDescriptor& task,
bool replace_existing = true);
void SetPowerPointFileHandler(Profile* profile,
const TaskDescriptor& task,
bool replace_existing = true);
// Whether we have an explicit user preference stored for the file handler for
// this extension. |extension| should contain the leading '.'.
bool HasExplicitDefaultFileHandler(Profile* profile,
const std::string& extension);
// Updates the default task for each of the office file types to a Files
// SWA with |action_id|. |action_id| must be a valid action registered with the
// Files app SWA.
void SetWordFileHandlerToFilesSWA(Profile* profile,
const std::string& action_id,
bool replace_existing = true);
void SetExcelFileHandlerToFilesSWA(Profile* profile,
const std::string& action_id,
bool replace_existing = true);
void SetPowerPointFileHandlerToFilesSWA(Profile* profile,
const std::string& action_id,
bool replace_existing = true);
// Removes the specified default task for |action_id| for each of the office
// file types.
void RemoveFilesSWAWordFileHandler(Profile* profile,
const std::string& action_id);
void RemoveFilesSWAExcelFileHandler(Profile* profile,
const std::string& action_id);
void RemoveFilesSWAPowerPointFileHandler(Profile* profile,
const std::string& action_id);
// Sets the user preference storing whether we should always move office files
// to Google Drive without first asking the user.
void SetAlwaysMoveOfficeFilesToDrive(Profile* profile, bool complete = true);
// Whether we should always move office files to Google Drive without first
// asking the user.
bool GetAlwaysMoveOfficeFilesToDrive(Profile* profile);
// Sets the user preference storing whether we should always move office files
// to OneDrive without first asking the user.
void SetAlwaysMoveOfficeFilesToOneDrive(Profile* profile, bool complete = true);
// Whether we should always move office files to OneDrive without first asking
// the user.
bool GetAlwaysMoveOfficeFilesToOneDrive(Profile* profile);
// Sets the user preference storing whether the move confirmation dialog has
// been shown before for moving files to Drive.
void SetOfficeMoveConfirmationShownForDrive(Profile* profile, bool complete);
// Whether the move confirmation dialog has been shown before for moving files
// to Drive.
bool GetOfficeMoveConfirmationShownForDrive(Profile* profile);
// Sets the user preference storing whether the move confirmation dialog has
// been shown before for moving files to OneDrive.
void SetOfficeMoveConfirmationShownForOneDrive(Profile* profile, bool complete);
// Whether the move confirmation dialog has been shown before for moving files
// to OneDrive.
bool GetOfficeMoveConfirmationShownForOneDrive(Profile* profile);
// Sets the user preference storing whether the move confirmation dialog has
// been shown before for uploading files from a local source to Drive.
void SetOfficeMoveConfirmationShownForLocalToDrive(Profile* profile,
bool shown);
// Whether the move confirmation dialog has been shown before for uploading
// files from a local source to Drive.
bool GetOfficeMoveConfirmationShownForLocalToDrive(Profile* profile);
// Sets the user preference storing whether the move confirmation dialog has
// been shown before for uploading files from a local source to OneDrive.
void SetOfficeMoveConfirmationShownForLocalToOneDrive(Profile* profile,
bool shown);
// Whether the move confirmation dialog has been shown before for uploading
// files from a local source to OneDrive.
bool GetOfficeMoveConfirmationShownForLocalToOneDrive(Profile* profile);
// Sets the user preference storing whether the move confirmation dialog has
// been shown before for uploading files from a cloud source to Drive.
void SetOfficeMoveConfirmationShownForCloudToDrive(Profile* profile,
bool shown);
// Whether the move confirmation dialog has been shown before for uploading
// files from a cloud source to Drive.
bool GetOfficeMoveConfirmationShownForCloudToDrive(Profile* profile);
// Sets the user preference storing whether the move confirmation dialog has
// been shown before for uploading files from a cloud source to OneDrive.
void SetOfficeMoveConfirmationShownForCloudToOneDrive(Profile* profile,
bool shown);
// Whether the move confirmation dialog has been shown before for uploading
// files from a cloud source to OneDrive.
bool GetOfficeMoveConfirmationShownForCloudToOneDrive(Profile* profile);
// Sets the preference `office.file_moved_one_drive`.
void SetOfficeFileMovedToOneDrive(Profile* profile, base::Time moved);
// Sets the preference `office.file_moved_google_drive`.
void SetOfficeFileMovedToGoogleDrive(Profile* profile, base::Time moved);
} // namespace file_manager::file_tasks
#endif // CHROME_BROWSER_ASH_FILE_MANAGER_OFFICE_FILE_TASKS_H_
|