Commit 519d45c4 authored by Owen Min's avatar Owen Min Committed by Commit Bot

Generate profile report with extension requests only.

Extension request only report only contains
- profile id
- extension request.
But not
- extension list
- policies info

Profile name and sign in user info only added on CrOS.

Bug: 1137964
Change-Id: I76bc72acde86f149ac090d839d159ddb56b6bb6a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2485276Reviewed-by: default avatarJulian Pastarmov <pastarmovj@chromium.org>
Reviewed-by: default avatarOwen Min <zmin@chromium.org>
Commit-Queue: Owen Min <zmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#819442}
parent 4fc1007c
...@@ -265,4 +265,41 @@ TEST_F(ProfileReportGeneratorTest, TooManyRequests) { ...@@ -265,4 +265,41 @@ TEST_F(ProfileReportGeneratorTest, TooManyRequests) {
report2->extension_requests(id).id()); report2->extension_requests(id).id());
} }
TEST_F(ProfileReportGeneratorTest, ExtensionRequestOnlyReport) {
profile()->GetTestingPrefService()->SetManagedPref(
prefs::kCloudExtensionRequestEnabled,
std::make_unique<base::Value>(true));
std::vector<std::string> ids = {kExtensionId};
SetExtensionToPendingList(ids);
IdentityTestEnvironmentProfileAdaptor identity_test_env_adaptor(profile());
auto expected_info =
identity_test_env_adaptor.identity_test_env()->SetPrimaryAccount(
"test@mail.com");
auto report = generator_.MaybeGenerate(profile()->GetPath(),
profile()->GetProfileUserName(),
ReportType::kExtensionRequest);
// Extension request and profile id are included. Profile name and sign in
// users info are included on CrOS only.
EXPECT_TRUE(report);
EXPECT_EQ(profile()->GetPath().AsUTF8Unsafe(), report->id());
#if defined(OS_CHROMEOS)
EXPECT_EQ(profile()->GetProfileUserName(), report->name());
EXPECT_TRUE(report->has_chrome_signed_in_user());
#else
EXPECT_FALSE(report->has_name());
EXPECT_FALSE(report->has_chrome_signed_in_user());
#endif
ASSERT_EQ(1, report->extension_requests_size());
EXPECT_EQ(kExtensionId, report->extension_requests(0).id());
EXPECT_EQ(kFakeTime, report->extension_requests(0).request_timestamp());
// Policies and extensions info should not be added.
EXPECT_EQ(0, report->chrome_policies_size());
EXPECT_EQ(0, report->extensions_size());
EXPECT_EQ(0, report->policy_fetched_timestamps_size());
}
} // namespace enterprise_reporting } // namespace enterprise_reporting
...@@ -34,6 +34,7 @@ static_library("enterprise") { ...@@ -34,6 +34,7 @@ static_library("enterprise") {
"browser/reporting/report_request_queue_generator.h", "browser/reporting/report_request_queue_generator.h",
"browser/reporting/report_scheduler.cc", "browser/reporting/report_scheduler.cc",
"browser/reporting/report_scheduler.h", "browser/reporting/report_scheduler.h",
"browser/reporting/report_type.h",
"browser/reporting/report_uploader.cc", "browser/reporting/report_uploader.cc",
"browser/reporting/report_uploader.h", "browser/reporting/report_uploader.h",
"browser/reporting/reporting_delegate_factory.h", "browser/reporting/reporting_delegate_factory.h",
......
...@@ -31,32 +31,44 @@ void ProfileReportGenerator::set_policies_enabled(bool enabled) { ...@@ -31,32 +31,44 @@ void ProfileReportGenerator::set_policies_enabled(bool 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,
ReportType report_type) {
if (!delegate_->Init(path)) { if (!delegate_->Init(path)) {
return nullptr; return nullptr;
} }
report_ = std::make_unique<em::ChromeUserProfileInfo>(); report_ = std::make_unique<em::ChromeUserProfileInfo>();
report_->set_id(path.AsUTF8Unsafe()); report_->set_id(path.AsUTF8Unsafe());
report_->set_name(name);
report_->set_is_full_report(true);
delegate_->GetSigninUserInfo(report_.get()); if (report_type == ReportType::kExtensionRequest) {
if (extensions_enabled_) { #if defined(OS_CHROMEOS)
delegate_->GetExtensionInfo(report_.get()); // Extension request is aggregated at the user level on CrOS.
} report_->set_name(name);
delegate_->GetExtensionRequest(report_.get()); delegate_->GetSigninUserInfo(report_.get());
#endif // defined(OS_CHROMEOS)
if (policies_enabled_) { delegate_->GetExtensionRequest(report_.get());
// TODO(crbug.com/983151): Upload policy error as their IDs.
auto client = delegate_->MakePolicyConversionsClient(); } else {
policies_ = policy::DictionaryPolicyConversions(std::move(client)) report_->set_name(name);
.EnableConvertTypes(false) report_->set_is_full_report(true);
.EnablePrettyPrint(false)
.ToValue(); delegate_->GetSigninUserInfo(report_.get());
GetChromePolicyInfo(); if (extensions_enabled_) {
GetExtensionPolicyInfo(); delegate_->GetExtensionInfo(report_.get());
GetPolicyFetchTimestampInfo(); }
delegate_->GetExtensionRequest(report_.get());
if (policies_enabled_) {
// TODO(crbug.com/983151): Upload policy error as their IDs.
auto client = delegate_->MakePolicyConversionsClient();
policies_ = policy::DictionaryPolicyConversions(std::move(client))
.EnableConvertTypes(false)
.EnablePrettyPrint(false)
.ToValue();
GetChromePolicyInfo();
GetExtensionPolicyInfo();
GetPolicyFetchTimestampInfo();
}
} }
return std::move(report_); return std::move(report_);
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include <string> #include <string>
#include "base/values.h" #include "base/values.h"
#include "components/enterprise/browser/reporting/report_request_definition.h"
#include "components/enterprise/browser/reporting/report_type.h"
#include "components/policy/core/browser/policy_conversions_client.h" #include "components/policy/core/browser/policy_conversions_client.h"
#include "components/policy/proto/device_management_backend.pb.h" #include "components/policy/proto/device_management_backend.pb.h"
...@@ -72,7 +74,8 @@ class ProfileReportGenerator { ...@@ -72,7 +74,8 @@ class ProfileReportGenerator {
// generated. // generated.
std::unique_ptr<enterprise_management::ChromeUserProfileInfo> MaybeGenerate( std::unique_ptr<enterprise_management::ChromeUserProfileInfo> MaybeGenerate(
const base::FilePath& path, const base::FilePath& path,
const std::string& name); const std::string& name,
ReportType report_type = ReportType::kFull);
protected: protected:
void GetChromePolicyInfo(); void GetChromePolicyInfo();
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_ENTERPRISE_BROWSER_REPORTING_REPORT_TYPE_H_
#define COMPONENTS_ENTERPRISE_BROWSER_REPORTING_REPORT_TYPE_H_
namespace enterprise_reporting {
enum ReportType : uint32_t {
kFull = 0,
kBrowserVersion = 1u << 0,
kExtensionRequest = 2u << 1,
};
} // namespace enterprise_reporting
#endif // COMPONENTS_ENTERPRISE_BROWSER_REPORTING_REPORT_TYPE_H_
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