Commit 9a1fdb3b authored by Owen Min's avatar Owen Min Committed by Commit Bot

Append extension request to the report

Extension requests are cached in the profile pref. Append the pending
list into the report.

Bug: 1006899
Change-Id: I62bee93204bb68a790f6ac6176046f17e1860172
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1894034Reviewed-by: default avatarJulian Pastarmov <pastarmovj@chromium.org>
Commit-Queue: Owen Min <zmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#712647}
parent 860963d4
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/signin/identity_manager_factory.h" #include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/common/pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/signin/public/identity_manager/account_info.h" #include "components/signin/public/identity_manager/account_info.h"
#include "components/signin/public/identity_manager/identity_manager.h" #include "components/signin/public/identity_manager/identity_manager.h"
...@@ -31,6 +33,10 @@ void ProfileReportGenerator::set_policies_enabled(bool enabled) { ...@@ -31,6 +33,10 @@ void ProfileReportGenerator::set_policies_enabled(bool enabled) {
policies_enabled_ = enabled; policies_enabled_ = enabled;
} }
void ProfileReportGenerator::set_extension_request_enabled(bool enabled) {
extension_request_enabled_ = enabled;
}
std::unique_ptr<em::ChromeUserProfileInfo> std::unique_ptr<em::ChromeUserProfileInfo>
ProfileReportGenerator::MaybeGenerate(const base::FilePath& path, ProfileReportGenerator::MaybeGenerate(const base::FilePath& path,
const std::string& name) { const std::string& name) {
...@@ -47,6 +53,7 @@ ProfileReportGenerator::MaybeGenerate(const base::FilePath& path, ...@@ -47,6 +53,7 @@ ProfileReportGenerator::MaybeGenerate(const base::FilePath& path,
GetSigninUserInfo(); GetSigninUserInfo();
GetExtensionInfo(); GetExtensionInfo();
GetExtensionRequest();
if (policies_enabled_) { if (policies_enabled_) {
// TODO(crbug.com/983151): Upload policy error as their IDs. // TODO(crbug.com/983151): Upload policy error as their IDs.
...@@ -91,5 +98,14 @@ void ProfileReportGenerator::GetPolicyFetchTimestampInfo() { ...@@ -91,5 +98,14 @@ void ProfileReportGenerator::GetPolicyFetchTimestampInfo() {
AppendMachineLevelUserCloudPolicyFetchTimestamp(report_.get()); AppendMachineLevelUserCloudPolicyFetchTimestamp(report_.get());
} }
void ProfileReportGenerator::GetExtensionRequest() {
if (!extension_request_enabled_)
return;
const auto pending_list = profile_->GetPrefs()
->GetList(prefs::kCloudExtensionRequestIds)
->GetList();
for (const base::Value& pending_request : pending_list)
report_->add_extension_requests()->set_id(pending_request.GetString());
}
} // namespace enterprise_reporting } // namespace enterprise_reporting
...@@ -33,6 +33,7 @@ class ProfileReportGenerator { ...@@ -33,6 +33,7 @@ class ProfileReportGenerator {
void set_extensions_enabled(bool enabled); void set_extensions_enabled(bool enabled);
void set_policies_enabled(bool enabled); void set_policies_enabled(bool enabled);
void set_extension_request_enabled(bool enabled);
// Generates report for Profile if it's activated. Returns the report with // Generates report for Profile if it's activated. Returns the report with
// |callback| once it's ready. The report is null if it can't be generated. // |callback| once it's ready. The report is null if it can't be generated.
...@@ -48,6 +49,7 @@ class ProfileReportGenerator { ...@@ -48,6 +49,7 @@ class ProfileReportGenerator {
void GetChromePolicyInfo(); void GetChromePolicyInfo();
void GetExtensionPolicyInfo(); void GetExtensionPolicyInfo();
void GetPolicyFetchTimestampInfo(); void GetPolicyFetchTimestampInfo();
void GetExtensionRequest();
private: private:
Profile* profile_; Profile* profile_;
...@@ -55,6 +57,7 @@ class ProfileReportGenerator { ...@@ -55,6 +57,7 @@ class ProfileReportGenerator {
bool extensions_enabled_ = true; bool extensions_enabled_ = true;
bool policies_enabled_ = true; bool policies_enabled_ = true;
bool extension_request_enabled_ = false;
std::unique_ptr<em::ChromeUserProfileInfo> report_ = nullptr; std::unique_ptr<em::ChromeUserProfileInfo> report_ = nullptr;
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/profiles/profile_attributes_storage.h" #include "chrome/browser/profiles/profile_attributes_storage.h"
#include "chrome/browser/signin/identity_test_environment_profile_adaptor.h" #include "chrome/browser/signin/identity_test_environment_profile_adaptor.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile_manager.h" #include "chrome/test/base/testing_profile_manager.h"
#include "components/account_id/account_id.h" #include "components/account_id/account_id.h"
...@@ -18,8 +19,9 @@ ...@@ -18,8 +19,9 @@
namespace enterprise_reporting { namespace enterprise_reporting {
namespace { namespace {
const char kProfile[] = "Profile"; constexpr char kProfile[] = "Profile";
const char kIdleProfile[] = "IdleProfile"; constexpr char kIdleProfile[] = "IdleProfile";
constexpr char kExtensionId[] = "abcdefghijklmnopabcdefghijklmnop";
} // namespace } // namespace
...@@ -56,6 +58,15 @@ class ProfileReportGeneratorTest : public ::testing::Test { ...@@ -56,6 +58,15 @@ class ProfileReportGeneratorTest : public ::testing::Test {
return report; return report;
} }
void SetExtensionToPendingList(const std::vector<std::string>& ids) {
base::Value::ListStorage id_values;
for (auto id : ids)
id_values.push_back(base::Value(id));
profile()->GetTestingPrefService()->SetUserPref(
prefs::kCloudExtensionRequestIds,
std::make_unique<base::Value>(std::move(id_values)));
}
TestingProfile* profile() { return profile_; } TestingProfile* profile() { return profile_; }
TestingProfileManager* profile_manager() { return &profile_manager_; } TestingProfileManager* profile_manager() { return &profile_manager_; }
...@@ -97,4 +108,23 @@ TEST_F(ProfileReportGeneratorTest, SignedInProfile) { ...@@ -97,4 +108,23 @@ TEST_F(ProfileReportGeneratorTest, SignedInProfile) {
report->chrome_signed_in_user().obfudscated_gaia_id()); report->chrome_signed_in_user().obfudscated_gaia_id());
} }
TEST_F(ProfileReportGeneratorTest, PendingRequest) {
generator_.set_extension_request_enabled(true);
std::vector<std::string> ids = {kExtensionId};
SetExtensionToPendingList(ids);
auto report = GenerateReport();
EXPECT_EQ(1, report->extension_requests_size());
EXPECT_EQ(kExtensionId, report->extension_requests(0).id());
}
TEST_F(ProfileReportGeneratorTest, NoPendingRequestWhenItsDisabled) {
generator_.set_extension_request_enabled(false);
std::vector<std::string> ids = {kExtensionId};
SetExtensionToPendingList(ids);
auto report = GenerateReport();
EXPECT_EQ(0, report->extension_requests_size());
}
} // namespace enterprise_reporting } // namespace enterprise_reporting
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