Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7362)

Unified Diff: chrome/browser/ui/webui/policy_ui_handler.cc

Issue 2486813002: Add DeviceADPolicyManager to provide AD policy. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/policy_ui_handler.cc
diff --git a/chrome/browser/ui/webui/policy_ui_handler.cc b/chrome/browser/ui/webui/policy_ui_handler.cc
index b0a20c299a0d671cd6b832f2b88b9715c49e2fbd..eb98883b2060534efba6359650033d3616b3210c 100644
--- a/chrome/browser/ui/webui/policy_ui_handler.cc
+++ b/chrome/browser/ui/webui/policy_ui_handler.cc
@@ -35,6 +35,7 @@
#include "components/policy/core/common/cloud/cloud_policy_client.h"
#include "components/policy/core/common/cloud/cloud_policy_constants.h"
#include "components/policy/core/common/cloud/cloud_policy_core.h"
+#include "components/policy/core/common/cloud/cloud_policy_manager.h"
#include "components/policy/core/common/cloud/cloud_policy_refresh_scheduler.h"
#include "components/policy/core/common/cloud/cloud_policy_store.h"
#include "components/policy/core/common/cloud/cloud_policy_validator.h"
@@ -54,10 +55,12 @@
#if defined(OS_CHROMEOS)
#include "chrome/browser/browser_process_platform_part.h"
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
-#include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h"
+#include "chrome/browser/chromeos/policy/device_ad_policy_manager.h"
+#include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h"
#include "chrome/browser/chromeos/policy/device_local_account_policy_service.h"
#include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h"
#include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chromeos.h"
+#include "chrome/browser/chromeos/settings/install_attributes.h"
#include "components/user_manager/user_manager.h"
#else
#include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h"
@@ -78,10 +81,11 @@ namespace {
// Strings that map from PolicySource enum to i18n string keys and their IDs.
// Their order has to follow the order of the policy::PolicySource enum.
const PolicyStringMap kPolicySources[policy::POLICY_SOURCE_COUNT] = {
- {"sourceEnterpriseDefault", IDS_POLICY_SOURCE_ENTERPRISE_DEFAULT},
- {"sourceCloud", IDS_POLICY_SOURCE_CLOUD},
- {"sourcePublicSessionOverride", IDS_POLICY_SOURCE_PUBLIC_SESSION_OVERRIDE},
- {"sourcePlatform", IDS_POLICY_SOURCE_PLATFORM},
+ {"sourceEnterpriseDefault", IDS_POLICY_SOURCE_ENTERPRISE_DEFAULT},
+ {"sourceCloud", IDS_POLICY_SOURCE_CLOUD},
+ {"sourceActiveDirectory", IDS_POLICY_SOURCE_ACTIVE_DIRECTORY},
+ {"sourcePublicSessionOverride", IDS_POLICY_SOURCE_PUBLIC_SESSION_OVERRIDE},
+ {"sourcePlatform", IDS_POLICY_SOURCE_PLATFORM},
};
// Formats the association state indicated by |data|. If |data| is NULL, the
@@ -198,11 +202,13 @@ std::unique_ptr<base::Value> CopyAndConvert(const base::Value* value) {
} // namespace
-// An interface for querying the status of cloud policy.
-class CloudPolicyStatusProvider {
+// An interface for querying the status of a policy provider. It surfaces
+// things like last fetch time or status of the backing store, but not the
+// actual policies themselves.
+class PolicyStatusProvider {
public:
- CloudPolicyStatusProvider();
- virtual ~CloudPolicyStatusProvider();
+ PolicyStatusProvider();
+ virtual ~PolicyStatusProvider();
// Sets a callback to invoke upon status changes.
void SetStatusChangeCallback(const base::Closure& callback);
@@ -215,7 +221,7 @@ class CloudPolicyStatusProvider {
private:
base::Closure callback_;
- DISALLOW_COPY_AND_ASSIGN(CloudPolicyStatusProvider);
+ DISALLOW_COPY_AND_ASSIGN(PolicyStatusProvider);
};
// Status provider implementation that pulls cloud policy status from a
@@ -223,7 +229,7 @@ class CloudPolicyStatusProvider {
// changes on that CloudPolicyCore and reports them through the status change
// callback.
class CloudPolicyCoreStatusProvider
- : public CloudPolicyStatusProvider,
+ : public PolicyStatusProvider,
public policy::CloudPolicyStore::Observer {
public:
explicit CloudPolicyCoreStatusProvider(policy::CloudPolicyCore* core);
@@ -279,7 +285,7 @@ class DevicePolicyStatusProvider : public CloudPolicyCoreStatusProvider {
// may go away any time behind the scenes, at which point the status message
// text will indicate CloudPolicyStore::STATUS_BAD_STATE.
class DeviceLocalAccountPolicyStatusProvider
- : public CloudPolicyStatusProvider,
+ : public PolicyStatusProvider,
public policy::DeviceLocalAccountPolicyService::Observer {
public:
DeviceLocalAccountPolicyStatusProvider(
@@ -287,7 +293,7 @@ class DeviceLocalAccountPolicyStatusProvider
policy::DeviceLocalAccountPolicyService* service);
~DeviceLocalAccountPolicyStatusProvider() override;
- // CloudPolicyStatusProvider implementation.
+ // PolicyStatusProvider implementation.
void GetStatus(base::DictionaryValue* dict) override;
// policy::DeviceLocalAccountPolicyService::Observer implementation.
@@ -300,23 +306,32 @@ class DeviceLocalAccountPolicyStatusProvider
DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyStatusProvider);
};
+
+class DeviceADPolicyStatusProvider : public PolicyStatusProvider {
emaxx 2016/11/11 15:25:09 Add a short comment for this class?
Thiemo Nagel 2016/11/16 19:11:01 Done.
+ public:
+ explicit DeviceADPolicyStatusProvider(policy::DeviceADPolicyManager* manager);
+ ~DeviceADPolicyStatusProvider() override = default;
emaxx 2016/11/11 15:25:09 Just curious: is this due to some compiler complai
Thiemo Nagel 2016/11/16 19:11:01 No. It's probably bad form because it creates an
+
+ // PolicyStatusProvider implementation.
+ void GetStatus(base::DictionaryValue* dict) override;
+
+ private:
+ const policy::CloudPolicyStore* store_;
+};
#endif
-CloudPolicyStatusProvider::CloudPolicyStatusProvider() {
-}
+PolicyStatusProvider::PolicyStatusProvider() {}
-CloudPolicyStatusProvider::~CloudPolicyStatusProvider() {
-}
+PolicyStatusProvider::~PolicyStatusProvider() {}
-void CloudPolicyStatusProvider::SetStatusChangeCallback(
+void PolicyStatusProvider::SetStatusChangeCallback(
const base::Closure& callback) {
callback_ = callback;
}
-void CloudPolicyStatusProvider::GetStatus(base::DictionaryValue* dict) {
-}
+void PolicyStatusProvider::GetStatus(base::DictionaryValue* dict) {}
-void CloudPolicyStatusProvider::NotifyStatusChange() {
+void PolicyStatusProvider::NotifyStatusChange() {
if (!callback_.is_null())
callback_.Run();
}
@@ -413,7 +428,18 @@ void DeviceLocalAccountPolicyStatusProvider::OnPolicyUpdated(
void DeviceLocalAccountPolicyStatusProvider::OnDeviceLocalAccountsChanged() {
NotifyStatusChange();
}
-#endif
+
+DeviceADPolicyStatusProvider::DeviceADPolicyStatusProvider(
+ policy::DeviceADPolicyManager* manager)
+ : store_(manager->store()) {}
+
+void DeviceADPolicyStatusProvider::GetStatus(base::DictionaryValue* dict) {
+ base::string16 status =
+ policy::FormatStoreStatus(store_->status(), store_->validation_status());
+ dict->SetString("status", status);
+}
+
+#endif // defined(OS_CHROMEOS)
PolicyUIHandler::PolicyUIHandler()
: weak_factory_(this) {
@@ -467,8 +493,15 @@ void PolicyUIHandler::RegisterMessages() {
#if defined(OS_CHROMEOS)
policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
- if (connector->IsEnterpriseManaged())
- device_status_provider_.reset(new DevicePolicyStatusProvider(connector));
+ if (connector->IsEnterpriseManaged()) {
+ if (connector->GetDeviceADPolicyManager()) {
+ device_status_provider_ = base::MakeUnique<DeviceADPolicyStatusProvider>(
+ connector->GetDeviceADPolicyManager());
+ } else {
+ device_status_provider_ =
+ base::MakeUnique<DevicePolicyStatusProvider>(connector);
+ }
+ }
const user_manager::UserManager* user_manager =
user_manager::UserManager::Get();
@@ -500,9 +533,9 @@ void PolicyUIHandler::RegisterMessages() {
#endif
if (!user_status_provider_.get())
- user_status_provider_.reset(new CloudPolicyStatusProvider());
+ user_status_provider_.reset(new PolicyStatusProvider());
if (!device_status_provider_.get())
- device_status_provider_.reset(new CloudPolicyStatusProvider());
+ device_status_provider_.reset(new PolicyStatusProvider());
base::Closure update_callback(base::Bind(&PolicyUIHandler::SendStatus,
base::Unretained(this)));
@@ -729,14 +762,16 @@ void PolicyUIHandler::HandleReloadPolicies(const base::ListValue* args) {
// service is not working properly.
// TODO(binjin): evaluate and possibly remove this after invalidation
// service is landed and tested. http://crbug.com/480982
- policy::BrowserPolicyConnectorChromeOS* connector =
- g_browser_process->platform_part()->browser_policy_connector_chromeos();
- policy::RemoteCommandsService* remote_commands_service =
- connector->GetDeviceCloudPolicyManager()
- ->core()
- ->remote_commands_service();
- if (remote_commands_service)
- remote_commands_service->FetchRemoteCommands();
+ policy::CloudPolicyManager* manager =
+ g_browser_process->platform_part()
+ ->browser_policy_connector_chromeos()
+ ->GetDeviceCloudPolicyManager();
+ if (manager) {
+ policy::RemoteCommandsService* remote_commands_service =
+ manager->core()->remote_commands_service();
+ if (remote_commands_service)
+ remote_commands_service->FetchRemoteCommands();
+ }
#endif
GetPolicyService()->RefreshPolicies(base::Bind(
&PolicyUIHandler::OnRefreshPoliciesDone, weak_factory_.GetWeakPtr()));

Powered by Google App Engine
This is Rietveld 408576698