Commit 4abc8a5c authored by Dominique Fauteux-Chapleau's avatar Dominique Fauteux-Chapleau Committed by Commit Bot

Migrate EnterpriseReportingPrivateApi to new DM token class.

Migrates RetrieveDMToken calls to use the new BrowserDMToken class and
change the class member from a string to this class.

Also add a few includes the linter warns about.

Bug: 1020296
Change-Id: I6754c373cc34c1b3ca25da81847793ab199cddb0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1903952
Commit-Queue: Dominique Fauteux-Chapleau <domfc@chromium.org>
Reviewed-by: default avatarTien Mai <tienmai@chromium.org>
Reviewed-by: default avatarOwen Min <zmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713814}
parent c9d11ae0
......@@ -5,6 +5,8 @@
#include "chrome/browser/extensions/api/enterprise_reporting_private/enterprise_reporting_private_api.h"
#include <memory>
#include <utility>
#include <vector>
#include "base/bind.h"
#include "base/json/json_writer.h"
......@@ -51,7 +53,9 @@ EnterpriseReportingPrivateUploadChromeDesktopReportFunction::
EnterpriseReportingPrivateUploadChromeDesktopReportFunction::
EnterpriseReportingPrivateUploadChromeDesktopReportFunction(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) {
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory)
: dm_token_(
policy::BrowserDMTokenStorage::BrowserDMToken::CreateEmptyToken()) {
policy::DeviceManagementService* device_management_service =
g_browser_process->browser_policy_connector()
->device_management_service();
......@@ -66,7 +70,7 @@ EnterpriseReportingPrivateUploadChromeDesktopReportFunction::
std::string() /* manufacture_date */, device_management_service,
std::move(url_loader_factory), nullptr,
policy::CloudPolicyClient::DeviceDMTokenCallback());
dm_token_ = policy::BrowserDMTokenStorage::Get()->RetrieveDMToken();
dm_token_ = policy::BrowserDMTokenStorage::Get()->RetrieveBrowserDMToken();
client_id_ = policy::BrowserDMTokenStorage::Get()->RetrieveClientId();
}
......@@ -85,7 +89,7 @@ ExtensionFunction::ResponseAction
EnterpriseReportingPrivateUploadChromeDesktopReportFunction::Run() {
VLOG(1) << "Uploading enterprise report";
if (dm_token_.empty() || client_id_.empty()) {
if (!dm_token_.is_valid() || client_id_.empty()) {
LogReportError("Device is not enrolled.");
return RespondNow(Error(enterprise_reporting::kDeviceNotEnrolled));
}
......@@ -104,7 +108,7 @@ EnterpriseReportingPrivateUploadChromeDesktopReportFunction::Run() {
}
if (!cloud_policy_client_->is_registered())
cloud_policy_client_->SetupRegistration(dm_token_, client_id_,
cloud_policy_client_->SetupRegistration(dm_token_.value(), client_id_,
std::vector<std::string>());
cloud_policy_client_->UploadChromeDesktopReport(
......@@ -123,8 +127,9 @@ void EnterpriseReportingPrivateUploadChromeDesktopReportFunction::
}
void EnterpriseReportingPrivateUploadChromeDesktopReportFunction::
SetRegistrationInfoForTesting(const std::string& dm_token,
const std::string& client_id) {
SetRegistrationInfoForTesting(
const policy::BrowserDMTokenStorage::BrowserDMToken& dm_token,
const std::string& client_id) {
dm_token_ = dm_token;
client_id_ = client_id;
}
......
......@@ -5,7 +5,11 @@
#ifndef CHROME_BROWSER_EXTENSIONS_API_ENTERPRISE_REPORTING_PRIVATE_ENTERPRISE_REPORTING_PRIVATE_API_H_
#define CHROME_BROWSER_EXTENSIONS_API_ENTERPRISE_REPORTING_PRIVATE_ENTERPRISE_REPORTING_PRIVATE_API_H_
#include <memory>
#include <string>
#include "base/memory/ref_counted.h"
#include "chrome/browser/policy/browser_dm_token_storage.h"
#include "extensions/browser/extension_function.h"
namespace policy {
......@@ -39,8 +43,9 @@ class EnterpriseReportingPrivateUploadChromeDesktopReportFunction
void SetCloudPolicyClientForTesting(
std::unique_ptr<policy::CloudPolicyClient> client);
void SetRegistrationInfoForTesting(const std::string& dm_token,
const std::string& client_id);
void SetRegistrationInfoForTesting(
const policy::BrowserDMTokenStorage::BrowserDMToken& dm_token,
const std::string& client_id);
// Used by tests that want to overrode the URLLoaderFactory used to simulate
// network requests.
......@@ -58,7 +63,7 @@ class EnterpriseReportingPrivateUploadChromeDesktopReportFunction
void OnReportUploaded(bool status);
std::unique_ptr<policy::CloudPolicyClient> cloud_policy_client_;
std::string dm_token_;
policy::BrowserDMTokenStorage::BrowserDMToken dm_token_;
std::string client_id_;
DISALLOW_COPY_AND_ASSIGN(
......
......@@ -43,7 +43,16 @@ class EnterpriseReportingPrivateUploadChromeDesktopReportTest
test_url_loader_factory_.GetSafeWeakWrapper());
client_ = client.get();
function->SetCloudPolicyClientForTesting(std::move(client));
function->SetRegistrationInfoForTesting(dm_token, kFakeClientId);
if (dm_token.empty()) {
function->SetRegistrationInfoForTesting(
policy::BrowserDMTokenStorage::BrowserDMToken::CreateEmptyToken(),
kFakeClientId);
} else {
function->SetRegistrationInfoForTesting(
policy::BrowserDMTokenStorage::BrowserDMToken::CreateValidToken(
dm_token),
kFakeClientId);
}
return function;
}
......
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