Commit 02a9cb76 authored by Tim Song's avatar Tim Song Committed by Commit Bot

Introduce chrome.enterprise.reportingPrivate.getDeviceInfo() API.

This is a private API for getting the device state for enterprise reporting.
This CL uses a stub implementation for now. Platform-specific implementations
will be added in future CLs.

TEST=manual + unit test with stub
BUG=996079

Change-Id: I2bb1d6035c11dea530058582b51835197b8da462
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1846754
Commit-Queue: Tim Song <tengs@chromium.org>
Reviewed-by: default avatarKaran Bhatia <karandeepb@chromium.org>
Reviewed-by: default avatarGustavo Sacomoto <sacomoto@chromium.org>
Reviewed-by: default avatarOwen Min <zmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#721854}
parent b6493fbb
......@@ -1028,6 +1028,8 @@ jumbo_static_library("extensions") {
sources += [
"api/enterprise_reporting_private/chrome_desktop_report_request_helper.cc",
"api/enterprise_reporting_private/chrome_desktop_report_request_helper.h",
"api/enterprise_reporting_private/device_info_fetcher.cc",
"api/enterprise_reporting_private/device_info_fetcher.h",
"api/enterprise_reporting_private/enterprise_reporting_private_api.cc",
"api/enterprise_reporting_private/enterprise_reporting_private_api.h",
"api/enterprise_reporting_private/prefs.cc",
......
// Copyright 2019 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.
#include "chrome/browser/extensions/api/enterprise_reporting_private/device_info_fetcher.h"
#include "base/logging.h"
namespace extensions {
namespace enterprise_reporting {
namespace {
// Stub implementation of DeviceInfoFetcher.
class StubDeviceFetcher : public DeviceInfoFetcher {
public:
StubDeviceFetcher() {}
~StubDeviceFetcher() override = default;
DeviceInfo Fetch() override {
DeviceInfo device_info;
device_info.os_name = "stubOS";
device_info.os_version = "0.0.0.0";
device_info.device_host_name = "midnightshift";
device_info.device_model = "topshot";
device_info.serial_number = "twirlchange";
device_info.screen_lock_secured =
::extensions::api::enterprise_reporting_private::SETTING_VALUE_ENABLED;
device_info.disk_encrypted =
::extensions::api::enterprise_reporting_private::SETTING_VALUE_DISABLED;
return device_info;
}
private:
DISALLOW_COPY_AND_ASSIGN(StubDeviceFetcher);
};
} // namespace
DeviceInfoFetcher::DeviceInfoFetcher() {}
DeviceInfoFetcher::~DeviceInfoFetcher() = default;
std::unique_ptr<DeviceInfoFetcher> DeviceInfoFetcher::CreateInstance() {
// TODO(996079): Return a stub implementation for now. We will add
// platform-specific implementations in follow-up CLs.
return std::make_unique<StubDeviceFetcher>();
}
} // namespace enterprise_reporting
} // namespace extensions
// Copyright 2019 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 CHROME_BROWSER_EXTENSIONS_API_ENTERPRISE_REPORTING_PRIVATE_DEVICE_INFO_FETCHER_H_
#define CHROME_BROWSER_EXTENSIONS_API_ENTERPRISE_REPORTING_PRIVATE_DEVICE_INFO_FETCHER_H_
#include "base/macros.h"
#include "base/values.h"
#include "chrome/common/extensions/api/enterprise_reporting_private.h"
namespace extensions {
namespace enterprise_reporting {
using DeviceInfo = ::extensions::api::enterprise_reporting_private::DeviceInfo;
// Interface used by the chrome.enterprise.reportingPrivate.getDeviceInfo()
// function that fetches info of the device. Each supported platform has its own
// subclass implementation.
class DeviceInfoFetcher {
public:
DeviceInfoFetcher();
virtual ~DeviceInfoFetcher();
// Returns a platform specific instance of DeviceInfoFetcher.
static std::unique_ptr<DeviceInfoFetcher> CreateInstance();
// Fetches the device information for the current platform.
virtual DeviceInfo Fetch() = 0;
private:
DISALLOW_COPY_AND_ASSIGN(DeviceInfoFetcher);
};
} // namespace enterprise_reporting
} // namespace extensions
#endif // CHROME_BROWSER_EXTENSIONS_API_ENTERPRISE_REPORTING_PRIVATE_DEVICE_INFO_FETCHER_H_
......@@ -15,6 +15,7 @@
#include "base/values.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/api/enterprise_reporting_private/chrome_desktop_report_request_helper.h"
#include "chrome/browser/extensions/api/enterprise_reporting_private/device_info_fetcher.h"
#include "chrome/browser/net/system_network_context_manager.h"
#include "chrome/browser/policy/browser_dm_token_storage.h"
#include "chrome/browser/policy/chrome_browser_policy_connector.h"
......@@ -282,4 +283,19 @@ void EnterpriseReportingPrivateSetDeviceDataFunction::OnDataStored(
}
}
// getDeviceInfo
EnterpriseReportingPrivateGetDeviceInfoFunction::
EnterpriseReportingPrivateGetDeviceInfoFunction() = default;
ExtensionFunction::ResponseAction
EnterpriseReportingPrivateGetDeviceInfoFunction::Run() {
enterprise_reporting::DeviceInfo device_info =
enterprise_reporting::DeviceInfoFetcher::CreateInstance()->Fetch();
return RespondNow(OneArgument(device_info.ToValue()));
}
EnterpriseReportingPrivateGetDeviceInfoFunction::
~EnterpriseReportingPrivateGetDeviceInfoFunction() = default;
} // namespace extensions
......@@ -145,6 +145,22 @@ class EnterpriseReportingPrivateSetDeviceDataFunction
DISALLOW_COPY_AND_ASSIGN(EnterpriseReportingPrivateSetDeviceDataFunction);
};
class EnterpriseReportingPrivateGetDeviceInfoFunction
: public ExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("enterprise.reportingPrivate.getDeviceInfo",
ENTERPRISEREPORTINGPRIVATE_GETDEVICEINFO)
EnterpriseReportingPrivateGetDeviceInfoFunction();
// ExtensionFunction
ExtensionFunction::ResponseAction Run() override;
private:
~EnterpriseReportingPrivateGetDeviceInfoFunction() override;
DISALLOW_COPY_AND_ASSIGN(EnterpriseReportingPrivateGetDeviceInfoFunction);
};
} // namespace extensions
#endif // CHROME_BROWSER_EXTENSIONS_API_ENTERPRISE_REPORTING_PRIVATE_ENTERPRISE_REPORTING_PRIVATE_API_H_
......@@ -13,6 +13,7 @@
#include "chrome/browser/extensions/extension_api_unittest.h"
#include "chrome/browser/extensions/extension_function_test_utils.h"
#include "chrome/browser/policy/fake_browser_dm_token_storage.h"
#include "chrome/common/extensions/api/enterprise_reporting_private.h"
#include "components/policy/core/common/cloud/mock_cloud_policy_client.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_url_loader_factory.h"
......@@ -26,6 +27,9 @@ using ::testing::_;
using ::testing::Invoke;
using ::testing::WithArgs;
namespace enterprise_reporting_private =
::extensions::api::enterprise_reporting_private;
namespace extensions {
namespace {
......@@ -287,4 +291,28 @@ TEST_F(EnterpriseReportingPrivateGetPersistentSecretFunctionTest, GetSecret) {
#endif // defined(OS_WIN)
using EnterpriseReportingPrivateGetDeviceInfoTest = ExtensionApiUnittest;
TEST_F(EnterpriseReportingPrivateGetDeviceInfoTest, GetDeviceInfoStub) {
auto function =
base::MakeRefCounted<EnterpriseReportingPrivateGetDeviceInfoFunction>();
std::unique_ptr<base::Value> device_info_value =
RunFunctionAndReturnValue(function.get(), "[]");
ASSERT_TRUE(device_info_value.get());
enterprise_reporting_private::DeviceInfo info;
ASSERT_TRUE(enterprise_reporting_private::DeviceInfo::Populate(
*device_info_value, &info));
EXPECT_EQ("stubOS", info.os_name);
EXPECT_EQ("0.0.0.0", info.os_version);
EXPECT_EQ("midnightshift", info.device_host_name);
EXPECT_EQ("topshot", info.device_model);
EXPECT_EQ("twirlchange", info.serial_number);
EXPECT_EQ(enterprise_reporting_private::SETTING_VALUE_ENABLED,
info.screen_lock_secured);
EXPECT_EQ(enterprise_reporting_private::SETTING_VALUE_DISABLED,
info.disk_encrypted);
}
} // namespace extensions
......@@ -19,6 +19,23 @@ namespace enterprise.reportingPrivate {
// Invokde by <code>getDeviceDataCallback</code> to return the device data.
callback GetDeviceDataCallback = void(ArrayBuffer data);
// Possible states a particular device setting can be in.
enum SettingValue { UNKNOWN, DISABLED, ENABLED };
// Device info fields returned by the getDeviceInfo API.
dictionary DeviceInfo {
DOMString osName;
DOMString osVersion;
DOMString deviceHostName;
DOMString deviceModel;
DOMString serialNumber;
SettingValue screenLockSecured;
SettingValue diskEncrypted;
};
// Invoked by <code>getDeviceInfo</code> to return device information.
callback GetDeviceInfoCallback = void(DeviceInfo deviceInfo);
interface Functions {
// Uploads the status of Chrome browser to the admin console by sending
......@@ -43,6 +60,9 @@ namespace enterprise.reportingPrivate {
ArrayBuffer data,
optional DoneCallback callback);
// Gets the device information (including disk encryption status,
// screen lock status, serial number, model).
static void getDeviceInfo(optional GetDeviceInfoCallback callback);
};
};
......@@ -1484,6 +1484,7 @@ enum HistogramValue {
ENTERPRISEREPORTINGPRIVATE_GETPERSISTENTSECRET = 1421,
ENTERPRISEREPORTINGPRIVATE_GETDEVICEDATA = 1422,
ENTERPRISEREPORTINGPRIVATE_SETDEVICEDATA = 1423,
ENTERPRISEREPORTINGPRIVATE_GETDEVICEINFO = 1424,
// Last entry: Add new entries above, then run:
// python tools/metrics/histograms/update_extension_histograms.py
ENUM_BOUNDARY
......
......@@ -21480,6 +21480,7 @@ Called by update_net_error_codes.py.-->
<int value="1421" label="ENTERPRISEREPORTINGPRIVATE_GETPERSISTENTSECRET"/>
<int value="1422" label="ENTERPRISEREPORTINGPRIVATE_GETDEVICEDATA"/>
<int value="1423" label="ENTERPRISEREPORTINGPRIVATE_SETDEVICEDATA"/>
<int value="1424" label="ENTERPRISEREPORTINGPRIVATE_GETDEVICEINFO"/>
</enum>
<enum name="ExtensionIconState">
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