Commit 0e1b03b8 authored by Oleg Davydov's avatar Oleg Davydov Committed by Commit Bot

Support removing extension from policy in InstallationTracker

Historically InstallationTracker was made to get a broad picture of what
happens with force-installed extensions. So case "policy changed shortly
after login so extension was not installed because it is not needed more"
was ignored as something that happens rare.

This CL support that case too. Note that if policy changed shortly after
login, we still ignore new extensions. We do this intentionally: for
such a new extension we may want to know "whether it is installed five
minutes after it appear in policy", not "five minutes after login".

Bug: 981891
Change-Id: If700a222d43504092bad8fb69f811fad0d54fd8e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1853404
Commit-Queue: Oleg Davydov <burunduk@chromium.org>
Reviewed-by: default avatarSergey Poromov <poromov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705535}
parent d3bf2a16
......@@ -49,14 +49,32 @@ InstallationTracker::InstallationTracker(
InstallationTracker::~InstallationTracker() = default;
void InstallationTracker::OnForcedExtensionsPrefChanged() {
// Load forced extensions list only once.
if (!forced_extensions_.empty())
return;
const base::DictionaryValue* value =
pref_service_->GetDictionary(pref_names::kInstallForceList);
if (!value || value->empty())
if (!value)
return;
std::vector<ExtensionId> extensions_to_remove;
for (const auto& extension_id : forced_extensions_) {
if (value->FindKey(extension_id) == nullptr)
extensions_to_remove.push_back(extension_id);
}
for (const auto& extension_id : extensions_to_remove) {
forced_extensions_.erase(extension_id);
pending_forced_extensions_.erase(extension_id);
}
// Report if all remaining extensions were removed from policy.
if (loaded_ && pending_forced_extensions_.empty())
ReportResults(true /* succeeded */);
// Load forced extensions list only once.
if (value->empty() || loaded_) {
return;
}
loaded_ = true;
for (const auto& entry : *value) {
forced_extensions_.insert(entry.first);
......
......@@ -68,6 +68,9 @@ class InstallationTracker : public ExtensionRegistryObserver {
// Set of not yet loaded force installed extensions.
std::set<std::string> pending_forced_extensions_;
// Tracks whether non-empty forcelist policy was received at least once.
bool loaded_ = false;
// Tracks whether stats were already reported for the session.
bool reported_ = false;
......
......@@ -64,6 +64,12 @@ class ForcedExtensionsInstallationTrackerTest : public testing::Test {
base::Value::ToUniquePtrValue(std::move(dict)));
}
void SetupEmptyForceList() {
base::Value dict(base::Value::Type::DICTIONARY);
prefs_->SetManagedPref(pref_names::kInstallForceList,
base::Value::ToUniquePtrValue(std::move(dict)));
}
protected:
content::BrowserTaskEnvironment task_environment_;
TestingProfile profile_;
......@@ -118,6 +124,21 @@ TEST_F(ForcedExtensionsInstallationTrackerTest,
prefs_->GetManagedPref(pref_names::kInstallForceList)->DictSize(), 1);
}
TEST_F(ForcedExtensionsInstallationTrackerTest,
ExtensionsInstallationCancelled) {
SetupForceList();
SetupEmptyForceList();
// InstallationTracker shuts down timer because there is nothing to do more.
EXPECT_FALSE(fake_timer_->IsRunning());
histogram_tester_.ExpectTotalCount(kLoadTimeStats, 0);
histogram_tester_.ExpectTotalCount(kTimedOutStats, 0);
histogram_tester_.ExpectTotalCount(kTimedOutNotInstalledStats, 0);
histogram_tester_.ExpectTotalCount(kFailureReasons, 0);
histogram_tester_.ExpectTotalCount(kInstallationStages, 0);
histogram_tester_.ExpectTotalCount(kFailureCrxInstallErrorStats, 0);
histogram_tester_.ExpectTotalCount(kTotalCountStats, 0);
}
TEST_F(ForcedExtensionsInstallationTrackerTest,
ExtensionsInstallationTimedOutDifferentReasons) {
SetupForceList();
......
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