Commit a9fed76e authored by Owen Min's avatar Owen Min Committed by Commit Bot

Add plugin info into browser report.

This is the second half of moving plugins in enterprise report from
profile to browser.

1) Plugin information is put into basic request.
2) Basic request generation is async.
3) Full profile report is filled once the basic request is ready.

Bug: 956237
Change-Id: I1e5919f8f61bed4b17a548c9d6708fc7538dc7b2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1775139Reviewed-by: default avatarMarc-André Decoste <mad@chromium.org>
Commit-Queue: Owen Min <zmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#691632}
parent 6be8fcd6
......@@ -19,6 +19,8 @@
#include "components/policy/core/common/cloud/cloud_policy_util.h"
#include "components/version_info/channel.h"
#include "components/version_info/version_info.h"
#include "content/public/browser/plugin_service.h"
#include "content/public/common/webplugininfo.h"
#if defined(OS_WIN)
#include "base/win/wmi.h"
......@@ -48,22 +50,6 @@ void ReportGenerator::Generate(ReportCallback callback) {
DCHECK(!callback_);
callback_ = std::move(callback);
CreateBasicRequest();
if (basic_request_size_ > maximum_report_size_) {
// Basic request is already too large so we can't upload any valid report.
// Skip all Profiles and response an empty request list.
std::move(callback_).Run(std::move(requests_));
return;
}
requests_.push(
std::make_unique<em::ChromeDesktopReportRequest>(basic_request_));
for (int index = 0;
index < basic_request_.browser_report().chrome_user_profile_infos_size();
index++) {
GenerateProfileReportWithIndex(index);
}
std::move(callback_).Run(std::move(requests_));
}
void ReportGenerator::SetMaximumReportSizeForTesting(size_t size) {
......@@ -81,7 +67,8 @@ void ReportGenerator::CreateBasicRequest() {
->add_chrome_user_profile_infos()
->Swap(profile.get());
}
basic_request_size_ = basic_request_.ByteSizeLong();
content::PluginService::GetInstance()->GetPlugins(base::BindOnce(
&ReportGenerator::OnPluginsReady, weak_ptr_factory_.GetWeakPtr()));
}
std::unique_ptr<em::OSReport> ReportGenerator::GetOSReport() {
......@@ -171,4 +158,37 @@ void ReportGenerator::GenerateProfileReportWithIndex(int profile_index) {
// TODO(crbug.com/956237): Record this event with UMA metrics.
}
void ReportGenerator::OnPluginsReady(
const std::vector<content::WebPluginInfo>& plugins) {
auto* browser_report = basic_request_.mutable_browser_report();
for (auto plugin : plugins) {
auto* plugin_info = browser_report->add_plugins();
plugin_info->set_name(base::UTF16ToUTF8(plugin.name));
plugin_info->set_version(base::UTF16ToUTF8(plugin.version));
plugin_info->set_filename(plugin.path.BaseName().AsUTF8Unsafe());
plugin_info->set_description(base::UTF16ToUTF8(plugin.desc));
}
OnBasicRequestReady();
}
void ReportGenerator::OnBasicRequestReady() {
basic_request_size_ = basic_request_.ByteSizeLong();
if (basic_request_size_ > maximum_report_size_) {
// Basic request is already too large so we can't upload any valid report.
// Skip all Profiles and response an empty request list.
std::move(callback_).Run(std::move(requests_));
return;
}
requests_.push(
std::make_unique<em::ChromeDesktopReportRequest>(basic_request_));
for (int index = 0;
index < basic_request_.browser_report().chrome_user_profile_infos_size();
index++) {
GenerateProfileReportWithIndex(index);
}
std::move(callback_).Run(std::move(requests_));
}
} // namespace enterprise_reporting
......@@ -16,6 +16,10 @@
namespace em = enterprise_management;
namespace content {
struct WebPluginInfo;
}
namespace enterprise_reporting {
class ReportGenerator {
......@@ -59,6 +63,9 @@ class ReportGenerator {
private:
void GenerateProfileReportWithIndex(int profile_index);
void OnPluginsReady(const std::vector<content::WebPluginInfo>& plugins);
void OnBasicRequestReady();
ProfileReportGenerator profile_report_generator_;
ReportCallback callback_;
......
......@@ -17,6 +17,7 @@
#include "chrome/test/base/testing_profile_manager.h"
#include "components/account_id/account_id.h"
#include "content/public/browser/plugin_service.h"
#include "content/public/common/webplugininfo.h"
#include "content/public/test/browser_task_environment.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/extension_builder.h"
......@@ -30,6 +31,11 @@ namespace {
#if !defined(OS_CHROMEOS)
constexpr char kProfile[] = "Profile";
const char kPluginName[] = "plugin";
const char kPluginVersion[] = "1.0";
const char kPluginDescription[] = "This is a plugin.";
const char kPluginFileName[] = "file_name";
// We only upload serial number on Windows.
void VerifySerialNumber(const std::string& serial_number) {
#if defined(OS_WIN)
......@@ -121,6 +127,19 @@ class ReportGeneratorTest : public ::testing::Test {
return profile_names;
}
void CreatePlugin() {
content::WebPluginInfo info;
info.name = base::ASCIIToUTF16(kPluginName);
info.version = base::ASCIIToUTF16(kPluginVersion);
info.desc = base::ASCIIToUTF16(kPluginDescription);
info.path =
base::FilePath().AppendASCII("path").AppendASCII(kPluginFileName);
content::PluginService* plugin_service =
content::PluginService::GetInstance();
plugin_service->RegisterInternalPlugin(info, true);
plugin_service->RefreshPlugins();
}
std::vector<std::unique_ptr<em::ChromeDesktopReportRequest>>
GenerateRequests() {
base::RunLoop run_loop;
......@@ -185,6 +204,7 @@ class ReportGeneratorTest : public ::testing::Test {
TEST_F(ReportGeneratorTest, GenerateBasicReport) {
auto profile_names = CreateProfiles(/*number*/ 2, kIdle);
CreatePlugin();
auto requests = GenerateRequests();
EXPECT_EQ(1u, requests.size());
......@@ -205,6 +225,13 @@ TEST_F(ReportGeneratorTest, GenerateBasicReport) {
EXPECT_NE(std::string(), browser_report.browser_version());
EXPECT_NE(std::string(), browser_report.executable_path());
EXPECT_TRUE(browser_report.has_channel());
// There might be other plugins like PDF plugin, however, our fake plugin
// should be the first one in the report.
EXPECT_LE(1, browser_report.plugins_size());
EXPECT_EQ(kPluginName, browser_report.plugins(0).name());
EXPECT_EQ(kPluginVersion, browser_report.plugins(0).version());
EXPECT_EQ(kPluginDescription, browser_report.plugins(0).description());
EXPECT_EQ(kPluginFileName, browser_report.plugins(0).filename());
VerifyProfileReport(/*active_profile_names*/ std::set<std::string>(),
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