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

Side by Side Diff: chrome/browser/ui/webui/policy_ui_handler.cc

Issue 2486813002: Add DeviceADPolicyManager to provide AD policy. (Closed)
Patch Set: Address Bernhard's comments 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/policy_ui_handler.h" 5 #include "chrome/browser/ui/webui/policy_ui_handler.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 17 matching lines...) Expand all
28 #include "chrome/browser/policy/schema_registry_service_factory.h" 28 #include "chrome/browser/policy/schema_registry_service_factory.h"
29 #include "chrome/browser/profiles/profile.h" 29 #include "chrome/browser/profiles/profile.h"
30 #include "chrome/grit/policy_resources.h" 30 #include "chrome/grit/policy_resources.h"
31 #include "chrome/grit/policy_resources_map.h" 31 #include "chrome/grit/policy_resources_map.h"
32 #include "components/policy/core/browser/browser_policy_connector.h" 32 #include "components/policy/core/browser/browser_policy_connector.h"
33 #include "components/policy/core/browser/cloud/message_util.h" 33 #include "components/policy/core/browser/cloud/message_util.h"
34 #include "components/policy/core/browser/configuration_policy_handler_list.h" 34 #include "components/policy/core/browser/configuration_policy_handler_list.h"
35 #include "components/policy/core/common/cloud/cloud_policy_client.h" 35 #include "components/policy/core/common/cloud/cloud_policy_client.h"
36 #include "components/policy/core/common/cloud/cloud_policy_constants.h" 36 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
37 #include "components/policy/core/common/cloud/cloud_policy_core.h" 37 #include "components/policy/core/common/cloud/cloud_policy_core.h"
38 #include "components/policy/core/common/cloud/cloud_policy_manager.h"
38 #include "components/policy/core/common/cloud/cloud_policy_refresh_scheduler.h" 39 #include "components/policy/core/common/cloud/cloud_policy_refresh_scheduler.h"
39 #include "components/policy/core/common/cloud/cloud_policy_store.h" 40 #include "components/policy/core/common/cloud/cloud_policy_store.h"
40 #include "components/policy/core/common/cloud/cloud_policy_validator.h" 41 #include "components/policy/core/common/cloud/cloud_policy_validator.h"
41 #include "components/policy/core/common/policy_details.h" 42 #include "components/policy/core/common/policy_details.h"
42 #include "components/policy/core/common/policy_types.h" 43 #include "components/policy/core/common/policy_types.h"
43 #include "components/policy/core/common/remote_commands/remote_commands_service. h" 44 #include "components/policy/core/common/remote_commands/remote_commands_service. h"
44 #include "components/policy/core/common/schema.h" 45 #include "components/policy/core/common/schema.h"
45 #include "components/policy/core/common/schema_map.h" 46 #include "components/policy/core/common/schema_map.h"
46 #include "components/policy/policy_constants.h" 47 #include "components/policy/policy_constants.h"
47 #include "components/policy/proto/device_management_backend.pb.h" 48 #include "components/policy/proto/device_management_backend.pb.h"
48 #include "components/strings/grit/components_strings.h" 49 #include "components/strings/grit/components_strings.h"
49 #include "content/public/browser/web_contents.h" 50 #include "content/public/browser/web_contents.h"
50 #include "extensions/features/features.h" 51 #include "extensions/features/features.h"
51 #include "google_apis/gaia/gaia_auth_util.h" 52 #include "google_apis/gaia/gaia_auth_util.h"
52 #include "ui/base/l10n/l10n_util.h" 53 #include "ui/base/l10n/l10n_util.h"
53 #include "ui/base/l10n/time_format.h" 54 #include "ui/base/l10n/time_format.h"
54 55
55 #if defined(OS_CHROMEOS) 56 #if defined(OS_CHROMEOS)
56 #include "chrome/browser/browser_process_platform_part.h" 57 #include "chrome/browser/browser_process_platform_part.h"
57 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" 58 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
58 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" 59 #include "chrome/browser/chromeos/policy/device_active_directory_policy_manager. h"
60 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h"
59 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" 61 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h"
60 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" 62 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h"
61 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom eos.h" 63 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom eos.h"
64 #include "chrome/browser/chromeos/settings/install_attributes.h"
62 #include "components/user_manager/user_manager.h" 65 #include "components/user_manager/user_manager.h"
63 #else 66 #else
64 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" 67 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h"
65 #include "components/policy/core/common/cloud/user_cloud_policy_manager.h" 68 #include "components/policy/core/common/cloud/user_cloud_policy_manager.h"
66 #endif 69 #endif
67 70
68 #if BUILDFLAG(ENABLE_EXTENSIONS) 71 #if BUILDFLAG(ENABLE_EXTENSIONS)
69 #include "extensions/browser/extension_registry.h" 72 #include "extensions/browser/extension_registry.h"
70 #include "extensions/common/extension.h" 73 #include "extensions/common/extension.h"
71 #include "extensions/common/manifest.h" 74 #include "extensions/common/manifest.h"
72 #include "extensions/common/manifest_constants.h" 75 #include "extensions/common/manifest_constants.h"
73 #endif 76 #endif
74 77
75 namespace em = enterprise_management; 78 namespace em = enterprise_management;
76 79
77 namespace { 80 namespace {
78 81
79 // Strings that map from PolicySource enum to i18n string keys and their IDs. 82 // Strings that map from PolicySource enum to i18n string keys and their IDs.
80 // Their order has to follow the order of the policy::PolicySource enum. 83 // Their order has to follow the order of the policy::PolicySource enum.
81 const PolicyStringMap kPolicySources[policy::POLICY_SOURCE_COUNT] = { 84 const PolicyStringMap kPolicySources[policy::POLICY_SOURCE_COUNT] = {
82 {"sourceEnterpriseDefault", IDS_POLICY_SOURCE_ENTERPRISE_DEFAULT}, 85 {"sourceEnterpriseDefault", IDS_POLICY_SOURCE_ENTERPRISE_DEFAULT},
83 {"sourceCloud", IDS_POLICY_SOURCE_CLOUD}, 86 {"sourceCloud", IDS_POLICY_SOURCE_CLOUD},
84 {"sourcePublicSessionOverride", IDS_POLICY_SOURCE_PUBLIC_SESSION_OVERRIDE}, 87 {"sourceActiveDirectory", IDS_POLICY_SOURCE_ACTIVE_DIRECTORY},
Dan Beam 2016/11/18 16:45:05 alphabetize
Thiemo Nagel 2016/11/21 13:31:22 Done.
85 {"sourcePlatform", IDS_POLICY_SOURCE_PLATFORM}, 88 {"sourcePublicSessionOverride", IDS_POLICY_SOURCE_PUBLIC_SESSION_OVERRIDE},
89 {"sourcePlatform", IDS_POLICY_SOURCE_PLATFORM},
86 }; 90 };
87 91
88 // Formats the association state indicated by |data|. If |data| is NULL, the 92 // Formats the association state indicated by |data|. If |data| is NULL, the
89 // state is considered to be UNMANAGED. 93 // state is considered to be UNMANAGED.
90 base::string16 FormatAssociationState(const em::PolicyData* data) { 94 base::string16 FormatAssociationState(const em::PolicyData* data) {
91 if (data) { 95 if (data) {
92 switch (data->state()) { 96 switch (data->state()) {
93 case em::PolicyData::ACTIVE: 97 case em::PolicyData::ACTIVE:
94 return l10n_util::GetStringUTF16(IDS_POLICY_ASSOCIATION_STATE_ACTIVE); 98 return l10n_util::GetStringUTF16(IDS_POLICY_ASSOCIATION_STATE_ACTIVE);
95 case em::PolicyData::UNMANAGED: 99 case em::PolicyData::UNMANAGED:
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 if (list->GetDictionary(i, &dict)) 196 if (list->GetDictionary(i, &dict))
193 list->Set(i, DictionaryToJSONString(*dict)); 197 list->Set(i, DictionaryToJSONString(*dict));
194 } 198 }
195 } 199 }
196 200
197 return copy; 201 return copy;
198 } 202 }
199 203
200 } // namespace 204 } // namespace
201 205
202 // An interface for querying the status of cloud policy. 206 // An interface for querying the status of a policy provider. It surfaces
203 class CloudPolicyStatusProvider { 207 // things like last fetch time or status of the backing store, but not the
208 // actual policies themselves.
209 class PolicyStatusProvider {
204 public: 210 public:
205 CloudPolicyStatusProvider(); 211 PolicyStatusProvider();
206 virtual ~CloudPolicyStatusProvider(); 212 virtual ~PolicyStatusProvider();
207 213
208 // Sets a callback to invoke upon status changes. 214 // Sets a callback to invoke upon status changes.
209 void SetStatusChangeCallback(const base::Closure& callback); 215 void SetStatusChangeCallback(const base::Closure& callback);
210 216
211 virtual void GetStatus(base::DictionaryValue* dict); 217 virtual void GetStatus(base::DictionaryValue* dict);
212 218
213 protected: 219 protected:
214 void NotifyStatusChange(); 220 void NotifyStatusChange();
215 221
216 private: 222 private:
217 base::Closure callback_; 223 base::Closure callback_;
218 224
219 DISALLOW_COPY_AND_ASSIGN(CloudPolicyStatusProvider); 225 DISALLOW_COPY_AND_ASSIGN(PolicyStatusProvider);
220 }; 226 };
221 227
222 // Status provider implementation that pulls cloud policy status from a 228 // Status provider implementation that pulls cloud policy status from a
223 // CloudPolicyCore instance provided at construction time. Also listens for 229 // CloudPolicyCore instance provided at construction time. Also listens for
224 // changes on that CloudPolicyCore and reports them through the status change 230 // changes on that CloudPolicyCore and reports them through the status change
225 // callback. 231 // callback.
226 class CloudPolicyCoreStatusProvider 232 class CloudPolicyCoreStatusProvider
227 : public CloudPolicyStatusProvider, 233 : public PolicyStatusProvider,
228 public policy::CloudPolicyStore::Observer { 234 public policy::CloudPolicyStore::Observer {
229 public: 235 public:
230 explicit CloudPolicyCoreStatusProvider(policy::CloudPolicyCore* core); 236 explicit CloudPolicyCoreStatusProvider(policy::CloudPolicyCore* core);
231 ~CloudPolicyCoreStatusProvider() override; 237 ~CloudPolicyCoreStatusProvider() override;
232 238
233 // policy::CloudPolicyStore::Observer implementation. 239 // policy::CloudPolicyStore::Observer implementation.
234 void OnStoreLoaded(policy::CloudPolicyStore* store) override; 240 void OnStoreLoaded(policy::CloudPolicyStore* store) override;
235 void OnStoreError(policy::CloudPolicyStore* store) override; 241 void OnStoreError(policy::CloudPolicyStore* store) override;
236 242
237 protected: 243 protected:
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 DISALLOW_COPY_AND_ASSIGN(DevicePolicyStatusProvider); 279 DISALLOW_COPY_AND_ASSIGN(DevicePolicyStatusProvider);
274 }; 280 };
275 281
276 // A cloud policy status provider that reads policy status from the policy core 282 // A cloud policy status provider that reads policy status from the policy core
277 // associated with the device-local account specified by |user_id| at 283 // associated with the device-local account specified by |user_id| at
278 // construction time. The indirection via user ID and 284 // construction time. The indirection via user ID and
279 // DeviceLocalAccountPolicyService is necessary because the device-local account 285 // DeviceLocalAccountPolicyService is necessary because the device-local account
280 // may go away any time behind the scenes, at which point the status message 286 // may go away any time behind the scenes, at which point the status message
281 // text will indicate CloudPolicyStore::STATUS_BAD_STATE. 287 // text will indicate CloudPolicyStore::STATUS_BAD_STATE.
282 class DeviceLocalAccountPolicyStatusProvider 288 class DeviceLocalAccountPolicyStatusProvider
283 : public CloudPolicyStatusProvider, 289 : public PolicyStatusProvider,
284 public policy::DeviceLocalAccountPolicyService::Observer { 290 public policy::DeviceLocalAccountPolicyService::Observer {
285 public: 291 public:
286 DeviceLocalAccountPolicyStatusProvider( 292 DeviceLocalAccountPolicyStatusProvider(
287 const std::string& user_id, 293 const std::string& user_id,
288 policy::DeviceLocalAccountPolicyService* service); 294 policy::DeviceLocalAccountPolicyService* service);
289 ~DeviceLocalAccountPolicyStatusProvider() override; 295 ~DeviceLocalAccountPolicyStatusProvider() override;
290 296
291 // CloudPolicyStatusProvider implementation. 297 // PolicyStatusProvider implementation.
292 void GetStatus(base::DictionaryValue* dict) override; 298 void GetStatus(base::DictionaryValue* dict) override;
293 299
294 // policy::DeviceLocalAccountPolicyService::Observer implementation. 300 // policy::DeviceLocalAccountPolicyService::Observer implementation.
295 void OnPolicyUpdated(const std::string& user_id) override; 301 void OnPolicyUpdated(const std::string& user_id) override;
296 void OnDeviceLocalAccountsChanged() override; 302 void OnDeviceLocalAccountsChanged() override;
297 303
298 private: 304 private:
299 const std::string user_id_; 305 const std::string user_id_;
300 policy::DeviceLocalAccountPolicyService* service_; 306 policy::DeviceLocalAccountPolicyService* service_;
301 307
302 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyStatusProvider); 308 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyStatusProvider);
303 }; 309 };
310
311 // Provides status for DeviceActiveDirectoryPolicyManager.
312 class DeviceActiveDirectoryPolicyStatusProvider : public PolicyStatusProvider {
313 public:
314 explicit DeviceActiveDirectoryPolicyStatusProvider(
315 policy::DeviceActiveDirectoryPolicyManager* manager);
316 ~DeviceActiveDirectoryPolicyStatusProvider() override;
317
318 // PolicyStatusProvider implementation.
319 void GetStatus(base::DictionaryValue* dict) override;
320
321 private:
322 const policy::CloudPolicyStore* store_;
Dan Beam 2016/11/18 16:45:05 DISALLOW
Thiemo Nagel 2016/11/21 13:31:22 Done.
323 };
304 #endif 324 #endif
305 325
306 CloudPolicyStatusProvider::CloudPolicyStatusProvider() { 326 PolicyStatusProvider::PolicyStatusProvider() {}
307 }
308 327
309 CloudPolicyStatusProvider::~CloudPolicyStatusProvider() { 328 PolicyStatusProvider::~PolicyStatusProvider() {}
310 }
311 329
312 void CloudPolicyStatusProvider::SetStatusChangeCallback( 330 void PolicyStatusProvider::SetStatusChangeCallback(
313 const base::Closure& callback) { 331 const base::Closure& callback) {
314 callback_ = callback; 332 callback_ = callback;
315 } 333 }
316 334
317 void CloudPolicyStatusProvider::GetStatus(base::DictionaryValue* dict) { 335 void PolicyStatusProvider::GetStatus(base::DictionaryValue* dict) {}
318 }
319 336
320 void CloudPolicyStatusProvider::NotifyStatusChange() { 337 void PolicyStatusProvider::NotifyStatusChange() {
321 if (!callback_.is_null()) 338 if (!callback_.is_null())
322 callback_.Run(); 339 callback_.Run();
323 } 340 }
324 341
325 CloudPolicyCoreStatusProvider::CloudPolicyCoreStatusProvider( 342 CloudPolicyCoreStatusProvider::CloudPolicyCoreStatusProvider(
326 policy::CloudPolicyCore* core) : core_(core) { 343 policy::CloudPolicyCore* core) : core_(core) {
327 core_->store()->AddObserver(this); 344 core_->store()->AddObserver(this);
328 // TODO(bartfab): Add an observer that watches for client errors. Observing 345 // TODO(bartfab): Add an observer that watches for client errors. Observing
329 // core_->client() directly is not safe as the client may be destroyed and 346 // core_->client() directly is not safe as the client may be destroyed and
330 // (re-)created anytime if the user signs in or out on desktop platforms. 347 // (re-)created anytime if the user signs in or out on desktop platforms.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 424
408 void DeviceLocalAccountPolicyStatusProvider::OnPolicyUpdated( 425 void DeviceLocalAccountPolicyStatusProvider::OnPolicyUpdated(
409 const std::string& user_id) { 426 const std::string& user_id) {
410 if (user_id == user_id_) 427 if (user_id == user_id_)
411 NotifyStatusChange(); 428 NotifyStatusChange();
412 } 429 }
413 430
414 void DeviceLocalAccountPolicyStatusProvider::OnDeviceLocalAccountsChanged() { 431 void DeviceLocalAccountPolicyStatusProvider::OnDeviceLocalAccountsChanged() {
415 NotifyStatusChange(); 432 NotifyStatusChange();
416 } 433 }
417 #endif 434
435 DeviceActiveDirectoryPolicyStatusProvider::
436 DeviceActiveDirectoryPolicyStatusProvider(
437 policy::DeviceActiveDirectoryPolicyManager* manager)
438 : store_(manager->store()) {}
439
440 DeviceActiveDirectoryPolicyStatusProvider::
441 ~DeviceActiveDirectoryPolicyStatusProvider() {}
442
443 // TODO(tnagel): Provide more details and/or remove unused fields from UI. See
444 // https://crbug.com/664747.
445 void DeviceActiveDirectoryPolicyStatusProvider::GetStatus(
446 base::DictionaryValue* dict) {
447 base::string16 status =
448 policy::FormatStoreStatus(store_->status(), store_->validation_status());
449 dict->SetString("status", status);
450 }
451
452 #endif // defined(OS_CHROMEOS)
418 453
419 PolicyUIHandler::PolicyUIHandler() 454 PolicyUIHandler::PolicyUIHandler()
420 : weak_factory_(this) { 455 : weak_factory_(this) {
421 } 456 }
422 457
423 PolicyUIHandler::~PolicyUIHandler() { 458 PolicyUIHandler::~PolicyUIHandler() {
424 GetPolicyService()->RemoveObserver(policy::POLICY_DOMAIN_CHROME, this); 459 GetPolicyService()->RemoveObserver(policy::POLICY_DOMAIN_CHROME, this);
425 GetPolicyService()->RemoveObserver(policy::POLICY_DOMAIN_EXTENSIONS, this); 460 GetPolicyService()->RemoveObserver(policy::POLICY_DOMAIN_EXTENSIONS, this);
426 policy::SchemaRegistry* registry = 461 policy::SchemaRegistry* registry =
427 policy::SchemaRegistryServiceFactory::GetForContext( 462 policy::SchemaRegistryServiceFactory::GetForContext(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 source->AddLocalizedString("unset", IDS_POLICY_UNSET); 496 source->AddLocalizedString("unset", IDS_POLICY_UNSET);
462 source->AddLocalizedString("unknown", IDS_POLICY_UNKNOWN); 497 source->AddLocalizedString("unknown", IDS_POLICY_UNKNOWN);
463 source->AddLocalizedString("notSpecified", IDS_POLICY_NOT_SPECIFIED); 498 source->AddLocalizedString("notSpecified", IDS_POLICY_NOT_SPECIFIED);
464 source->SetJsonPath("strings.js"); 499 source->SetJsonPath("strings.js");
465 } 500 }
466 501
467 void PolicyUIHandler::RegisterMessages() { 502 void PolicyUIHandler::RegisterMessages() {
468 #if defined(OS_CHROMEOS) 503 #if defined(OS_CHROMEOS)
469 policy::BrowserPolicyConnectorChromeOS* connector = 504 policy::BrowserPolicyConnectorChromeOS* connector =
470 g_browser_process->platform_part()->browser_policy_connector_chromeos(); 505 g_browser_process->platform_part()->browser_policy_connector_chromeos();
471 if (connector->IsEnterpriseManaged()) 506 if (connector->IsEnterpriseManaged()) {
472 device_status_provider_.reset(new DevicePolicyStatusProvider(connector)); 507 if (connector->GetDeviceActiveDirectoryPolicyManager()) {
508 device_status_provider_ =
509 base::MakeUnique<DeviceActiveDirectoryPolicyStatusProvider>(
510 connector->GetDeviceActiveDirectoryPolicyManager());
511 } else {
512 device_status_provider_ =
513 base::MakeUnique<DevicePolicyStatusProvider>(connector);
514 }
515 }
473 516
474 const user_manager::UserManager* user_manager = 517 const user_manager::UserManager* user_manager =
475 user_manager::UserManager::Get(); 518 user_manager::UserManager::Get();
476 if (user_manager->IsLoggedInAsPublicAccount()) { 519 if (user_manager->IsLoggedInAsPublicAccount()) {
477 policy::DeviceLocalAccountPolicyService* local_account_service = 520 policy::DeviceLocalAccountPolicyService* local_account_service =
478 connector->GetDeviceLocalAccountPolicyService(); 521 connector->GetDeviceLocalAccountPolicyService();
479 if (local_account_service) { 522 if (local_account_service) {
480 user_status_provider_.reset(new DeviceLocalAccountPolicyStatusProvider( 523 user_status_provider_ =
481 user_manager->GetActiveUser()->GetAccountId().GetUserEmail(), 524 base::MakeUnique<DeviceLocalAccountPolicyStatusProvider>(
482 local_account_service)); 525 user_manager->GetActiveUser()->GetAccountId().GetUserEmail(),
526 local_account_service);
483 } 527 }
484 } else { 528 } else {
485 policy::UserCloudPolicyManagerChromeOS* user_cloud_policy_manager = 529 policy::UserCloudPolicyManagerChromeOS* user_cloud_policy_manager =
486 policy::UserCloudPolicyManagerFactoryChromeOS::GetForProfile( 530 policy::UserCloudPolicyManagerFactoryChromeOS::GetForProfile(
487 Profile::FromWebUI(web_ui())); 531 Profile::FromWebUI(web_ui()));
488 if (user_cloud_policy_manager) { 532 if (user_cloud_policy_manager) {
489 user_status_provider_.reset( 533 user_status_provider_ =
490 new UserPolicyStatusProvider(user_cloud_policy_manager->core())); 534 base::MakeUnique<UserPolicyStatusProvider>(
535 user_cloud_policy_manager->core());
491 } 536 }
492 } 537 }
493 #else 538 #else
494 policy::UserCloudPolicyManager* user_cloud_policy_manager = 539 policy::UserCloudPolicyManager* user_cloud_policy_manager =
495 policy::UserCloudPolicyManagerFactory::GetForBrowserContext( 540 policy::UserCloudPolicyManagerFactory::GetForBrowserContext(
496 web_ui()->GetWebContents()->GetBrowserContext()); 541 web_ui()->GetWebContents()->GetBrowserContext());
497 if (user_cloud_policy_manager) { 542 if (user_cloud_policy_manager) {
498 user_status_provider_.reset( 543 user_status_provider_ = base::MakeUnique<UserPolicyStatusProvider>(
499 new UserPolicyStatusProvider(user_cloud_policy_manager->core())); 544 user_cloud_policy_manager->core());
500 } 545 }
501 #endif 546 #endif
502 547
503 if (!user_status_provider_.get()) 548 if (!user_status_provider_.get())
504 user_status_provider_.reset(new CloudPolicyStatusProvider()); 549 user_status_provider_ = base::MakeUnique<PolicyStatusProvider>();
505 if (!device_status_provider_.get()) 550 if (!device_status_provider_.get())
506 device_status_provider_.reset(new CloudPolicyStatusProvider()); 551 device_status_provider_ = base::MakeUnique<PolicyStatusProvider>();
507 552
508 base::Closure update_callback(base::Bind(&PolicyUIHandler::SendStatus, 553 base::Closure update_callback(base::Bind(&PolicyUIHandler::SendStatus,
509 base::Unretained(this))); 554 base::Unretained(this)));
510 user_status_provider_->SetStatusChangeCallback(update_callback); 555 user_status_provider_->SetStatusChangeCallback(update_callback);
511 device_status_provider_->SetStatusChangeCallback(update_callback); 556 device_status_provider_->SetStatusChangeCallback(update_callback);
512 GetPolicyService()->AddObserver(policy::POLICY_DOMAIN_CHROME, this); 557 GetPolicyService()->AddObserver(policy::POLICY_DOMAIN_CHROME, this);
513 GetPolicyService()->AddObserver(policy::POLICY_DOMAIN_EXTENSIONS, this); 558 GetPolicyService()->AddObserver(policy::POLICY_DOMAIN_EXTENSIONS, this);
514 559
515 #if BUILDFLAG(ENABLE_EXTENSIONS) 560 #if BUILDFLAG(ENABLE_EXTENSIONS)
516 extensions::ExtensionRegistry::Get(Profile::FromWebUI(web_ui())) 561 extensions::ExtensionRegistry::Get(Profile::FromWebUI(web_ui()))
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 SendPolicyValues(); 768 SendPolicyValues();
724 SendStatus(); 769 SendStatus();
725 } 770 }
726 771
727 void PolicyUIHandler::HandleReloadPolicies(const base::ListValue* args) { 772 void PolicyUIHandler::HandleReloadPolicies(const base::ListValue* args) {
728 #if defined(OS_CHROMEOS) 773 #if defined(OS_CHROMEOS)
729 // Allow user to manually fetch remote commands, in case invalidation 774 // Allow user to manually fetch remote commands, in case invalidation
730 // service is not working properly. 775 // service is not working properly.
731 // TODO(binjin): evaluate and possibly remove this after invalidation 776 // TODO(binjin): evaluate and possibly remove this after invalidation
732 // service is landed and tested. http://crbug.com/480982 777 // service is landed and tested. http://crbug.com/480982
733 policy::BrowserPolicyConnectorChromeOS* connector = 778 policy::CloudPolicyManager* manager =
734 g_browser_process->platform_part()->browser_policy_connector_chromeos(); 779 g_browser_process->platform_part()
735 policy::RemoteCommandsService* remote_commands_service = 780 ->browser_policy_connector_chromeos()
736 connector->GetDeviceCloudPolicyManager() 781 ->GetDeviceCloudPolicyManager();
737 ->core() 782 // Active Directory management has no CloudPolicyManager.
738 ->remote_commands_service(); 783 if (manager) {
739 if (remote_commands_service) 784 policy::RemoteCommandsService* remote_commands_service =
740 remote_commands_service->FetchRemoteCommands(); 785 manager->core()->remote_commands_service();
786 if (remote_commands_service)
787 remote_commands_service->FetchRemoteCommands();
788 }
741 #endif 789 #endif
742 GetPolicyService()->RefreshPolicies(base::Bind( 790 GetPolicyService()->RefreshPolicies(base::Bind(
743 &PolicyUIHandler::OnRefreshPoliciesDone, weak_factory_.GetWeakPtr())); 791 &PolicyUIHandler::OnRefreshPoliciesDone, weak_factory_.GetWeakPtr()));
744 } 792 }
745 793
746 void PolicyUIHandler::OnRefreshPoliciesDone() const { 794 void PolicyUIHandler::OnRefreshPoliciesDone() const {
747 web_ui()->CallJavascriptFunctionUnsafe("policy.Page.reloadPoliciesDone"); 795 web_ui()->CallJavascriptFunctionUnsafe("policy.Page.reloadPoliciesDone");
748 } 796 }
749 797
750 policy::PolicyService* PolicyUIHandler::GetPolicyService() const { 798 policy::PolicyService* PolicyUIHandler::GetPolicyService() const {
751 return policy::ProfilePolicyConnectorFactory::GetForBrowserContext( 799 return policy::ProfilePolicyConnectorFactory::GetForBrowserContext(
752 web_ui()->GetWebContents()->GetBrowserContext())->policy_service(); 800 web_ui()->GetWebContents()->GetBrowserContext())->policy_service();
753 } 801 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698