Commit fd291ef1 authored by Anqing Zhao's avatar Anqing Zhao Committed by Commit Bot

Skip some fields for CBCM Reporting on Chrome OS

According to offline discussion, we agree not to collect following data
on Chrome OS.
* browser_version
* browser_channel
* plugins

Bug: 1010213
Change-Id: I8f2c1e0d0f264f6a78c422afcbc101498ce362c8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1976591
Commit-Queue: Anqing Zhao <anqing@google.com>
Reviewed-by: default avatarSergey Poromov <poromov@chromium.org>
Reviewed-by: default avatarOwen Min <zmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#726807}
parent 3e3214fc
...@@ -43,10 +43,24 @@ void BrowserReportGenerator::Generate(ReportCallback callback) { ...@@ -43,10 +43,24 @@ void BrowserReportGenerator::Generate(ReportCallback callback) {
callback_ = std::move(callback); callback_ = std::move(callback);
auto report = std::make_unique<em::BrowserReport>(); auto report = std::make_unique<em::BrowserReport>();
GenerateBasicInfos(report.get());
GenerateProfileInfos(report.get());
// std::move is required here because the function completes the report
// asynchronously.
GeneratePlugins(std::move(report));
}
void BrowserReportGenerator::GenerateBasicInfos(em::BrowserReport* report) {
#if !defined(OS_CHROMEOS)
report->set_browser_version(version_info::GetVersionNumber()); report->set_browser_version(version_info::GetVersionNumber());
report->set_channel(policy::ConvertToProtoChannel(chrome::GetChannel())); report->set_channel(policy::ConvertToProtoChannel(chrome::GetChannel()));
#endif
report->set_executable_path(GetExecutablePath()); report->set_executable_path(GetExecutablePath());
}
void BrowserReportGenerator::GenerateProfileInfos(em::BrowserReport* report) {
for (auto* entry : g_browser_process->profile_manager() for (auto* entry : g_browser_process->profile_manager()
->GetProfileAttributesStorage() ->GetProfileAttributesStorage()
.GetAllProfilesAttributes()) { .GetAllProfilesAttributes()) {
...@@ -63,10 +77,17 @@ void BrowserReportGenerator::Generate(ReportCallback callback) { ...@@ -63,10 +77,17 @@ void BrowserReportGenerator::Generate(ReportCallback callback) {
profile->set_name(base::UTF16ToUTF8(entry->GetName())); profile->set_name(base::UTF16ToUTF8(entry->GetName()));
profile->set_is_full_report(false); profile->set_is_full_report(false);
} }
}
void BrowserReportGenerator::GeneratePlugins(
std::unique_ptr<em::BrowserReport> report) {
#if defined(OS_CHROMEOS)
std::move(callback_).Run(std::move(report));
#else
content::PluginService::GetInstance()->GetPlugins( content::PluginService::GetInstance()->GetPlugins(
base::BindOnce(&BrowserReportGenerator::OnPluginsReady, base::BindOnce(&BrowserReportGenerator::OnPluginsReady,
weak_ptr_factory_.GetWeakPtr(), std::move(report))); weak_ptr_factory_.GetWeakPtr(), std::move(report)));
#endif
} }
void BrowserReportGenerator::OnPluginsReady( void BrowserReportGenerator::OnPluginsReady(
......
...@@ -35,6 +35,17 @@ class BrowserReportGenerator { ...@@ -35,6 +35,17 @@ class BrowserReportGenerator {
void Generate(ReportCallback callback); void Generate(ReportCallback callback);
private: private:
// Generate browser_version, channel, executable_path info in the given
// report instance.
void GenerateBasicInfos(em::BrowserReport* report);
// Generate user profiles info in the given report instance.
void GenerateProfileInfos(em::BrowserReport* report);
// Generate plugin info in the given report instance. It requires the
// ownership of report instance to pass into ReportCallback method.
void GeneratePlugins(std::unique_ptr<em::BrowserReport> report);
void OnPluginsReady(std::unique_ptr<em::BrowserReport> report, void OnPluginsReady(std::unique_ptr<em::BrowserReport> report,
const std::vector<content::WebPluginInfo>& plugins); const std::vector<content::WebPluginInfo>& plugins);
......
...@@ -90,9 +90,15 @@ class BrowserReportGeneratorTest : public ::testing::Test { ...@@ -90,9 +90,15 @@ class BrowserReportGeneratorTest : public ::testing::Test {
[&run_loop](std::unique_ptr<em::BrowserReport> report) { [&run_loop](std::unique_ptr<em::BrowserReport> report) {
EXPECT_TRUE(report.get()); EXPECT_TRUE(report.get());
#if defined(OS_CHROMEOS)
EXPECT_FALSE(report->has_browser_version());
EXPECT_FALSE(report->has_channel());
#else
EXPECT_NE(std::string(), report->browser_version()); EXPECT_NE(std::string(), report->browser_version());
EXPECT_NE(std::string(), report->executable_path());
EXPECT_TRUE(report->has_channel()); EXPECT_TRUE(report->has_channel());
#endif
EXPECT_NE(std::string(), report->executable_path());
EXPECT_EQ(1, report->chrome_user_profile_infos_size()); EXPECT_EQ(1, report->chrome_user_profile_infos_size());
em::ChromeUserProfileInfo profile = em::ChromeUserProfileInfo profile =
...@@ -101,12 +107,16 @@ class BrowserReportGeneratorTest : public ::testing::Test { ...@@ -101,12 +107,16 @@ class BrowserReportGeneratorTest : public ::testing::Test {
EXPECT_EQ(kProfileName, profile.name()); EXPECT_EQ(kProfileName, profile.name());
EXPECT_FALSE(profile.is_full_report()); EXPECT_FALSE(profile.is_full_report());
#if defined(OS_CHROMEOS)
EXPECT_EQ(0, report->plugins_size());
#else
EXPECT_LE(1, report->plugins_size()); EXPECT_LE(1, report->plugins_size());
em::Plugin plugin = report->plugins(0); em::Plugin plugin = report->plugins(0);
EXPECT_EQ(kPluginName, plugin.name()); EXPECT_EQ(kPluginName, plugin.name());
EXPECT_EQ(kPluginVersion, plugin.version()); EXPECT_EQ(kPluginVersion, plugin.version());
EXPECT_EQ(kPluginFileName, plugin.filename()); EXPECT_EQ(kPluginFileName, plugin.filename());
EXPECT_EQ(kPluginDescription, plugin.description()); EXPECT_EQ(kPluginDescription, plugin.description());
#endif
run_loop.Quit(); run_loop.Quit();
})); }));
run_loop.Run(); run_loop.Run();
......
...@@ -292,9 +292,18 @@ TEST_F(ReportGeneratorTest, GenerateBasicReport) { ...@@ -292,9 +292,18 @@ TEST_F(ReportGeneratorTest, GenerateBasicReport) {
EXPECT_TRUE(basic_request->has_browser_report()); EXPECT_TRUE(basic_request->has_browser_report());
auto& browser_report = basic_request->browser_report(); auto& browser_report = basic_request->browser_report();
#if defined(OS_CHROMEOS)
EXPECT_FALSE(browser_report.has_browser_version());
EXPECT_FALSE(browser_report.has_channel());
#else
EXPECT_NE(std::string(), browser_report.browser_version()); EXPECT_NE(std::string(), browser_report.browser_version());
EXPECT_NE(std::string(), browser_report.executable_path());
EXPECT_TRUE(browser_report.has_channel()); EXPECT_TRUE(browser_report.has_channel());
#endif
EXPECT_NE(std::string(), browser_report.executable_path());
#if defined(OS_CHROMEOS)
EXPECT_EQ(0, browser_report.plugins_size());
#else
// There might be other plugins like PDF plugin, however, our fake plugin // There might be other plugins like PDF plugin, however, our fake plugin
// should be the first one in the report. // should be the first one in the report.
EXPECT_LE(1, browser_report.plugins_size()); EXPECT_LE(1, browser_report.plugins_size());
...@@ -302,6 +311,7 @@ TEST_F(ReportGeneratorTest, GenerateBasicReport) { ...@@ -302,6 +311,7 @@ TEST_F(ReportGeneratorTest, GenerateBasicReport) {
EXPECT_EQ(kPluginVersion, browser_report.plugins(0).version()); EXPECT_EQ(kPluginVersion, browser_report.plugins(0).version());
EXPECT_EQ(kPluginDescription, browser_report.plugins(0).description()); EXPECT_EQ(kPluginDescription, browser_report.plugins(0).description());
EXPECT_EQ(kPluginFileName, browser_report.plugins(0).filename()); EXPECT_EQ(kPluginFileName, browser_report.plugins(0).filename());
#endif
VerifyProfileReport(/*active_profile_names*/ std::set<std::string>(), VerifyProfileReport(/*active_profile_names*/ std::set<std::string>(),
profile_names, browser_report); profile_names, browser_report);
......
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