Commit fbdbe39e authored by Rohit Rao's avatar Rohit Rao Committed by Commit Bot

[ios] Moves BrowserPolicyConnectorIOS to //ios/chrome/browser/policy.

Removes code that is related to the DeviceManagementService and cloud
policy. That code will be brought back later, when we are ready to bring
up cloud policy support. For now, BrowserPolicyConnectorIOS only
supports device-local policies.

BUG=1024115

Change-Id: Ia3ace77846a500dd56258649955023baaff78777
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2063149Reviewed-by: default avatarOwen Min <zmin@chromium.org>
Commit-Queue: Rohit Rao <rohitrao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#742729}
parent 34aa80d6
...@@ -58,20 +58,6 @@ ...@@ -58,20 +58,6 @@
namespace policy { namespace policy {
namespace {
bool ProviderHasPolicies(const ConfigurationPolicyProvider* provider) {
if (!provider)
return false;
for (const auto& pair : provider->policies()) {
if (!pair.second->empty())
return true;
}
return false;
}
} // namespace
ChromeBrowserPolicyConnector::ChromeBrowserPolicyConnector() ChromeBrowserPolicyConnector::ChromeBrowserPolicyConnector()
: BrowserPolicyConnector(base::Bind(&BuildHandlerList)) { : BrowserPolicyConnector(base::Bind(&BuildHandlerList)) {
#if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
......
...@@ -20,8 +20,6 @@ jumbo_source_set("internal") { ...@@ -20,8 +20,6 @@ jumbo_source_set("internal") {
"browser_policy_connector.h", "browser_policy_connector.h",
"browser_policy_connector_base.cc", "browser_policy_connector_base.cc",
"browser_policy_connector_base.h", "browser_policy_connector_base.h",
"browser_policy_connector_ios.h",
"browser_policy_connector_ios.mm",
"cloud/message_util.cc", "cloud/message_util.cc",
"cloud/message_util.h", "cloud/message_util.h",
"configuration_policy_handler.cc", "configuration_policy_handler.cc",
......
...@@ -124,6 +124,17 @@ void BrowserPolicyConnector::ScheduleServiceInitialization( ...@@ -124,6 +124,17 @@ void BrowserPolicyConnector::ScheduleServiceInitialization(
device_management_service_->ScheduleInitialization(delay_milliseconds); device_management_service_->ScheduleInitialization(delay_milliseconds);
} }
bool BrowserPolicyConnector::ProviderHasPolicies(
const ConfigurationPolicyProvider* provider) const {
if (!provider)
return false;
for (const auto& pair : provider->policies()) {
if (!pair.second->empty())
return true;
}
return false;
}
// static // static
bool BrowserPolicyConnector::IsNonEnterpriseUser(const std::string& username) { bool BrowserPolicyConnector::IsNonEnterpriseUser(const std::string& username) {
TRACE_EVENT0("browser", "BrowserPolicyConnector::IsNonEnterpriseUser"); TRACE_EVENT0("browser", "BrowserPolicyConnector::IsNonEnterpriseUser");
......
...@@ -87,6 +87,9 @@ class POLICY_EXPORT BrowserPolicyConnector : public BrowserPolicyConnectorBase { ...@@ -87,6 +87,9 @@ class POLICY_EXPORT BrowserPolicyConnector : public BrowserPolicyConnectorBase {
PrefService* local_state, PrefService* local_state,
std::unique_ptr<DeviceManagementService> device_management_service); std::unique_ptr<DeviceManagementService> device_management_service);
// Returns true if the given |provider| has any registered policies.
bool ProviderHasPolicies(const ConfigurationPolicyProvider* provider) const;
private: private:
std::unique_ptr<PolicyStatisticsCollector> policy_statistics_collector_; std::unique_ptr<PolicyStatisticsCollector> policy_statistics_collector_;
......
...@@ -101,6 +101,7 @@ source_set("browser") { ...@@ -101,6 +101,7 @@ source_set("browser") {
"//ios/chrome/browser/drag_and_drop", "//ios/chrome/browser/drag_and_drop",
"//ios/chrome/browser/find_in_page:feature_flags", "//ios/chrome/browser/find_in_page:feature_flags",
"//ios/chrome/browser/itunes_urls", "//ios/chrome/browser/itunes_urls",
"//ios/chrome/browser/policy",
"//ios/chrome/browser/signin:feature_flags", "//ios/chrome/browser/signin:feature_flags",
"//ios/chrome/browser/ssl:feature_flags", "//ios/chrome/browser/ssl:feature_flags",
"//ios/chrome/browser/sync/glue", "//ios/chrome/browser/sync/glue",
......
...@@ -54,6 +54,8 @@ include_rules = [ ...@@ -54,6 +54,8 @@ include_rules = [
"+components/password_manager/ios", "+components/password_manager/ios",
"+components/payments/core", "+components/payments/core",
"+components/payments/mojom", "+components/payments/mojom",
"+components/policy/core/browser",
"+components/policy/core/common",
"+components/pref_registry", "+components/pref_registry",
"+components/prefs", "+components/prefs",
"+components/profile_metrics", "+components/profile_metrics",
......
...@@ -2,6 +2,23 @@ ...@@ -2,6 +2,23 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
source_set("policy") {
sources = [
"browser_policy_connector_ios.h",
"browser_policy_connector_ios.mm",
]
deps = [
"//base",
"//components/policy/core/common",
"//services/network/public/cpp",
]
public_deps = [ "//components/policy/core/browser" ]
configs += [ "//build/config/compiler:enable_arc" ]
}
source_set("feature_flags") { source_set("feature_flags") {
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
sources = [ sources = [
......
michaeldo@chromium.org
rohitrao@chromium.org
file://components/policy/OWNERS
# COMPONENT: Enterprise>CloudPolicy
# TEAM: ios-directory-owners@chromium.org
# OS: iOS
// Copyright 2014 The Chromium Authors. All rights reserved. // Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef COMPONENTS_POLICY_CORE_BROWSER_BROWSER_POLICY_CONNECTOR_IOS_H_ #ifndef IOS_CHROME_BROWSER_POLICY_BROWSER_POLICY_CONNECTOR_IOS_H_
#define COMPONENTS_POLICY_CORE_BROWSER_BROWSER_POLICY_CONNECTOR_IOS_H_ #define IOS_CHROME_BROWSER_POLICY_BROWSER_POLICY_CONNECTOR_IOS_H_
#include <memory> #include <memory>
#include <string> #include <string>
...@@ -11,21 +11,20 @@ ...@@ -11,21 +11,20 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "components/policy/core/browser/browser_policy_connector.h" #include "components/policy/core/browser/browser_policy_connector.h"
#include "components/policy/policy_export.h"
namespace network { namespace network {
class SharedURLLoaderFactory; class SharedURLLoaderFactory;
} }
namespace policy { namespace policy {
class ConfigurationPolicyProvider; class ConfigurationPolicyProvider;
} // namespace policy
// Extends BrowserPolicyConnector with the setup for iOS builds. // Extends BrowserPolicyConnector with the setup for iOS builds.
class POLICY_EXPORT BrowserPolicyConnectorIOS : public BrowserPolicyConnector { class BrowserPolicyConnectorIOS : public policy::BrowserPolicyConnector {
public: public:
BrowserPolicyConnectorIOS(const HandlerListFactory& handler_list_factory, BrowserPolicyConnectorIOS(
const std::string& user_agent); const policy::HandlerListFactory& handler_list_factory);
~BrowserPolicyConnectorIOS() override; ~BrowserPolicyConnectorIOS() override;
...@@ -42,17 +41,13 @@ class POLICY_EXPORT BrowserPolicyConnectorIOS : public BrowserPolicyConnector { ...@@ -42,17 +41,13 @@ class POLICY_EXPORT BrowserPolicyConnectorIOS : public BrowserPolicyConnector {
CreatePolicyProviders() override; CreatePolicyProviders() override;
private: private:
std::unique_ptr<ConfigurationPolicyProvider> CreatePlatformProvider(); std::unique_ptr<policy::ConfigurationPolicyProvider> CreatePlatformProvider();
ConfigurationPolicyProvider* GetPlatformProvider(); policy::ConfigurationPolicyProvider* GetPlatformProvider();
std::string user_agent_;
// Owned by base class. // Owned by base class.
ConfigurationPolicyProvider* platform_provider_ = nullptr; policy::ConfigurationPolicyProvider* platform_provider_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(BrowserPolicyConnectorIOS); DISALLOW_COPY_AND_ASSIGN(BrowserPolicyConnectorIOS);
}; };
} // namespace policy #endif // IOS_CHROME_BROWSER_POLICY_BROWSER_POLICY_CONNECTOR_IOS_H_
#endif // COMPONENTS_POLICY_CORE_BROWSER_BROWSER_POLICY_CONNECTOR_IOS_H_
// Copyright 2014 The Chromium Authors. All rights reserved. // Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "components/policy/core/browser/browser_policy_connector_ios.h" #include "ios/chrome/browser/policy/browser_policy_connector_ios.h"
#include <stdint.h> #include <stdint.h>
...@@ -20,75 +20,28 @@ ...@@ -20,75 +20,28 @@
#include "components/policy/core/common/policy_loader_ios.h" #include "components/policy/core/common/policy_loader_ios.h"
#include "services/network/public/cpp/shared_url_loader_factory.h" #include "services/network/public/cpp/shared_url_loader_factory.h"
namespace policy { #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace { using policy::AsyncPolicyLoader;
using policy::AsyncPolicyProvider;
class DeviceManagementServiceConfiguration using policy::BrowserPolicyConnectorBase;
: public DeviceManagementService::Configuration { using policy::BrowserPolicyConnector;
public: using policy::ConfigurationPolicyProvider;
explicit DeviceManagementServiceConfiguration(const std::string& user_agent) using policy::HandlerListFactory;
: user_agent_(user_agent) {} using policy::PolicyLoaderIOS;
~DeviceManagementServiceConfiguration() override {}
std::string GetDMServerUrl() override {
return BrowserPolicyConnector::GetDeviceManagementUrl();
}
std::string GetAgentParameter() override { return user_agent_; }
std::string GetPlatformParameter() override {
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 GetReportingServerUrl() override {
return BrowserPolicyConnector::GetRealtimeReportingUrl();
}
private:
std::string user_agent_;
DISALLOW_COPY_AND_ASSIGN(DeviceManagementServiceConfiguration);
};
} // namespace
BrowserPolicyConnectorIOS::BrowserPolicyConnectorIOS( BrowserPolicyConnectorIOS::BrowserPolicyConnectorIOS(
const HandlerListFactory& handler_list_factory, const HandlerListFactory& handler_list_factory)
const std::string& user_agent) : BrowserPolicyConnector(handler_list_factory) {}
: BrowserPolicyConnector(handler_list_factory), user_agent_(user_agent) {}
BrowserPolicyConnectorIOS::~BrowserPolicyConnectorIOS() {} BrowserPolicyConnectorIOS::~BrowserPolicyConnectorIOS() {}
void BrowserPolicyConnectorIOS::Init( void BrowserPolicyConnectorIOS::Init(
PrefService* local_state, PrefService* local_state,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) { scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) {
std::unique_ptr<DeviceManagementService::Configuration> configuration( InitInternal(local_state, nullptr);
new DeviceManagementServiceConfiguration(user_agent_));
std::unique_ptr<DeviceManagementService> device_management_service(
new DeviceManagementService(std::move(configuration)));
// Delay initialization of the cloud policy requests by 5 seconds.
const int64_t kServiceInitializationStartupDelay = 5000;
device_management_service->ScheduleInitialization(
kServiceInitializationStartupDelay);
InitInternal(local_state, std::move(device_management_service));
} }
bool BrowserPolicyConnectorIOS::IsEnterpriseManaged() const { bool BrowserPolicyConnectorIOS::IsEnterpriseManaged() const {
...@@ -97,16 +50,7 @@ bool BrowserPolicyConnectorIOS::IsEnterpriseManaged() const { ...@@ -97,16 +50,7 @@ bool BrowserPolicyConnectorIOS::IsEnterpriseManaged() const {
} }
bool BrowserPolicyConnectorIOS::HasMachineLevelPolicies() { bool BrowserPolicyConnectorIOS::HasMachineLevelPolicies() {
const ConfigurationPolicyProvider* provider = GetPlatformProvider(); return ProviderHasPolicies(GetPlatformProvider());
if (!provider) {
return false;
}
for (const auto& pair : provider->policies()) {
if (!pair.second->empty()) {
return true;
}
}
return false;
} }
std::vector<std::unique_ptr<policy::ConfigurationPolicyProvider>> std::vector<std::unique_ptr<policy::ConfigurationPolicyProvider>>
...@@ -138,5 +82,3 @@ ConfigurationPolicyProvider* BrowserPolicyConnectorIOS::GetPlatformProvider() { ...@@ -138,5 +82,3 @@ ConfigurationPolicyProvider* BrowserPolicyConnectorIOS::GetPlatformProvider() {
BrowserPolicyConnectorBase::GetPolicyProviderForTesting(); BrowserPolicyConnectorBase::GetPolicyProviderForTesting();
return provider ? provider : platform_provider_; return provider ? provider : platform_provider_;
} }
} // namespace policy
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