Commit a1fee262 authored by Guillaume Jenkins's avatar Guillaume Jenkins Committed by Commit Bot

[iOS CBCM]Add iOS CBCM skeleton

Hooks up the basic CBCM infrastructure to Bling initialization. CBCM
is disabled by default and requires the
"--enable-chrome-browser-cloud-management" command-line switch to be
enabled.

This basic skeleton does not yet implement any of the CBCM
functionality, even when the command-line switch is set. It only creates
the iOS classes needed for CBCM to function (except the reporting
delegates, which will be added later) and hooks up their lifecycle.

This also adds a simple EG test that launches Chrome with and without
the command-line switch and makes sure the browser can still be used
to navigate, which should catch any initialization issues in both the
enabled and disabled code paths.

Bug: 1066495
Change-Id: Ic939f45cd20878981a8d407576e79252ec778ada
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2331915
Commit-Queue: Guillaume Jenkins <gujen@google.com>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795109}
parent 506df871
......@@ -4,16 +4,24 @@
source_set("policy") {
sources = [
"browser_dm_token_storage_ios.h",
"browser_dm_token_storage_ios.mm",
"browser_policy_connector_ios.h",
"browser_policy_connector_ios.mm",
"browser_state_policy_connector.h",
"browser_state_policy_connector.mm",
"browser_state_policy_connector_factory.h",
"browser_state_policy_connector_factory.mm",
"chrome_browser_cloud_management_controller_ios.h",
"chrome_browser_cloud_management_controller_ios.mm",
"configuration_policy_handler_list_factory.h",
"configuration_policy_handler_list_factory.mm",
"device_management_service_configuration_ios.h",
"device_management_service_configuration_ios.mm",
"policy_conversions_client_ios.h",
"policy_conversions_client_ios.mm",
"reporting/reporting_delegate_factory_ios.h",
"reporting/reporting_delegate_factory_ios.mm",
"schema_registry_factory.h",
"schema_registry_factory.mm",
]
......@@ -33,6 +41,7 @@ source_set("policy") {
"//components/translate/core/browser:translate_pref_names",
"//components/variations",
"//components/variations/service",
"//components/version_info:version_info",
"//ios/chrome/browser",
"//ios/chrome/browser:pref_names",
"//ios/chrome/browser/browser_state",
......
// 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 IOS_CHROME_BROWSER_POLICY_BROWSER_DM_TOKEN_STORAGE_IOS_H_
#define IOS_CHROME_BROWSER_POLICY_BROWSER_DM_TOKEN_STORAGE_IOS_H_
#include "components/enterprise/browser/controller/browser_dm_token_storage.h"
#include <string>
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/sequence_checker.h"
#include "base/single_thread_task_runner.h"
namespace policy {
// Implementation of BrowserDMTokenStorage delegate for iOS.
class BrowserDMTokenStorageIOS : public BrowserDMTokenStorage::Delegate {
public:
BrowserDMTokenStorageIOS();
BrowserDMTokenStorageIOS(const BrowserDMTokenStorageIOS&) = delete;
BrowserDMTokenStorageIOS& operator=(const BrowserDMTokenStorageIOS&) = delete;
~BrowserDMTokenStorageIOS() override;
private:
// BrowserDMTokenStorage::Delegate implementation.
std::string InitClientId() override;
std::string InitEnrollmentToken() override;
std::string InitDMToken() override;
bool InitEnrollmentErrorOption() override;
BrowserDMTokenStorage::StoreTask SaveDMTokenTask(
const std::string& token,
const std::string& client_id) override;
scoped_refptr<base::TaskRunner> SaveDMTokenTaskRunner() override;
scoped_refptr<base::TaskRunner> task_runner_;
};
} // namespace policy
#endif // IOS_CHROME_BROWSER_POLICY_BROWSER_DM_TOKEN_STORAGE_IOS_H_
// 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.
#include "ios/chrome/browser/policy/browser_dm_token_storage_ios.h"
#include "base/base64url.h"
#include "base/files/file_util.h"
#include "base/files/important_file_writer.h"
#include "base/hash/sha1.h"
#include "base/path_service.h"
#include "base/task/post_task.h"
#include "base/task/thread_pool.h"
#include "ios/chrome/browser/file_metadata_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace policy {
namespace {
const char kDmTokenBaseDir[] =
FILE_PATH_LITERAL("Google/Chrome Cloud Enrollment/");
bool GetDmTokenFilePath(base::FilePath* token_file_path,
const std::string& client_id,
bool create_dir) {
if (!base::PathService::Get(base::DIR_APP_DATA, token_file_path))
return false;
*token_file_path = token_file_path->Append(kDmTokenBaseDir);
if (create_dir && !base::CreateDirectory(*token_file_path))
return false;
std::string filename;
base::Base64UrlEncode(base::SHA1HashString(client_id),
base::Base64UrlEncodePolicy::OMIT_PADDING, &filename);
*token_file_path = token_file_path->Append(filename.c_str());
return true;
}
bool StoreDMTokenInDirAppDataDir(const std::string& token,
const std::string& client_id) {
base::FilePath token_file_path;
if (!GetDmTokenFilePath(&token_file_path, client_id, true)) {
NOTREACHED();
return false;
}
if (!base::ImportantFileWriter::WriteFileAtomically(token_file_path, token)) {
return false;
}
SetSkipSystemBackupAttributeToItem(token_file_path, true);
return true;
}
} // namespace
BrowserDMTokenStorageIOS::BrowserDMTokenStorageIOS()
: task_runner_(base::ThreadPool::CreateTaskRunner({base::MayBlock()})) {}
BrowserDMTokenStorageIOS::~BrowserDMTokenStorageIOS() {}
std::string BrowserDMTokenStorageIOS::InitClientId() {
// TODO(crbug.com/1066495): Finish iOS CBCM implementation.
return "";
}
std::string BrowserDMTokenStorageIOS::InitEnrollmentToken() {
// TODO(crbug.com/1066495): Finish iOS CBCM implementation.
return "";
}
std::string BrowserDMTokenStorageIOS::InitDMToken() {
// TODO(crbug.com/1066495): Finish iOS CBCM implementation.
return "";
}
bool BrowserDMTokenStorageIOS::InitEnrollmentErrorOption() {
// No error should be shown if enrollment fails on iOS.
return false;
}
BrowserDMTokenStorage::StoreTask BrowserDMTokenStorageIOS::SaveDMTokenTask(
const std::string& token,
const std::string& client_id) {
return base::BindOnce(&StoreDMTokenInDirAppDataDir, token, client_id);
}
scoped_refptr<base::TaskRunner>
BrowserDMTokenStorageIOS::SaveDMTokenTaskRunner() {
return task_runner_;
}
} // namespace policy
......@@ -10,6 +10,7 @@
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "components/enterprise/browser/controller/chrome_browser_cloud_management_controller.h"
#include "components/policy/core/browser/browser_policy_connector.h"
namespace network {
......@@ -18,11 +19,17 @@ class SharedURLLoaderFactory;
namespace policy {
class ConfigurationPolicyProvider;
class ChromeBrowserCloudManagementController;
class MachineLevelUserCloudPolicyManager;
} // namespace policy
// Extends BrowserPolicyConnector with the setup for iOS builds.
class BrowserPolicyConnectorIOS : public policy::BrowserPolicyConnector {
public:
// Service initialization delay time in millisecond on startup. (So that
// displaying Chrome's GUI does not get delayed.)
static const int64_t kServiceInitializationStartupDelay = 5000;
BrowserPolicyConnectorIOS(
const policy::HandlerListFactory& handler_list_factory);
......@@ -33,12 +40,23 @@ class BrowserPolicyConnectorIOS : public policy::BrowserPolicyConnector {
// BrowserPolicyConnectorBase::SetPolicyProviderForTesting().
policy::ConfigurationPolicyProvider* GetPlatformProvider();
policy::ChromeBrowserCloudManagementController*
chrome_browser_cloud_management_controller() {
return chrome_browser_cloud_management_controller_.get();
}
policy::MachineLevelUserCloudPolicyManager*
machine_level_user_cloud_policy_manager() {
return machine_level_user_cloud_policy_manager_;
}
// BrowserPolicyConnector.
void Init(PrefService* local_state,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory)
override;
bool IsEnterpriseManaged() const override;
bool HasMachineLevelPolicies() override;
void Shutdown() override;
protected:
// BrowserPolicyConnectorBase.
......@@ -51,6 +69,11 @@ class BrowserPolicyConnectorIOS : public policy::BrowserPolicyConnector {
// Owned by base class.
policy::ConfigurationPolicyProvider* platform_provider_ = nullptr;
std::unique_ptr<policy::ChromeBrowserCloudManagementController>
chrome_browser_cloud_management_controller_;
policy::MachineLevelUserCloudPolicyManager*
machine_level_user_cloud_policy_manager_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(BrowserPolicyConnectorIOS);
};
......
......@@ -15,10 +15,14 @@
#include "base/system/sys_info.h"
#include "base/task/post_task.h"
#include "base/task/thread_pool.h"
#include "components/enterprise/browser/controller/chrome_browser_cloud_management_controller.h"
#include "components/policy/core/common/async_policy_provider.h"
#include "components/policy/core/common/cloud/device_management_service.h"
#include "components/policy/core/common/cloud/machine_level_user_cloud_policy_manager.h"
#include "components/policy/core/common/configuration_policy_provider.h"
#include "components/policy/core/common/policy_loader_ios.h"
#include "ios/chrome/browser/policy/chrome_browser_cloud_management_controller_ios.h"
#include "ios/chrome/browser/policy/device_management_service_configuration_ios.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
......@@ -35,7 +39,11 @@ using policy::PolicyLoaderIOS;
BrowserPolicyConnectorIOS::BrowserPolicyConnectorIOS(
const HandlerListFactory& handler_list_factory)
: BrowserPolicyConnector(handler_list_factory) {}
: BrowserPolicyConnector(handler_list_factory) {
chrome_browser_cloud_management_controller_ = std::make_unique<
policy::ChromeBrowserCloudManagementController>(
std::make_unique<policy::ChromeBrowserCloudManagementControllerIOS>());
}
BrowserPolicyConnectorIOS::~BrowserPolicyConnectorIOS() {}
......@@ -48,7 +56,16 @@ ConfigurationPolicyProvider* BrowserPolicyConnectorIOS::GetPlatformProvider() {
void BrowserPolicyConnectorIOS::Init(
PrefService* local_state,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) {
InitInternal(local_state, /*device_management_service=*/nullptr);
std::unique_ptr<policy::DeviceManagementService::Configuration> configuration(
new policy::DeviceManagementServiceConfigurationIOS(
BrowserPolicyConnector::GetDeviceManagementUrl(),
BrowserPolicyConnector::GetRealtimeReportingUrl()));
std::unique_ptr<policy::DeviceManagementService> device_management_service(
new policy::DeviceManagementService(std::move(configuration)));
device_management_service->ScheduleInitialization(
kServiceInitializationStartupDelay);
InitInternal(local_state, std::move(device_management_service));
}
bool BrowserPolicyConnectorIOS::IsEnterpriseManaged() const {
......@@ -57,7 +74,16 @@ bool BrowserPolicyConnectorIOS::IsEnterpriseManaged() const {
}
bool BrowserPolicyConnectorIOS::HasMachineLevelPolicies() {
return ProviderHasPolicies(GetPlatformProvider());
return ProviderHasPolicies(GetPlatformProvider()) ||
ProviderHasPolicies(machine_level_user_cloud_policy_manager_);
}
void BrowserPolicyConnectorIOS::Shutdown() {
// Reset the controller before calling base class so that
// shutdown occurs in correct sequence.
chrome_browser_cloud_management_controller_.reset();
BrowserPolicyConnector::Shutdown();
}
std::vector<std::unique_ptr<policy::ConfigurationPolicyProvider>>
......@@ -71,6 +97,17 @@ BrowserPolicyConnectorIOS::CreatePolicyProviders() {
// PlatformProvider should be before all other providers (highest priority).
providers.insert(providers.begin(), std::move(platform_provider));
}
std::unique_ptr<policy::MachineLevelUserCloudPolicyManager>
machine_level_user_cloud_policy_manager =
chrome_browser_cloud_management_controller_->CreatePolicyManager(
platform_provider_);
if (machine_level_user_cloud_policy_manager) {
machine_level_user_cloud_policy_manager_ =
machine_level_user_cloud_policy_manager.get();
providers.push_back(std::move(machine_level_user_cloud_policy_manager));
}
return providers;
}
......
// 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 IOS_CHROME_BROWSER_POLICY_CHROME_BROWSER_CLOUD_MANAGEMENT_CONTROLLER_IOS_H_
#define IOS_CHROME_BROWSER_POLICY_CHROME_BROWSER_CLOUD_MANAGEMENT_CONTROLLER_IOS_H_
#include "components/enterprise/browser/controller/chrome_browser_cloud_management_controller.h"
#include "ios/chrome/browser/policy/reporting/reporting_delegate_factory_ios.h"
namespace policy {
// iOS implementation of the platform-specific operations of CBCMController.
class ChromeBrowserCloudManagementControllerIOS
: public ChromeBrowserCloudManagementController::Delegate {
public:
ChromeBrowserCloudManagementControllerIOS();
ChromeBrowserCloudManagementControllerIOS(
const ChromeBrowserCloudManagementControllerIOS&) = delete;
ChromeBrowserCloudManagementControllerIOS& operator=(
const ChromeBrowserCloudManagementControllerIOS&) = delete;
~ChromeBrowserCloudManagementControllerIOS() override;
// ChromeBrowserCloudManagementController::Delegate implementation.
void SetDMTokenStorageDelegate() override;
bool IsEnabled() override;
int GetUserDataDirKey() override;
base::FilePath GetExternalPolicyPath() override;
NetworkConnectionTrackerGetter CreateNetworkConnectionTrackerGetter()
override;
void InitializeOAuthTokenFactory(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
PrefService* local_state) override;
void StartWatchingRegistration(
ChromeBrowserCloudManagementController* controller) override;
bool WaitUntilPolicyEnrollmentFinished() override;
bool IsEnterpriseStartupDialogShowing() override;
void OnServiceAccountSet(CloudPolicyClient* client,
const std::string& account_email) override;
void ShutDown() override;
MachineLevelUserCloudPolicyManager* GetMachineLevelUserCloudPolicyManager()
override;
DeviceManagementService* GetDeviceManagementService() override;
scoped_refptr<network::SharedURLLoaderFactory> GetSharedURLLoaderFactory()
override;
std::unique_ptr<enterprise_reporting::ReportScheduler> CreateReportScheduler(
CloudPolicyClient* client) override;
void SetGaiaURLLoaderFactory(scoped_refptr<network::SharedURLLoaderFactory>
url_loader_factory) override;
private:
enterprise_reporting::ReportingDelegateFactoryIOS reporting_delegate_factory_;
};
} // namespace policy
#endif // IOS_CHROME_BROWSER_POLICY_CHROME_BROWSER_CLOUD_MANAGEMENT_CONTROLLER_IOS_H_
// 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.
#include "ios/chrome/browser/policy/chrome_browser_cloud_management_controller_ios.h"
#include "base/bind.h"
#include "components/policy/core/common/cloud/machine_level_user_cloud_policy_manager.h"
#include "components/policy/core/common/features.h"
#include "ios/chrome/browser/application_context.h"
#include "ios/chrome/browser/chrome_paths.h"
#include "ios/chrome/browser/policy/browser_dm_token_storage_ios.h"
#include "ios/chrome/browser/policy/browser_policy_connector_ios.h"
#include "ios/chrome/browser/policy/policy_features.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace policy {
ChromeBrowserCloudManagementControllerIOS::
ChromeBrowserCloudManagementControllerIOS() = default;
ChromeBrowserCloudManagementControllerIOS::
~ChromeBrowserCloudManagementControllerIOS() = default;
void ChromeBrowserCloudManagementControllerIOS::SetDMTokenStorageDelegate() {
BrowserDMTokenStorage::SetDelegate(
std::make_unique<BrowserDMTokenStorageIOS>());
}
bool ChromeBrowserCloudManagementControllerIOS::IsEnabled() {
return IsChromeBrowserCloudManagementEnabled();
}
int ChromeBrowserCloudManagementControllerIOS::GetUserDataDirKey() {
return ios::DIR_USER_DATA;
}
base::FilePath
ChromeBrowserCloudManagementControllerIOS::GetExternalPolicyPath() {
// External policies are not supported on iOS.
return base::FilePath();
}
ChromeBrowserCloudManagementController::Delegate::NetworkConnectionTrackerGetter
ChromeBrowserCloudManagementControllerIOS::
CreateNetworkConnectionTrackerGetter() {
return base::BindRepeating(&ApplicationContext::GetNetworkConnectionTracker,
base::Unretained(GetApplicationContext()));
}
void ChromeBrowserCloudManagementControllerIOS::InitializeOAuthTokenFactory(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
PrefService* local_state) {
// Policy invalidations aren't currently supported on iOS.
}
void ChromeBrowserCloudManagementControllerIOS::StartWatchingRegistration(
ChromeBrowserCloudManagementController* controller) {
// Enrollment isn't blocking or mandatory on iOS.
}
bool ChromeBrowserCloudManagementControllerIOS::
WaitUntilPolicyEnrollmentFinished() {
// Enrollment currently isn't blocking or mandatory on iOS, so this method
// isn't used. Always report success.
return true;
}
bool ChromeBrowserCloudManagementControllerIOS::
IsEnterpriseStartupDialogShowing() {
// There is no enterprise startup dialog on iOS.
return false;
}
void ChromeBrowserCloudManagementControllerIOS::OnServiceAccountSet(
CloudPolicyClient* client,
const std::string& account_email) {
// Policy invalidations aren't currently supported on iOS.
}
void ChromeBrowserCloudManagementControllerIOS::ShutDown() {
// No additional shutdown to perform on iOS.
}
MachineLevelUserCloudPolicyManager* ChromeBrowserCloudManagementControllerIOS::
GetMachineLevelUserCloudPolicyManager() {
return GetApplicationContext()
->GetBrowserPolicyConnector()
->machine_level_user_cloud_policy_manager();
}
DeviceManagementService*
ChromeBrowserCloudManagementControllerIOS::GetDeviceManagementService() {
return GetApplicationContext()
->GetBrowserPolicyConnector()
->device_management_service();
}
scoped_refptr<network::SharedURLLoaderFactory>
ChromeBrowserCloudManagementControllerIOS::GetSharedURLLoaderFactory() {
return GetApplicationContext()->GetSharedURLLoaderFactory();
}
std::unique_ptr<enterprise_reporting::ReportScheduler>
ChromeBrowserCloudManagementControllerIOS::CreateReportScheduler(
CloudPolicyClient* client) {
auto generator = std::make_unique<enterprise_reporting::ReportGenerator>(
&reporting_delegate_factory_);
return std::make_unique<enterprise_reporting::ReportScheduler>(
client, std::move(generator), &reporting_delegate_factory_);
}
void ChromeBrowserCloudManagementControllerIOS::SetGaiaURLLoaderFactory(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) {
// Policy invalidations aren't currently supported on iOS.
}
} // namespace policy
\ No newline at end of file
// 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 IOS_CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_SERVICE_CONFIGURATION_IOS_H_
#define IOS_CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_SERVICE_CONFIGURATION_IOS_H_
#include <string>
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "components/policy/core/common/cloud/device_management_service.h"
namespace policy {
// The iOS implementation of the device management service configuration that is
// used to create device management service instances.
class DeviceManagementServiceConfigurationIOS
: public DeviceManagementService::Configuration {
public:
DeviceManagementServiceConfigurationIOS(
const std::string& server_url,
const std::string& reporting_server_url);
DeviceManagementServiceConfigurationIOS(
const DeviceManagementServiceConfigurationIOS&) = delete;
DeviceManagementServiceConfigurationIOS& operator=(
const DeviceManagementServiceConfigurationIOS&) = delete;
~DeviceManagementServiceConfigurationIOS() override;
// DeviceManagementService::Configuration implementation.
std::string GetDMServerUrl() override;
std::string GetAgentParameter() override;
std::string GetPlatformParameter() override;
std::string GetReportingServerUrl() override;
std::string GetReportingConnectorServerUrl() override;
private:
const std::string server_url_;
const std::string reporting_server_url_;
};
} // namespace policy
#endif // IOS_CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_SERVICE_CONFIGURATION_IOS_H_
// 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.
#include "ios/chrome/browser/policy/device_management_service_configuration_ios.h"
#include <stdint.h>
#include "base/logging.h"
#include "base/strings/stringprintf.h"
#include "base/system/sys_info.h"
#include "build/build_config.h"
#include "components/policy/core/browser/browser_policy_connector.h"
#include "components/version_info/version_info.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace policy {
DeviceManagementServiceConfigurationIOS::
DeviceManagementServiceConfigurationIOS(
const std::string& server_url,
const std::string& reporting_server_url)
: server_url_(server_url), reporting_server_url_(reporting_server_url) {}
DeviceManagementServiceConfigurationIOS::
~DeviceManagementServiceConfigurationIOS() = default;
std::string DeviceManagementServiceConfigurationIOS::GetDMServerUrl() {
return server_url_;
}
std::string DeviceManagementServiceConfigurationIOS::GetAgentParameter() {
return base::StringPrintf("%s %s(%s)", version_info::GetProductName().c_str(),
version_info::GetVersionNumber().c_str(),
version_info::GetLastChange().c_str());
}
std::string DeviceManagementServiceConfigurationIOS::GetPlatformParameter() {
std::string os_name = base::SysInfo::OperatingSystemName();
std::string os_hardware = base::SysInfo::OperatingSystemArchitecture();
std::string os_version("-");
int32_t os_major_version = 0;
int32_t os_minor_version = 0;
int32_t os_bugfix_version = 0;
base::SysInfo::OperatingSystemVersionNumbers(
&os_major_version, &os_minor_version, &os_bugfix_version);
os_version = base::StringPrintf("%d.%d.%d", os_major_version,
os_minor_version, os_bugfix_version);
return base::StringPrintf("%s|%s|%s", os_name.c_str(), os_hardware.c_str(),
os_version.c_str());
}
std::string DeviceManagementServiceConfigurationIOS::GetReportingServerUrl() {
return reporting_server_url_;
}
std::string
DeviceManagementServiceConfigurationIOS::GetReportingConnectorServerUrl() {
return std::string();
}
} // namespace policy
......@@ -40,7 +40,8 @@ std::unique_ptr<base::Value> GetPlatformPolicy(const std::string& key) {
// |policy_data| must be in XML format. |policy_data| is passed to the
// application regardless of whether |disable_policy| is true or false..
AppLaunchConfiguration GenerateAppLaunchConfiguration(std::string policy_data,
bool disable_policy) {
bool disable_policy,
bool enable_cbcm) {
AppLaunchConfiguration config;
if (disable_policy) {
......@@ -51,6 +52,11 @@ AppLaunchConfiguration GenerateAppLaunchConfiguration(std::string policy_data,
switches::kEnableEnterprisePolicy);
}
if (enable_cbcm) {
config.additional_args.push_back(
std::string("--") + switches::kEnableChromeBrowserCloudManagement);
}
// Remove whitespace from the policy data, because the XML parser does not
// tolerate newlines.
base::RemoveChars(policy_data, base::kWhitespaceASCII, &policy_data);
......@@ -90,7 +96,8 @@ AppLaunchConfiguration GenerateAppLaunchConfiguration(std::string policy_data,
" <key>SearchSuggestEnabled</key>"
" <false/>"
"</dict>";
return GenerateAppLaunchConfiguration(policyData, /*disable_policy=*/false);
return GenerateAppLaunchConfiguration(policyData, /*disable_policy=*/false,
/*enable_cbcm*/ false);
}
// Tests the values of policies that were explicitly set.
......@@ -148,7 +155,8 @@ AppLaunchConfiguration GenerateAppLaunchConfiguration(std::string policy_data,
" <key>DefaultSearchProviderName</key>"
" <string>Test</string>"
"</dict>";
return GenerateAppLaunchConfiguration(policyData, /*disable_policy=*/true);
return GenerateAppLaunchConfiguration(policyData, /*disable_policy=*/true,
/*enable_cbcm*/ false);
}
// Tests that about:policy is not available when policy is disabled. Also serves
......@@ -169,3 +177,67 @@ AppLaunchConfiguration GenerateAppLaunchConfiguration(std::string policy_data,
}
@end
// Test case that enables CBCM.
@interface CBCMEnabledTestCase : ChromeTestCase
@end
@implementation CBCMEnabledTestCase
- (AppLaunchConfiguration)appConfigurationForTestCase {
std::string policyData = "<dict>"
" <key>SearchSuggestEnabled</key>"
" <false/>"
"</dict>";
return GenerateAppLaunchConfiguration(policyData, /*disable_policy=*/false,
/*enable_cbcm=*/true);
}
// Ensure that policies can still be correctly set, and that the browser is
// working normally by visiting the about:policy page.
- (void)testPoliciesWork {
std::unique_ptr<base::Value> suggestValue =
GetPlatformPolicy(policy::key::kSearchSuggestEnabled);
GREYAssertTrue(suggestValue && suggestValue->is_bool(),
@"suggestValue was not of type bool");
GREYAssertFalse(suggestValue->GetBool(),
@"suggestValue had an unexpected value");
[ChromeEarlGrey loadURL:GURL("chrome://policy")];
[ChromeEarlGrey waitForWebStateContainingText:l10n_util::GetStringUTF8(
IDS_POLICY_SHOW_UNSET)];
}
@end
// Test case that disables CBCM.
@interface CBCMDisabledTestCase : ChromeTestCase
@end
@implementation CBCMDisabledTestCase
- (AppLaunchConfiguration)appConfigurationForTestCase {
std::string policyData = "<dict>"
" <key>SearchSuggestEnabled</key>"
" <false/>"
"</dict>";
return GenerateAppLaunchConfiguration(policyData, /*disable_policy=*/false,
/*enable_cbcm=*/false);
}
// Ensure that policies can still be correctly set, and that the browser is
// working normally by visiting the about:policy page.
- (void)testPoliciesWork {
std::unique_ptr<base::Value> suggestValue =
GetPlatformPolicy(policy::key::kSearchSuggestEnabled);
GREYAssertTrue(suggestValue && suggestValue->is_bool(),
@"suggestValue was not of type bool");
GREYAssertFalse(suggestValue->GetBool(),
@"suggestValue had an unexpected value");
[ChromeEarlGrey loadURL:GURL("chrome://policy")];
[ChromeEarlGrey waitForWebStateContainingText:l10n_util::GetStringUTF8(
IDS_POLICY_SHOW_UNSET)];
}
@end
// 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 IOS_CHROME_BROWSER_POLICY_REPORTING_REPORTING_DELEGATE_FACTORY_IOS_H_
#define IOS_CHROME_BROWSER_POLICY_REPORTING_REPORTING_DELEGATE_FACTORY_IOS_H_
#include "components/enterprise/browser/reporting/reporting_delegate_factory.h"
#include <memory>
#include "components/enterprise/browser/reporting/browser_report_generator.h"
#include "components/enterprise/browser/reporting/profile_report_generator.h"
#include "components/enterprise/browser/reporting/report_generator.h"
#include "components/enterprise/browser/reporting/report_scheduler.h"
namespace enterprise_reporting {
// iOS implementation of the reporting delegate factory. Creates iOS-specific
// delegates for the enterprise reporting classes.
class ReportingDelegateFactoryIOS : public ReportingDelegateFactory {
public:
ReportingDelegateFactoryIOS() = default;
ReportingDelegateFactoryIOS(const ReportingDelegateFactoryIOS&) = delete;
ReportingDelegateFactoryIOS& operator=(const ReportingDelegateFactoryIOS&) =
delete;
~ReportingDelegateFactoryIOS() override = default;
std::unique_ptr<BrowserReportGenerator::Delegate>
GetBrowserReportGeneratorDelegate() override;
std::unique_ptr<ProfileReportGenerator::Delegate>
GetProfileReportGeneratorDelegate() override;
std::unique_ptr<ReportGenerator::Delegate> GetReportGeneratorDelegate()
override;
std::unique_ptr<ReportScheduler::Delegate> GetReportSchedulerDelegate()
override;
};
} // namespace enterprise_reporting
#endif // IOS_CHROME_BROWSER_POLICY_REPORTING_REPORTING_DELEGATE_FACTORY_IOS_H_
// 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.
#include "ios/chrome/browser/policy/reporting/reporting_delegate_factory_ios.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace enterprise_reporting {
std::unique_ptr<BrowserReportGenerator::Delegate>
ReportingDelegateFactoryIOS::GetBrowserReportGeneratorDelegate() {
// TODO(crbug.com/1066495): Finish iOS CBCM implementation.
return nullptr;
}
std::unique_ptr<ProfileReportGenerator::Delegate>
ReportingDelegateFactoryIOS::GetProfileReportGeneratorDelegate() {
// TODO(crbug.com/1066495): Finish iOS CBCM implementation.
return nullptr;
}
std::unique_ptr<ReportGenerator::Delegate>
ReportingDelegateFactoryIOS::GetReportGeneratorDelegate() {
// TODO(crbug.com/1066495): Finish iOS CBCM implementation.
return nullptr;
}
std::unique_ptr<ReportScheduler::Delegate>
ReportingDelegateFactoryIOS::GetReportSchedulerDelegate() {
// TODO(crbug.com/1066495): Finish iOS CBCM implementation.
return nullptr;
}
} // namespace enterprise_reporting
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