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 { ...@@ -52,7 +52,7 @@ namespace {
// Pointer to singleton instance. // Pointer to singleton instance.
NoteTakingHelper* g_helper = nullptr; NoteTakingHelper* g_helper = nullptr;
// Whitelisted Chrome note-taking apps. // Allowed Chrome note-taking apps.
const char* const kExtensionIds[] = { const char* const kExtensionIds[] = {
// TODO(jdufault): Remove dev version? See crbug.com/640828. // TODO(jdufault): Remove dev version? See crbug.com/640828.
NoteTakingHelper::kDevKeepExtensionId, NoteTakingHelper::kDevKeepExtensionId,
...@@ -90,10 +90,10 @@ bool IsLockScreenEnabled(const extensions::Extension* app) { ...@@ -90,10 +90,10 @@ bool IsLockScreenEnabled(const extensions::Extension* app) {
app, app_runtime::ACTION_TYPE_NEW_NOTE); app, app_runtime::ACTION_TYPE_NEW_NOTE);
} }
// Gets the set of apps (more specifically, their app IDs) that are allowed to // Gets the set of app IDs that are allowed to be launched on the lock screen,
// be launched on the lock screen, if the feature is whitelisted using // if the feature is restricted using the
// |prefs::kNoteTakingAppsLockScreenAllowlist| preference. If the pref is not // |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). // checked).
// Note that |prefs::kNoteTakingrAppsAllowedOnLockScreen| is currently only // Note that |prefs::kNoteTakingrAppsAllowedOnLockScreen| is currently only
// expected to be set by policy (if it's set at all). // expected to be set by policy (if it's set at all).
...@@ -217,7 +217,7 @@ std::unique_ptr<NoteTakingAppInfo> NoteTakingHelper::GetPreferredChromeAppInfo( ...@@ -217,7 +217,7 @@ std::unique_ptr<NoteTakingAppInfo> NoteTakingHelper::GetPreferredChromeAppInfo(
if (!preferred_app) if (!preferred_app)
return nullptr; return nullptr;
if (!IsWhitelistedChromeApp(preferred_app) && if (!IsAllowedChromeApp(preferred_app) &&
!extensions::ActionHandlersInfo::HasActionHandler( !extensions::ActionHandlersInfo::HasActionHandler(
preferred_app, app_runtime::ACTION_TYPE_NEW_NOTE)) { preferred_app, app_runtime::ACTION_TYPE_NEW_NOTE)) {
return nullptr; return nullptr;
...@@ -372,11 +372,10 @@ NoteTakingHelper::NoteTakingHelper() ...@@ -372,11 +372,10 @@ NoteTakingHelper::NoteTakingHelper()
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kNoteTakingAppIds); switches::kNoteTakingAppIds);
if (!switch_value.empty()) { 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); switch_value, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
} }
whitelisted_chrome_app_ids_.insert(whitelisted_chrome_app_ids_.end(), allowed_chrome_app_ids_.insert(allowed_chrome_app_ids_.end(), kExtensionIds,
kExtensionIds,
kExtensionIds + base::size(kExtensionIds)); kExtensionIds + base::size(kExtensionIds));
// Track profiles so we can observe their extension registries. // Track profiles so we can observe their extension registries.
...@@ -431,10 +430,10 @@ NoteTakingHelper::~NoteTakingHelper() { ...@@ -431,10 +430,10 @@ NoteTakingHelper::~NoteTakingHelper() {
} }
} }
bool NoteTakingHelper::IsWhitelistedChromeApp( bool NoteTakingHelper::IsAllowedChromeApp(
const extensions::Extension* extension) const { const extensions::Extension* extension) const {
DCHECK(extension); 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( std::vector<const extensions::Extension*> NoteTakingHelper::GetChromeApps(
...@@ -446,7 +445,7 @@ std::vector<const extensions::Extension*> NoteTakingHelper::GetChromeApps( ...@@ -446,7 +445,7 @@ std::vector<const extensions::Extension*> NoteTakingHelper::GetChromeApps(
extension_registry->enabled_extensions(); extension_registry->enabled_extensions();
std::vector<const extensions::Extension*> 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)) { if (enabled_extensions.Contains(id)) {
extensions.push_back(extension_registry->GetExtensionById( extensions.push_back(extension_registry->GetExtensionById(
id, extensions::ExtensionRegistry::ENABLED)); id, extensions::ExtensionRegistry::ENABLED));
...@@ -599,7 +598,7 @@ NoteTakingHelper::LaunchResult NoteTakingHelper::LaunchAppInternal( ...@@ -599,7 +598,7 @@ NoteTakingHelper::LaunchResult NoteTakingHelper::LaunchAppInternal(
void NoteTakingHelper::OnExtensionLoaded( void NoteTakingHelper::OnExtensionLoaded(
content::BrowserContext* browser_context, content::BrowserContext* browser_context,
const extensions::Extension* extension) { const extensions::Extension* extension) {
if (IsWhitelistedChromeApp(extension) || if (IsAllowedChromeApp(extension) ||
extensions::ActionHandlersInfo::HasActionHandler( extensions::ActionHandlersInfo::HasActionHandler(
extension, app_runtime::ACTION_TYPE_NEW_NOTE)) { extension, app_runtime::ACTION_TYPE_NEW_NOTE)) {
for (Observer& observer : observers_) for (Observer& observer : observers_)
...@@ -611,7 +610,7 @@ void NoteTakingHelper::OnExtensionUnloaded( ...@@ -611,7 +610,7 @@ void NoteTakingHelper::OnExtensionUnloaded(
content::BrowserContext* browser_context, content::BrowserContext* browser_context,
const extensions::Extension* extension, const extensions::Extension* extension,
extensions::UnloadedExtensionReason reason) { extensions::UnloadedExtensionReason reason) {
if (IsWhitelistedChromeApp(extension) || if (IsAllowedChromeApp(extension) ||
extensions::ActionHandlersInfo::HasActionHandler( extensions::ActionHandlersInfo::HasActionHandler(
extension, app_runtime::ACTION_TYPE_NEW_NOTE)) { extension, app_runtime::ACTION_TYPE_NEW_NOTE)) {
for (Observer& observer : observers_) for (Observer& observer : observers_)
...@@ -632,11 +631,12 @@ NoteTakingLockScreenSupport NoteTakingHelper::GetLockScreenSupportForChromeApp( ...@@ -632,11 +631,12 @@ NoteTakingLockScreenSupport NoteTakingHelper::GetLockScreenSupportForChromeApp(
if (!IsLockScreenEnabled(app)) if (!IsLockScreenEnabled(app))
return NoteTakingLockScreenSupport::kNotSupported; return NoteTakingLockScreenSupport::kNotSupported;
if (lock_screen_whitelist_state_ == AppWhitelistState::kUndetermined) if (allowed_lock_screen_apps_state_ == AllowedAppListState::kUndetermined)
UpdateLockScreenAppsWhitelistState(); UpdateAllowedLockScreenAppsList();
if (lock_screen_whitelist_state_ == AppWhitelistState::kAppsWhitelisted && if (allowed_lock_screen_apps_state_ ==
!lock_screen_apps_allowed_by_policy_.count(app->id())) { AllowedAppListState::kAllowedAppsListed &&
!allowed_lock_screen_apps_by_policy_.count(app->id())) {
return NoteTakingLockScreenSupport::kNotAllowedByPolicy; return NoteTakingLockScreenSupport::kNotAllowedByPolicy;
} }
...@@ -647,7 +647,7 @@ NoteTakingLockScreenSupport NoteTakingHelper::GetLockScreenSupportForChromeApp( ...@@ -647,7 +647,7 @@ NoteTakingLockScreenSupport NoteTakingHelper::GetLockScreenSupportForChromeApp(
} }
void NoteTakingHelper::OnAllowedNoteTakingAppsChanged() { void NoteTakingHelper::OnAllowedNoteTakingAppsChanged() {
if (lock_screen_whitelist_state_ == AppWhitelistState::kUndetermined) if (allowed_lock_screen_apps_state_ == AllowedAppListState::kUndetermined)
return; return;
std::unique_ptr<NoteTakingAppInfo> preferred_app = std::unique_ptr<NoteTakingAppInfo> preferred_app =
...@@ -656,7 +656,7 @@ void NoteTakingHelper::OnAllowedNoteTakingAppsChanged() { ...@@ -656,7 +656,7 @@ void NoteTakingHelper::OnAllowedNoteTakingAppsChanged() {
preferred_app ? preferred_app->lock_screen_support preferred_app ? preferred_app->lock_screen_support
: NoteTakingLockScreenSupport::kNotSupported; : NoteTakingLockScreenSupport::kNotSupported;
UpdateLockScreenAppsWhitelistState(); UpdateAllowedLockScreenAppsList();
preferred_app = preferred_app =
GetPreferredChromeAppInfo(profile_with_enabled_lock_screen_apps_); GetPreferredChromeAppInfo(profile_with_enabled_lock_screen_apps_);
...@@ -674,16 +674,17 @@ void NoteTakingHelper::OnAllowedNoteTakingAppsChanged() { ...@@ -674,16 +674,17 @@ void NoteTakingHelper::OnAllowedNoteTakingAppsChanged() {
} }
} }
void NoteTakingHelper::UpdateLockScreenAppsWhitelistState() { void NoteTakingHelper::UpdateAllowedLockScreenAppsList() {
std::unique_ptr<std::set<std::string>> whitelist = GetAllowedLockScreenApps( std::unique_ptr<std::set<std::string>> allowed_apps =
GetAllowedLockScreenApps(
profile_with_enabled_lock_screen_apps_->GetPrefs()); profile_with_enabled_lock_screen_apps_->GetPrefs());
if (whitelist) { if (allowed_apps) {
lock_screen_whitelist_state_ = AppWhitelistState::kAppsWhitelisted; allowed_lock_screen_apps_state_ = AllowedAppListState::kAllowedAppsListed;
lock_screen_apps_allowed_by_policy_.swap(*whitelist); allowed_lock_screen_apps_by_policy_.swap(*allowed_apps);
} else { } else {
lock_screen_whitelist_state_ = AppWhitelistState::kNoAppWhitelist; allowed_lock_screen_apps_state_ = AllowedAppListState::kAllAppsAllowed;
lock_screen_apps_allowed_by_policy_.clear(); allowed_lock_screen_apps_by_policy_.clear();
} }
} }
......
...@@ -80,8 +80,8 @@ struct NoteTakingAppInfo { ...@@ -80,8 +80,8 @@ struct NoteTakingAppInfo {
bool preferred; bool preferred;
// Whether the app supports taking notes on Chrome OS lock screen. Note that // 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 // this ability is guarded by enable-lock-screen-apps feature flag, and is
// whitelisted to Keep apps. // currently restricted to Keep apps.
NoteTakingLockScreenSupport lock_screen_support; NoteTakingLockScreenSupport lock_screen_support;
}; };
...@@ -212,26 +212,25 @@ class NoteTakingHelper : public arc::ArcIntentHelperObserver, ...@@ -212,26 +212,25 @@ class NoteTakingHelper : public arc::ArcIntentHelperObserver,
} }
private: private:
// The state of app ID whitelist cache (used for determining the state of // The state of the allowed app ID cache (used for determining the state of
// note-taking apps whtielisted for the lock screen). // note-taking apps allowed on the lock screen).
enum class AppWhitelistState { enum class AllowedAppListState {
// The whitelist value has not yet been determined. // The allowed apps have not yet been determined.
kUndetermined, kUndetermined,
// The app ID whitelist does not exist in the profile. // No app ID restriction exists in the profile.
kNoAppWhitelist, kAllAppsAllowed,
// The app ID whitelist exists in the profile. // A list of allowed app IDs exists in the profile.
kAppsWhitelisted kAllowedAppsListed
}; };
NoteTakingHelper(); NoteTakingHelper();
~NoteTakingHelper() override; ~NoteTakingHelper() override;
// Returns true if |extension| is a whitelisted note-taking app and false // Returns whether |extension| is an allowed note-taking app.
// otherwise. bool IsAllowedChromeApp(const extensions::Extension* extension) const;
bool IsWhitelistedChromeApp(const extensions::Extension* extension) const;
// Queries and returns all installed and enabled whitelisted Chrome // Queries and returns the note-taking Chrome apps that are installed,
// note-taking apps for |profile|. // enabled, and allowed for |profile|.
std::vector<const extensions::Extension*> GetChromeApps( std::vector<const extensions::Extension*> GetChromeApps(
Profile* profile) const; Profile* profile) const;
...@@ -266,11 +265,11 @@ class NoteTakingHelper : public arc::ArcIntentHelperObserver, ...@@ -266,11 +265,11 @@ class NoteTakingHelper : public arc::ArcIntentHelperObserver,
// |profile_with_enabled_lock_screen_apps_|. // |profile_with_enabled_lock_screen_apps_|.
void OnAllowedNoteTakingAppsChanged(); void OnAllowedNoteTakingAppsChanged();
// Updates the cached whitelist of note-taking apps allowed on the lock // Updates the cached list of note-taking apps allowed on the lock screen - it
// screen - it sets |lock_screen_whitelist_state_| and // sets |allowed_lock_screen_apps_state_| and
// |lock_screen_apps_allowed_by_policy_| to values appropriate for the current // |allowed_lock_screen_apps_by_policy_| to values appropriate for the current
// |profile_with_enabled_lock_screen_apps_| state. // |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 // 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 // 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, ...@@ -284,10 +283,10 @@ class NoteTakingHelper : public arc::ArcIntentHelperObserver,
// Callback used to launch Chrome apps. Can be overridden for tests. // Callback used to launch Chrome apps. Can be overridden for tests.
LaunchChromeAppCallback launch_chrome_app_callback_; 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 // note-taking apps in the order in which they're chosen if the user hasn't
// expressed a preference. // 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. // Cached information about available Android note-taking apps.
NoteTakingAppInfos android_apps_; NoteTakingAppInfos android_apps_;
...@@ -300,18 +299,19 @@ class NoteTakingHelper : public arc::ArcIntentHelperObserver, ...@@ -300,18 +299,19 @@ class NoteTakingHelper : public arc::ArcIntentHelperObserver,
// The profile for which lock screen apps are enabled, // The profile for which lock screen apps are enabled,
Profile* profile_with_enabled_lock_screen_apps_ = nullptr; Profile* profile_with_enabled_lock_screen_apps_ = nullptr;
// The current AppWhitelistState for lock screen note taking in // The current AllowedAppListState for lock screen note taking in
// |profile_with_enabled_lock_screen_apps_|. If kAppsWhitelisted, // |profile_with_enabled_lock_screen_apps_|. If kAllowedAppsListed,
// |lock_screen_apps_allowed_by_policy_| should contain the set of whitelisted // |lock_screen_apps_allowed_by_policy_| should contain the set of allowed
// app IDs. // app IDs.
AppWhitelistState lock_screen_whitelist_state_ = AllowedAppListState allowed_lock_screen_apps_state_ =
AppWhitelistState::kUndetermined; AllowedAppListState::kUndetermined;
// If |lock_screen_whitelist_state_| is kAppsWhitelisted, contains all app // If |allowed_lock_screen_apps_state_| is kAllowedAppsListed, contains all
// IDs that are allowed to handle new-note action on the lock screen. The set // app IDs that are allowed to handle new-note action on the lock screen. The
// should only be used for apps from |profile_with_enabled_lock_screen_apps_| // set should only be used for apps from
// and when |lock_screen_whitelist_state_| equals kAppsWhitelisted. // |profile_with_enabled_lock_screen_apps_| and when
std::set<std::string> lock_screen_apps_allowed_by_policy_; // |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 // Tracks kNoteTakingAppsLockScreenAllowlist pref for the profile for which
// lock screen apps are enabled. // 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