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

[iOS CBCM] Add support for enterprise reporting

Creates and implements the missing delegates for enterprise reporting
on iOS.

Note that this won't be functional yet because of an issue with the
way ApplicationContext instantiates its shared URLLoaderFactory. That
issue will be fixed in a separate CL.

#Squeegee

Bug: 1066495
Change-Id: Idb493efeca63bb19eaf250ede02608f6bd842a81
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2341995
Commit-Queue: Guillaume Jenkins <gujen@google.com>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Reviewed-by: default avatarOwen Min <zmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797290}
parent 64deb9a9
......@@ -111,6 +111,11 @@ void AppendChromePolicyInfoIntoProfileReport(
void AppendExtensionPolicyInfoIntoProfileReport(
const base::Value& policies,
em::ChromeUserProfileInfo* profile_info) {
if (!policies.FindKey("extensionPolicies")) {
// Android and iOS don't support extensions and their policies.
return;
}
for (const auto& extension_iter :
policies.FindKey("extensionPolicies")->DictItems()) {
const base::Value& policies = extension_iter.second;
......
......@@ -61,6 +61,7 @@ include_rules = [
"+components/policy/core/browser",
"+components/policy/core/common",
"+components/policy/policy_constants.h",
"+components/policy/proto/device_management_backend.pb.h",
"+components/pref_registry",
"+components/prefs",
"+components/profile_metrics",
......
......@@ -20,6 +20,14 @@ source_set("policy") {
"device_management_service_configuration_ios.mm",
"policy_conversions_client_ios.h",
"policy_conversions_client_ios.mm",
"reporting/browser_report_generator_ios.h",
"reporting/browser_report_generator_ios.mm",
"reporting/profile_report_generator_ios.h",
"reporting/profile_report_generator_ios.mm",
"reporting/report_generator_ios.h",
"reporting/report_generator_ios.mm",
"reporting/report_scheduler_ios.h",
"reporting/report_scheduler_ios.mm",
"reporting/reporting_delegate_factory_ios.h",
"reporting/reporting_delegate_factory_ios.mm",
"schema_registry_factory.h",
......@@ -35,6 +43,7 @@ source_set("policy") {
"//components/password_manager/core/common",
"//components/policy:generated",
"//components/policy/core/common",
"//components/policy/proto",
"//components/safe_browsing/core/common:safe_browsing_policy_handler",
"//components/safe_browsing/core/common:safe_browsing_prefs",
"//components/search_engines",
......@@ -45,6 +54,9 @@ source_set("policy") {
"//ios/chrome/browser",
"//ios/chrome/browser:pref_names",
"//ios/chrome/browser/browser_state",
"//ios/chrome/browser/signin",
"//ios/chrome/common",
"//ios/public/provider/chrome/browser/signin",
"//services/network/public/cpp",
]
......
......@@ -5,6 +5,8 @@
#include "ios/chrome/browser/policy/chrome_browser_cloud_management_controller_ios.h"
#include "base/bind.h"
#include "components/enterprise/browser/reporting/report_generator.h"
#include "components/enterprise/browser/reporting/report_scheduler.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"
......@@ -107,8 +109,10 @@ ChromeBrowserCloudManagementControllerIOS::GetSharedURLLoaderFactory() {
std::unique_ptr<enterprise_reporting::ReportScheduler>
ChromeBrowserCloudManagementControllerIOS::CreateReportScheduler(
CloudPolicyClient* client) {
// TODO(crbug.com/1066495): Finish iOS CBCM implementation.
return nullptr;
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(
......
// 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_BROWSER_REPORT_GENERATOR_IOS_H_
#define IOS_CHROME_BROWSER_POLICY_REPORTING_BROWSER_REPORT_GENERATOR_IOS_H_
#include "components/enterprise/browser/reporting/browser_report_generator.h"
#include <memory>
#include "base/callback.h"
#include "components/policy/proto/device_management_backend.pb.h"
#include "components/version_info/channel.h"
namespace em = ::enterprise_management;
namespace enterprise_reporting {
// iOS implementation of platform-specific info fetching for Enterprise browser
// report generation.
class BrowserReportGeneratorIOS : public BrowserReportGenerator::Delegate {
public:
using ReportCallback = base::OnceCallback<void(
std::unique_ptr<enterprise_management::BrowserReport>)>;
BrowserReportGeneratorIOS();
BrowserReportGeneratorIOS(const BrowserReportGeneratorIOS&) = delete;
BrowserReportGeneratorIOS& operator=(const BrowserReportGeneratorIOS&) =
delete;
~BrowserReportGeneratorIOS() override;
// BrowserReportGenerator::Delegate implementation.
std::string GetExecutablePath() override;
version_info::Channel GetChannel() override;
void GenerateBuildStateInfo(em::BrowserReport* report) override;
void GenerateProfileInfo(em::BrowserReport* report) override;
void GeneratePluginsIfNeeded(
ReportCallback callback,
std::unique_ptr<em::BrowserReport> report) override;
};
} // namespace enterprise_reporting
#endif // IOS_CHROME_BROWSER_POLICY_REPORTING_BROWSER_REPORT_GENERATOR_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/browser_report_generator_ios.h"
#include "base/mac/bundle_locations.h"
#include "base/mac/foundation_util.h"
#include "base/strings/sys_string_conversions.h"
#include "ios/chrome/browser/application_context.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state_manager.h"
#include "ios/chrome/common/channel_info.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace em = ::enterprise_management;
namespace enterprise_reporting {
BrowserReportGeneratorIOS::BrowserReportGeneratorIOS() = default;
BrowserReportGeneratorIOS::~BrowserReportGeneratorIOS() = default;
std::string BrowserReportGeneratorIOS::GetExecutablePath() {
NSBundle* baseBundle = base::mac::OuterBundle();
return base::SysNSStringToUTF8([baseBundle bundleIdentifier]);
}
version_info::Channel BrowserReportGeneratorIOS::GetChannel() {
return ::GetChannel();
}
void BrowserReportGeneratorIOS::GenerateBuildStateInfo(
em::BrowserReport* report) {
// Not used on iOS because there is no in-app auto-update.
}
void BrowserReportGeneratorIOS::GenerateProfileInfo(em::BrowserReport* report) {
for (const auto* entry : GetApplicationContext()
->GetChromeBrowserStateManager()
->GetLoadedBrowserStates()) {
// Skip off-the-record profile.
if (entry->IsOffTheRecord()) {
continue;
}
em::ChromeUserProfileInfo* profile =
report->add_chrome_user_profile_infos();
profile->set_id(entry->GetStatePath().AsUTF8Unsafe());
profile->set_name(entry->GetStatePath().BaseName().AsUTF8Unsafe());
profile->set_is_full_report(false);
}
}
void BrowserReportGeneratorIOS::GeneratePluginsIfNeeded(
ReportCallback callback,
std::unique_ptr<em::BrowserReport> report) {
// There are no plugins on iOS.
std::move(callback).Run(std::move(report));
}
} // namespace enterprise_reporting
// 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_PROFILE_REPORT_GENERATOR_IOS_H_
#define IOS_CHROME_BROWSER_POLICY_REPORTING_PROFILE_REPORT_GENERATOR_IOS_H_
#include "components/enterprise/browser/reporting/profile_report_generator.h"
#include <memory>
#include "base/macros.h"
#include "components/policy/core/browser/policy_conversions_client.h"
#include "components/policy/proto/device_management_backend.pb.h"
namespace base {
class FilePath;
}
namespace policy {
class MachineLevelUserCloudPolicyManager;
}
class ChromeBrowserState;
namespace enterprise_reporting {
/**
* iOS implementation of the profile reporting delegate.
*/
class ProfileReportGeneratorIOS : public ProfileReportGenerator::Delegate {
public:
ProfileReportGeneratorIOS();
ProfileReportGeneratorIOS(const ProfileReportGeneratorIOS&) = delete;
ProfileReportGeneratorIOS& operator=(const ProfileReportGeneratorIOS&) =
delete;
~ProfileReportGeneratorIOS() override;
// ProfileReportGenerator::Delegate implementation.
bool Init(const base::FilePath& path) override;
void GetSigninUserInfo(
enterprise_management::ChromeUserProfileInfo* report) override;
void GetExtensionInfo(
enterprise_management::ChromeUserProfileInfo* report) override;
void GetExtensionRequest(
enterprise_management::ChromeUserProfileInfo* report) override;
std::unique_ptr<policy::PolicyConversionsClient> MakePolicyConversionsClient()
override;
policy::MachineLevelUserCloudPolicyManager* GetCloudPolicyManager() override;
private:
ChromeBrowserState* browser_state_;
};
} // namespace enterprise_reporting
#endif // IOS_CHROME_BROWSER_POLICY_REPORTING_PROFILE_REPORT_GENERATOR_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/profile_report_generator_ios.h"
#include "base/strings/sys_string_conversions.h"
#include "components/policy/core/browser/policy_conversions.h"
#include "ios/chrome/browser/application_context.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state_manager.h"
#include "ios/chrome/browser/policy/browser_policy_connector_ios.h"
#include "ios/chrome/browser/policy/policy_conversions_client_ios.h"
#include "ios/chrome/browser/signin/authentication_service.h"
#include "ios/chrome/browser/signin/authentication_service_factory.h"
#include "ios/public/provider/chrome/browser/signin/chrome_identity.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace enterprise_reporting {
ProfileReportGeneratorIOS::ProfileReportGeneratorIOS() = default;
ProfileReportGeneratorIOS::~ProfileReportGeneratorIOS() = default;
bool ProfileReportGeneratorIOS::Init(const base::FilePath& path) {
browser_state_ =
GetApplicationContext()->GetChromeBrowserStateManager()->GetBrowserState(
path);
if (!browser_state_) {
return false;
}
return true;
}
void ProfileReportGeneratorIOS::GetSigninUserInfo(
enterprise_management::ChromeUserProfileInfo* report) {
if (!AuthenticationServiceFactory::GetForBrowserState(browser_state_)
->IsAuthenticated()) {
return;
}
ChromeIdentity* account_info =
AuthenticationServiceFactory::GetForBrowserState(browser_state_)
->GetAuthenticatedIdentity();
auto* signed_in_user_info = report->mutable_chrome_signed_in_user();
signed_in_user_info->set_email(
base::SysNSStringToUTF8(account_info.userEmail));
signed_in_user_info->set_obfudscated_gaia_id(
base::SysNSStringToUTF8(account_info.hashedGaiaID));
}
void ProfileReportGeneratorIOS::GetExtensionInfo(
enterprise_management::ChromeUserProfileInfo* report) {
// Extensions aren't supported on iOS.
}
void ProfileReportGeneratorIOS::GetExtensionRequest(
enterprise_management::ChromeUserProfileInfo* report) {
// Extensions aren't supported on iOS.
}
std::unique_ptr<policy::PolicyConversionsClient>
ProfileReportGeneratorIOS::MakePolicyConversionsClient() {
return std::make_unique<PolicyConversionsClientIOS>(browser_state_);
}
policy::MachineLevelUserCloudPolicyManager*
ProfileReportGeneratorIOS::GetCloudPolicyManager() {
return GetApplicationContext()
->GetBrowserPolicyConnector()
->machine_level_user_cloud_policy_manager();
}
} // namespace enterprise_reporting
// 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_REPORT_GENERATOR_IOS_H_
#define IOS_CHROME_BROWSER_POLICY_REPORTING_REPORT_GENERATOR_IOS_H_
#include "components/enterprise/browser/reporting/report_generator.h"
namespace enterprise_reporting {
/**
* iOS implementation of the report generator delegate.
*/
class ReportGeneratorIOS : public ReportGenerator::Delegate {
public:
ReportGeneratorIOS() = default;
ReportGeneratorIOS(const ReportGeneratorIOS&) = delete;
ReportGeneratorIOS& operator=(const ReportGeneratorIOS&) = delete;
~ReportGeneratorIOS() override = default;
// ReportGenerator::Delegate implementation.
void SetAndroidAppInfos(
ReportGenerator::ReportRequest* basic_request) override;
};
} // namespace enterprise_reporting
#endif // IOS_CHROME_BROWSER_POLICY_REPORTING_REPORT_GENERATOR_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/report_generator_ios.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace enterprise_reporting {
void ReportGeneratorIOS::SetAndroidAppInfos(
ReportGenerator::ReportRequest* basic_request) {
// Not used on iOS.
}
} // namespace enterprise_reporting
// 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_REPORT_SCHEDULER_IOS_H_
#define IOS_CHROME_BROWSER_POLICY_REPORTING_REPORT_SCHEDULER_IOS_H_
#include "components/enterprise/browser/reporting/report_scheduler.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace enterprise_reporting {
// Desktop implementation of the ReportScheduler delegate.
class ReportSchedulerIOS : public ReportScheduler::Delegate {
public:
ReportSchedulerIOS();
ReportSchedulerIOS(const ReportSchedulerIOS&) = delete;
ReportSchedulerIOS& operator=(const ReportSchedulerIOS&) = delete;
~ReportSchedulerIOS() override;
// ReportScheduler::Delegate implementation.
PrefService* GetLocalState() override;
void StartWatchingUpdatesIfNeeded(base::Time last_upload,
base::TimeDelta upload_interval) override;
void StopWatchingUpdates() override;
void SaveLastUploadVersion() override;
};
} // namespace enterprise_reporting
#endif // IOS_CHROME_BROWSER_POLICY_REPORTING_REPORT_SCHEDULER_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/report_scheduler_ios.h"
#include "ios/chrome/browser/application_context.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace enterprise_reporting {
ReportSchedulerIOS::ReportSchedulerIOS() = default;
ReportSchedulerIOS::~ReportSchedulerIOS() = default;
PrefService* ReportSchedulerIOS::GetLocalState() {
return GetApplicationContext()->GetLocalState();
}
void ReportSchedulerIOS::StartWatchingUpdatesIfNeeded(
base::Time last_upload,
base::TimeDelta upload_interval) {
// Not used on iOS because there is no in-app auto-update.
}
void ReportSchedulerIOS::StopWatchingUpdates() {
// Not used on iOS because there is no in-app auto-update.
}
void ReportSchedulerIOS::SaveLastUploadVersion() {
// Not used on iOS because there is no in-app auto-update.
}
} // namespace enterprise_reporting
......@@ -4,6 +4,11 @@
#include "ios/chrome/browser/policy/reporting/reporting_delegate_factory_ios.h"
#include "ios/chrome/browser/policy/reporting/browser_report_generator_ios.h"
#include "ios/chrome/browser/policy/reporting/profile_report_generator_ios.h"
#include "ios/chrome/browser/policy/reporting/report_generator_ios.h"
#include "ios/chrome/browser/policy/reporting/report_scheduler_ios.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
......@@ -12,26 +17,22 @@ namespace enterprise_reporting {
std::unique_ptr<BrowserReportGenerator::Delegate>
ReportingDelegateFactoryIOS::GetBrowserReportGeneratorDelegate() {
// TODO(crbug.com/1066495): Finish iOS CBCM implementation.
return nullptr;
return std::make_unique<BrowserReportGeneratorIOS>();
}
std::unique_ptr<ProfileReportGenerator::Delegate>
ReportingDelegateFactoryIOS::GetProfileReportGeneratorDelegate() {
// TODO(crbug.com/1066495): Finish iOS CBCM implementation.
return nullptr;
return std::make_unique<ProfileReportGeneratorIOS>();
}
std::unique_ptr<ReportGenerator::Delegate>
ReportingDelegateFactoryIOS::GetReportGeneratorDelegate() {
// TODO(crbug.com/1066495): Finish iOS CBCM implementation.
return nullptr;
return std::make_unique<ReportGeneratorIOS>();
}
std::unique_ptr<ReportScheduler::Delegate>
ReportingDelegateFactoryIOS::GetReportSchedulerDelegate() {
// TODO(crbug.com/1066495): Finish iOS CBCM implementation.
return nullptr;
return std::make_unique<ReportSchedulerIOS>();
}
} // 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