Commit 77f33a7d authored by Glen Robertson's avatar Glen Robertson Committed by Commit Bot

COIL: Remove usages of 'whiltelist' in note_taking_helper.

No functional changes.

Change-Id: I0868bbd38bac1e1fd1fe366a844ae01390af40f0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2454553
Commit-Queue: Glen Robertson <glenrob@chromium.org>
Auto-Submit: Glen Robertson <glenrob@chromium.org>
Reviewed-by: default avatarAchuith Bhandarkar <achuith@chromium.org>
Cr-Commit-Position: refs/heads/master@{#815526}
parent 3a3ed1e4
......@@ -52,7 +52,7 @@ namespace {
// Pointer to singleton instance.
NoteTakingHelper* g_helper = nullptr;
// Whitelisted Chrome note-taking apps.
// Allowed Chrome note-taking apps.
const char* const kExtensionIds[] = {
// TODO(jdufault): Remove dev version? See crbug.com/640828.
NoteTakingHelper::kDevKeepExtensionId,
......@@ -90,10 +90,10 @@ bool IsLockScreenEnabled(const extensions::Extension* app) {
app, app_runtime::ACTION_TYPE_NEW_NOTE);
}
// Gets the set of apps (more specifically, their app IDs) that are allowed to
// be launched on the lock screen, if the feature is whitelisted using
// Gets the set of app IDs that are allowed to be launched on the lock screen,
// if the feature is restricted using the
// |prefs::kNoteTakingAppsLockScreenAllowlist| preference. If the pref is not
// set, this method will return null (in which case the white-list should not be
// set, this method will return null (in which case the set should not be
// checked).
// Note that |prefs::kNoteTakingrAppsAllowedOnLockScreen| is currently only
// expected to be set by policy (if it's set at all).
......@@ -217,7 +217,7 @@ std::unique_ptr<NoteTakingAppInfo> NoteTakingHelper::GetPreferredChromeAppInfo(
if (!preferred_app)
return nullptr;
if (!IsWhitelistedChromeApp(preferred_app) &&
if (!IsAllowedChromeApp(preferred_app) &&
!extensions::ActionHandlersInfo::HasActionHandler(
preferred_app, app_runtime::ACTION_TYPE_NEW_NOTE)) {
return nullptr;
......@@ -372,12 +372,11 @@ NoteTakingHelper::NoteTakingHelper()
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kNoteTakingAppIds);
if (!switch_value.empty()) {
whitelisted_chrome_app_ids_ = base::SplitString(
allowed_chrome_app_ids_ = base::SplitString(
switch_value, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
}
whitelisted_chrome_app_ids_.insert(whitelisted_chrome_app_ids_.end(),
kExtensionIds,
kExtensionIds + base::size(kExtensionIds));
allowed_chrome_app_ids_.insert(allowed_chrome_app_ids_.end(), kExtensionIds,
kExtensionIds + base::size(kExtensionIds));
// Track profiles so we can observe their extension registries.
g_browser_process->profile_manager()->AddObserver(this);
......@@ -431,10 +430,10 @@ NoteTakingHelper::~NoteTakingHelper() {
}
}
bool NoteTakingHelper::IsWhitelistedChromeApp(
bool NoteTakingHelper::IsAllowedChromeApp(
const extensions::Extension* extension) const {
DCHECK(extension);
return base::Contains(whitelisted_chrome_app_ids_, extension->id());
return base::Contains(allowed_chrome_app_ids_, extension->id());
}
std::vector<const extensions::Extension*> NoteTakingHelper::GetChromeApps(
......@@ -446,7 +445,7 @@ std::vector<const extensions::Extension*> NoteTakingHelper::GetChromeApps(
extension_registry->enabled_extensions();
std::vector<const extensions::Extension*> extensions;
for (const auto& id : whitelisted_chrome_app_ids_) {
for (const auto& id : allowed_chrome_app_ids_) {
if (enabled_extensions.Contains(id)) {
extensions.push_back(extension_registry->GetExtensionById(
id, extensions::ExtensionRegistry::ENABLED));
......@@ -599,7 +598,7 @@ NoteTakingHelper::LaunchResult NoteTakingHelper::LaunchAppInternal(
void NoteTakingHelper::OnExtensionLoaded(
content::BrowserContext* browser_context,
const extensions::Extension* extension) {
if (IsWhitelistedChromeApp(extension) ||
if (IsAllowedChromeApp(extension) ||
extensions::ActionHandlersInfo::HasActionHandler(
extension, app_runtime::ACTION_TYPE_NEW_NOTE)) {
for (Observer& observer : observers_)
......@@ -611,7 +610,7 @@ void NoteTakingHelper::OnExtensionUnloaded(
content::BrowserContext* browser_context,
const extensions::Extension* extension,
extensions::UnloadedExtensionReason reason) {
if (IsWhitelistedChromeApp(extension) ||
if (IsAllowedChromeApp(extension) ||
extensions::ActionHandlersInfo::HasActionHandler(
extension, app_runtime::ACTION_TYPE_NEW_NOTE)) {
for (Observer& observer : observers_)
......@@ -632,11 +631,12 @@ NoteTakingLockScreenSupport NoteTakingHelper::GetLockScreenSupportForChromeApp(
if (!IsLockScreenEnabled(app))
return NoteTakingLockScreenSupport::kNotSupported;
if (lock_screen_whitelist_state_ == AppWhitelistState::kUndetermined)
UpdateLockScreenAppsWhitelistState();
if (allowed_lock_screen_apps_state_ == AllowedAppListState::kUndetermined)
UpdateAllowedLockScreenAppsList();
if (lock_screen_whitelist_state_ == AppWhitelistState::kAppsWhitelisted &&
!lock_screen_apps_allowed_by_policy_.count(app->id())) {
if (allowed_lock_screen_apps_state_ ==
AllowedAppListState::kAllowedAppsListed &&
!allowed_lock_screen_apps_by_policy_.count(app->id())) {
return NoteTakingLockScreenSupport::kNotAllowedByPolicy;
}
......@@ -647,7 +647,7 @@ NoteTakingLockScreenSupport NoteTakingHelper::GetLockScreenSupportForChromeApp(
}
void NoteTakingHelper::OnAllowedNoteTakingAppsChanged() {
if (lock_screen_whitelist_state_ == AppWhitelistState::kUndetermined)
if (allowed_lock_screen_apps_state_ == AllowedAppListState::kUndetermined)
return;
std::unique_ptr<NoteTakingAppInfo> preferred_app =
......@@ -656,7 +656,7 @@ void NoteTakingHelper::OnAllowedNoteTakingAppsChanged() {
preferred_app ? preferred_app->lock_screen_support
: NoteTakingLockScreenSupport::kNotSupported;
UpdateLockScreenAppsWhitelistState();
UpdateAllowedLockScreenAppsList();
preferred_app =
GetPreferredChromeAppInfo(profile_with_enabled_lock_screen_apps_);
......@@ -674,16 +674,17 @@ void NoteTakingHelper::OnAllowedNoteTakingAppsChanged() {
}
}
void NoteTakingHelper::UpdateLockScreenAppsWhitelistState() {
std::unique_ptr<std::set<std::string>> whitelist = GetAllowedLockScreenApps(
profile_with_enabled_lock_screen_apps_->GetPrefs());
void NoteTakingHelper::UpdateAllowedLockScreenAppsList() {
std::unique_ptr<std::set<std::string>> allowed_apps =
GetAllowedLockScreenApps(
profile_with_enabled_lock_screen_apps_->GetPrefs());
if (whitelist) {
lock_screen_whitelist_state_ = AppWhitelistState::kAppsWhitelisted;
lock_screen_apps_allowed_by_policy_.swap(*whitelist);
if (allowed_apps) {
allowed_lock_screen_apps_state_ = AllowedAppListState::kAllowedAppsListed;
allowed_lock_screen_apps_by_policy_.swap(*allowed_apps);
} else {
lock_screen_whitelist_state_ = AppWhitelistState::kNoAppWhitelist;
lock_screen_apps_allowed_by_policy_.clear();
allowed_lock_screen_apps_state_ = AllowedAppListState::kAllAppsAllowed;
allowed_lock_screen_apps_by_policy_.clear();
}
}
......
......@@ -80,8 +80,8 @@ struct NoteTakingAppInfo {
bool preferred;
// Whether the app supports taking notes on Chrome OS lock screen. Note that
// this ability is guarded by enable-lock-screen-apps feature flag, and
// whitelisted to Keep apps.
// this ability is guarded by enable-lock-screen-apps feature flag, and is
// currently restricted to Keep apps.
NoteTakingLockScreenSupport lock_screen_support;
};
......@@ -212,26 +212,25 @@ class NoteTakingHelper : public arc::ArcIntentHelperObserver,
}
private:
// The state of app ID whitelist cache (used for determining the state of
// note-taking apps whtielisted for the lock screen).
enum class AppWhitelistState {
// The whitelist value has not yet been determined.
// The state of the allowed app ID cache (used for determining the state of
// note-taking apps allowed on the lock screen).
enum class AllowedAppListState {
// The allowed apps have not yet been determined.
kUndetermined,
// The app ID whitelist does not exist in the profile.
kNoAppWhitelist,
// The app ID whitelist exists in the profile.
kAppsWhitelisted
// No app ID restriction exists in the profile.
kAllAppsAllowed,
// A list of allowed app IDs exists in the profile.
kAllowedAppsListed
};
NoteTakingHelper();
~NoteTakingHelper() override;
// Returns true if |extension| is a whitelisted note-taking app and false
// otherwise.
bool IsWhitelistedChromeApp(const extensions::Extension* extension) const;
// Returns whether |extension| is an allowed note-taking app.
bool IsAllowedChromeApp(const extensions::Extension* extension) const;
// Queries and returns all installed and enabled whitelisted Chrome
// note-taking apps for |profile|.
// Queries and returns the note-taking Chrome apps that are installed,
// enabled, and allowed for |profile|.
std::vector<const extensions::Extension*> GetChromeApps(
Profile* profile) const;
......@@ -266,11 +265,11 @@ class NoteTakingHelper : public arc::ArcIntentHelperObserver,
// |profile_with_enabled_lock_screen_apps_|.
void OnAllowedNoteTakingAppsChanged();
// Updates the cached whitelist of note-taking apps allowed on the lock
// screen - it sets |lock_screen_whitelist_state_| and
// |lock_screen_apps_allowed_by_policy_| to values appropriate for the current
// Updates the cached list of note-taking apps allowed on the lock screen - it
// sets |allowed_lock_screen_apps_state_| and
// |allowed_lock_screen_apps_by_policy_| to values appropriate for the current
// |profile_with_enabled_lock_screen_apps_| state.
void UpdateLockScreenAppsWhitelistState();
void UpdateAllowedLockScreenAppsList();
// True iff Play Store is enabled (i.e. per the checkbox on the settings
// page). Note that ARC may not be fully started yet when this is true, but it
......@@ -284,10 +283,10 @@ class NoteTakingHelper : public arc::ArcIntentHelperObserver,
// Callback used to launch Chrome apps. Can be overridden for tests.
LaunchChromeAppCallback launch_chrome_app_callback_;
// Extension IDs of whitelisted (but not necessarily installed) Chrome
// Extension IDs of allowed (but not necessarily installed) Chrome
// note-taking apps in the order in which they're chosen if the user hasn't
// expressed a preference.
std::vector<extensions::ExtensionId> whitelisted_chrome_app_ids_;
std::vector<extensions::ExtensionId> allowed_chrome_app_ids_;
// Cached information about available Android note-taking apps.
NoteTakingAppInfos android_apps_;
......@@ -300,18 +299,19 @@ class NoteTakingHelper : public arc::ArcIntentHelperObserver,
// The profile for which lock screen apps are enabled,
Profile* profile_with_enabled_lock_screen_apps_ = nullptr;
// The current AppWhitelistState for lock screen note taking in
// |profile_with_enabled_lock_screen_apps_|. If kAppsWhitelisted,
// |lock_screen_apps_allowed_by_policy_| should contain the set of whitelisted
// The current AllowedAppListState for lock screen note taking in
// |profile_with_enabled_lock_screen_apps_|. If kAllowedAppsListed,
// |lock_screen_apps_allowed_by_policy_| should contain the set of allowed
// app IDs.
AppWhitelistState lock_screen_whitelist_state_ =
AppWhitelistState::kUndetermined;
// If |lock_screen_whitelist_state_| is kAppsWhitelisted, contains all app
// IDs that are allowed to handle new-note action on the lock screen. The set
// should only be used for apps from |profile_with_enabled_lock_screen_apps_|
// and when |lock_screen_whitelist_state_| equals kAppsWhitelisted.
std::set<std::string> lock_screen_apps_allowed_by_policy_;
AllowedAppListState allowed_lock_screen_apps_state_ =
AllowedAppListState::kUndetermined;
// If |allowed_lock_screen_apps_state_| is kAllowedAppsListed, contains all
// app IDs that are allowed to handle new-note action on the lock screen. The
// set should only be used for apps from
// |profile_with_enabled_lock_screen_apps_| and when
// |allowed_lock_screen_apps_state_| equals kAllowedAppsListed.
std::set<std::string> allowed_lock_screen_apps_by_policy_;
// Tracks kNoteTakingAppsLockScreenAllowlist pref for the profile for which
// lock screen apps are enabled.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment