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
|
// 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.
#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/390223051): Remove C-library calls to fix the errors.
#pragma allow_unsafe_libc_calls
#endif
#include "components/enterprise/idle/action_type.h"
#include <algorithm>
#include <cstring>
#include <string>
#include <utility>
#include "base/containers/span.h"
#include "base/functional/bind.h"
#include "base/json/values_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "base/values.h"
#include "components/enterprise/idle/idle_pref_names.h"
namespace enterprise_idle {
namespace {
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
const char kCloseBrowsersActionName[] = "close_browsers";
const char kShowProfilePickerActionName[] = "show_profile_picker";
const char kClearDownloadHistoryActionName[] = "clear_download_history";
const char kClearHostedAppDataActionName[] = "clear_hosted_app_data";
#endif // !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
const char kClearBrowsingHistoryActionName[] = "clear_browsing_history";
const char kClearCookiesAndOtherSiteDataActionName[] =
"clear_cookies_and_other_site_data";
const char kClearCachedImagesAndFilesActionName[] =
"clear_cached_images_and_files";
const char kClearPasswordSigninActionName[] = "clear_password_signin";
const char kClearAutofillActionName[] = "clear_autofill";
#if BUILDFLAG(IS_IOS)
const char kSignOut[] = "sign_out";
const char kCloseTabs[] = "close_tabs";
#else
const char kClearSiteSettingsActionName[] = "clear_site_settings";
const char kReloadPagesActionName[] = "reload_pages";
#endif // BUILDFLAG(IS_IOS)
} // namespace
std::optional<ActionType> NameToActionType(const std::string& name) {
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
if (name == kCloseBrowsersActionName) {
return ActionType::kCloseBrowsers;
}
if (name == kShowProfilePickerActionName) {
return ActionType::kShowProfilePicker;
}
if (name == kClearDownloadHistoryActionName) {
return ActionType::kClearDownloadHistory;
}
if (name == kClearHostedAppDataActionName) {
return ActionType::kClearHostedAppData;
}
#endif // !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
if (name == kClearBrowsingHistoryActionName) {
return ActionType::kClearBrowsingHistory;
}
if (name == kClearCookiesAndOtherSiteDataActionName) {
return ActionType::kClearCookiesAndOtherSiteData;
}
if (name == kClearCachedImagesAndFilesActionName) {
return ActionType::kClearCachedImagesAndFiles;
}
if (name == kClearPasswordSigninActionName) {
return ActionType::kClearPasswordSignin;
}
if (name == kClearAutofillActionName) {
return ActionType::kClearAutofill;
}
#if BUILDFLAG(IS_IOS)
if (name == kSignOut) {
return ActionType::kSignOut;
}
if (name == kCloseTabs) {
return ActionType::kCloseTabs;
}
#else
if (name == kClearSiteSettingsActionName) {
return ActionType::kClearSiteSettings;
}
if (name == kReloadPagesActionName) {
return ActionType::kReloadPages;
}
#endif // BUILDFLAG(IS_IOS)
return std::nullopt;
}
std::string GetActionBrowsingDataTypeName(const std::string& action) {
// Get the data type to be cleared if the action is to clear browsig data.
auto remainder = base::RemovePrefix(action, "clear_");
return remainder ? std::string(*remainder) : std::string();
}
std::vector<ActionType> GetActionTypesFromPrefs(PrefService* prefs) {
std::vector<ActionType> actions;
std::ranges::transform(prefs->GetList(prefs::kIdleTimeoutActions),
std::back_inserter(actions),
[](const base::Value& action) {
return static_cast<ActionType>(action.GetInt());
});
return actions;
}
} // namespace enterprise_idle
|