| OLD | NEW |
| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 #include "google_apis/gaia/gaia_auth_util.h" | 52 #include "google_apis/gaia/gaia_auth_util.h" |
| 53 #include "ui/base/l10n/l10n_util.h" | 53 #include "ui/base/l10n/l10n_util.h" |
| 54 #include "ui/base/l10n/time_format.h" | 54 #include "ui/base/l10n/time_format.h" |
| 55 | 55 |
| 56 #if defined(OS_CHROMEOS) | 56 #if defined(OS_CHROMEOS) |
| 57 #include "chrome/browser/browser_process_platform_part.h" | 57 #include "chrome/browser/browser_process_platform_part.h" |
| 58 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 58 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 59 #include "chrome/browser/chromeos/policy/device_active_directory_policy_manager.
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" | 60 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" |
| 61 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" | 61 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" |
| 62 #include "chrome/browser/chromeos/policy/user_active_directory_policy_manager.h" |
| 62 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" | 63 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" |
| 63 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom
eos.h" | 64 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom
eos.h" |
| 64 #include "chrome/browser/chromeos/settings/install_attributes.h" | 65 #include "chrome/browser/chromeos/settings/install_attributes.h" |
| 65 #include "components/user_manager/user_manager.h" | 66 #include "components/user_manager/user_manager.h" |
| 66 #else | 67 #else |
| 67 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" | 68 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" |
| 68 #include "components/policy/core/common/cloud/user_cloud_policy_manager.h" | 69 #include "components/policy/core/common/cloud/user_cloud_policy_manager.h" |
| 69 #endif | 70 #endif |
| 70 | 71 |
| 71 #if BUILDFLAG(ENABLE_EXTENSIONS) | 72 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 protected: | 244 protected: |
| 244 // Policy status is read from the CloudPolicyClient, CloudPolicyStore and | 245 // Policy status is read from the CloudPolicyClient, CloudPolicyStore and |
| 245 // CloudPolicyRefreshScheduler hosted by this |core_|. | 246 // CloudPolicyRefreshScheduler hosted by this |core_|. |
| 246 policy::CloudPolicyCore* core_; | 247 policy::CloudPolicyCore* core_; |
| 247 | 248 |
| 248 private: | 249 private: |
| 249 DISALLOW_COPY_AND_ASSIGN(CloudPolicyCoreStatusProvider); | 250 DISALLOW_COPY_AND_ASSIGN(CloudPolicyCoreStatusProvider); |
| 250 }; | 251 }; |
| 251 | 252 |
| 252 // A cloud policy status provider for user policy. | 253 // A cloud policy status provider for user policy. |
| 253 class UserPolicyStatusProvider : public CloudPolicyCoreStatusProvider { | 254 class UserCloudPolicyStatusProvider : public CloudPolicyCoreStatusProvider { |
| 254 public: | 255 public: |
| 255 explicit UserPolicyStatusProvider(policy::CloudPolicyCore* core); | 256 explicit UserCloudPolicyStatusProvider(policy::CloudPolicyCore* core); |
| 256 ~UserPolicyStatusProvider() override; | 257 ~UserCloudPolicyStatusProvider() override; |
| 257 | 258 |
| 258 // CloudPolicyCoreStatusProvider implementation. | 259 // CloudPolicyCoreStatusProvider implementation. |
| 259 void GetStatus(base::DictionaryValue* dict) override; | 260 void GetStatus(base::DictionaryValue* dict) override; |
| 260 | 261 |
| 261 private: | 262 private: |
| 262 DISALLOW_COPY_AND_ASSIGN(UserPolicyStatusProvider); | 263 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyStatusProvider); |
| 263 }; | 264 }; |
| 264 | 265 |
| 265 #if defined(OS_CHROMEOS) | 266 #if defined(OS_CHROMEOS) |
| 266 // A cloud policy status provider for device policy. | 267 // A cloud policy status provider for device policy. |
| 267 class DevicePolicyStatusProvider : public CloudPolicyCoreStatusProvider { | 268 class DevicePolicyStatusProvider : public CloudPolicyCoreStatusProvider { |
| 268 public: | 269 public: |
| 269 explicit DevicePolicyStatusProvider( | 270 explicit DevicePolicyStatusProvider( |
| 270 policy::BrowserPolicyConnectorChromeOS* connector); | 271 policy::BrowserPolicyConnectorChromeOS* connector); |
| 271 ~DevicePolicyStatusProvider() override; | 272 ~DevicePolicyStatusProvider() override; |
| 272 | 273 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 301 void OnPolicyUpdated(const std::string& user_id) override; | 302 void OnPolicyUpdated(const std::string& user_id) override; |
| 302 void OnDeviceLocalAccountsChanged() override; | 303 void OnDeviceLocalAccountsChanged() override; |
| 303 | 304 |
| 304 private: | 305 private: |
| 305 const std::string user_id_; | 306 const std::string user_id_; |
| 306 policy::DeviceLocalAccountPolicyService* service_; | 307 policy::DeviceLocalAccountPolicyService* service_; |
| 307 | 308 |
| 308 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyStatusProvider); | 309 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyStatusProvider); |
| 309 }; | 310 }; |
| 310 | 311 |
| 311 // Provides status for DeviceActiveDirectoryPolicyManager. | 312 // Provides status for any Active Directory policy manager. |
| 312 class DeviceActiveDirectoryPolicyStatusProvider | 313 class ActiveDirectoryPolicyStatusProvider |
| 313 : public PolicyStatusProvider, | 314 : public PolicyStatusProvider, |
| 314 public policy::CloudPolicyStore::Observer { | 315 public policy::CloudPolicyStore::Observer { |
| 315 public: | 316 public: |
| 316 explicit DeviceActiveDirectoryPolicyStatusProvider( | 317 explicit ActiveDirectoryPolicyStatusProvider(policy::CloudPolicyStore* store); |
| 317 policy::DeviceActiveDirectoryPolicyManager* manager); | 318 ~ActiveDirectoryPolicyStatusProvider() override; |
| 318 ~DeviceActiveDirectoryPolicyStatusProvider() override; | |
| 319 | 319 |
| 320 // PolicyStatusProvider implementation. | 320 // PolicyStatusProvider implementation. |
| 321 void GetStatus(base::DictionaryValue* dict) override; | 321 void GetStatus(base::DictionaryValue* dict) override; |
| 322 | 322 |
| 323 // policy::CloudPolicyStore::Observer implementation. | 323 // policy::CloudPolicyStore::Observer implementation. |
| 324 void OnStoreLoaded(policy::CloudPolicyStore* store) override; | 324 void OnStoreLoaded(policy::CloudPolicyStore* store) override; |
| 325 void OnStoreError(policy::CloudPolicyStore* store) override; | 325 void OnStoreError(policy::CloudPolicyStore* store) override; |
| 326 | 326 |
| 327 private: | 327 private: |
| 328 policy::CloudPolicyStore* store_; | 328 policy::CloudPolicyStore* store_; |
| 329 | 329 |
| 330 DISALLOW_COPY_AND_ASSIGN(DeviceActiveDirectoryPolicyStatusProvider); | 330 DISALLOW_COPY_AND_ASSIGN(ActiveDirectoryPolicyStatusProvider); |
| 331 }; | 331 }; |
| 332 #endif | 332 #endif |
| 333 | 333 |
| 334 PolicyStatusProvider::PolicyStatusProvider() {} | 334 PolicyStatusProvider::PolicyStatusProvider() {} |
| 335 | 335 |
| 336 PolicyStatusProvider::~PolicyStatusProvider() {} | 336 PolicyStatusProvider::~PolicyStatusProvider() {} |
| 337 | 337 |
| 338 void PolicyStatusProvider::SetStatusChangeCallback( | 338 void PolicyStatusProvider::SetStatusChangeCallback( |
| 339 const base::Closure& callback) { | 339 const base::Closure& callback) { |
| 340 callback_ = callback; | 340 callback_ = callback; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 362 void CloudPolicyCoreStatusProvider::OnStoreLoaded( | 362 void CloudPolicyCoreStatusProvider::OnStoreLoaded( |
| 363 policy::CloudPolicyStore* store) { | 363 policy::CloudPolicyStore* store) { |
| 364 NotifyStatusChange(); | 364 NotifyStatusChange(); |
| 365 } | 365 } |
| 366 | 366 |
| 367 void CloudPolicyCoreStatusProvider::OnStoreError( | 367 void CloudPolicyCoreStatusProvider::OnStoreError( |
| 368 policy::CloudPolicyStore* store) { | 368 policy::CloudPolicyStore* store) { |
| 369 NotifyStatusChange(); | 369 NotifyStatusChange(); |
| 370 } | 370 } |
| 371 | 371 |
| 372 UserPolicyStatusProvider::UserPolicyStatusProvider( | 372 UserCloudPolicyStatusProvider::UserCloudPolicyStatusProvider( |
| 373 policy::CloudPolicyCore* core) : CloudPolicyCoreStatusProvider(core) { | 373 policy::CloudPolicyCore* core) |
| 374 } | 374 : CloudPolicyCoreStatusProvider(core) {} |
| 375 | 375 |
| 376 UserPolicyStatusProvider::~UserPolicyStatusProvider() { | 376 UserCloudPolicyStatusProvider::~UserCloudPolicyStatusProvider() {} |
| 377 } | |
| 378 | 377 |
| 379 void UserPolicyStatusProvider::GetStatus(base::DictionaryValue* dict) { | 378 void UserCloudPolicyStatusProvider::GetStatus(base::DictionaryValue* dict) { |
| 380 if (!core_->store()->is_managed()) | 379 if (!core_->store()->is_managed()) |
| 381 return; | 380 return; |
| 382 GetStatusFromCore(core_, dict); | 381 GetStatusFromCore(core_, dict); |
| 383 ExtractDomainFromUsername(dict); | 382 ExtractDomainFromUsername(dict); |
| 384 } | 383 } |
| 385 | 384 |
| 386 #if defined(OS_CHROMEOS) | 385 #if defined(OS_CHROMEOS) |
| 387 DevicePolicyStatusProvider::DevicePolicyStatusProvider( | 386 DevicePolicyStatusProvider::DevicePolicyStatusProvider( |
| 388 policy::BrowserPolicyConnectorChromeOS* connector) | 387 policy::BrowserPolicyConnectorChromeOS* connector) |
| 389 : CloudPolicyCoreStatusProvider( | 388 : CloudPolicyCoreStatusProvider( |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 void DeviceLocalAccountPolicyStatusProvider::OnPolicyUpdated( | 432 void DeviceLocalAccountPolicyStatusProvider::OnPolicyUpdated( |
| 434 const std::string& user_id) { | 433 const std::string& user_id) { |
| 435 if (user_id == user_id_) | 434 if (user_id == user_id_) |
| 436 NotifyStatusChange(); | 435 NotifyStatusChange(); |
| 437 } | 436 } |
| 438 | 437 |
| 439 void DeviceLocalAccountPolicyStatusProvider::OnDeviceLocalAccountsChanged() { | 438 void DeviceLocalAccountPolicyStatusProvider::OnDeviceLocalAccountsChanged() { |
| 440 NotifyStatusChange(); | 439 NotifyStatusChange(); |
| 441 } | 440 } |
| 442 | 441 |
| 443 DeviceActiveDirectoryPolicyStatusProvider:: | 442 ActiveDirectoryPolicyStatusProvider::ActiveDirectoryPolicyStatusProvider( |
| 444 DeviceActiveDirectoryPolicyStatusProvider( | 443 policy::CloudPolicyStore* store) |
| 445 policy::DeviceActiveDirectoryPolicyManager* manager) | 444 : store_(store) { |
| 446 : store_(manager->store()) { | |
| 447 store_->AddObserver(this); | 445 store_->AddObserver(this); |
| 448 } | 446 } |
| 449 | 447 |
| 450 DeviceActiveDirectoryPolicyStatusProvider:: | 448 ActiveDirectoryPolicyStatusProvider::~ActiveDirectoryPolicyStatusProvider() { |
| 451 ~DeviceActiveDirectoryPolicyStatusProvider() { | |
| 452 store_->RemoveObserver(this); | 449 store_->RemoveObserver(this); |
| 453 } | 450 } |
| 454 | 451 |
| 455 // TODO(tnagel): Provide more details and/or remove unused fields from UI. See | 452 // TODO(tnagel): Provide more details and/or remove unused fields from UI. See |
| 456 // https://crbug.com/664747. | 453 // https://crbug.com/664747. |
| 457 void DeviceActiveDirectoryPolicyStatusProvider::GetStatus( | 454 void ActiveDirectoryPolicyStatusProvider::GetStatus( |
| 458 base::DictionaryValue* dict) { | 455 base::DictionaryValue* dict) { |
| 459 base::string16 status = | 456 base::string16 status = |
| 460 policy::FormatStoreStatus(store_->status(), store_->validation_status()); | 457 policy::FormatStoreStatus(store_->status(), store_->validation_status()); |
| 461 dict->SetString("status", status); | 458 dict->SetString("status", status); |
| 462 } | 459 } |
| 463 | 460 |
| 464 void DeviceActiveDirectoryPolicyStatusProvider::OnStoreLoaded( | 461 void ActiveDirectoryPolicyStatusProvider::OnStoreLoaded( |
| 465 policy::CloudPolicyStore* store) { | 462 policy::CloudPolicyStore* store) { |
| 466 NotifyStatusChange(); | 463 NotifyStatusChange(); |
| 467 } | 464 } |
| 468 | 465 |
| 469 void DeviceActiveDirectoryPolicyStatusProvider::OnStoreError( | 466 void ActiveDirectoryPolicyStatusProvider::OnStoreError( |
| 470 policy::CloudPolicyStore* store) { | 467 policy::CloudPolicyStore* store) { |
| 471 NotifyStatusChange(); | 468 NotifyStatusChange(); |
| 472 } | 469 } |
| 473 | 470 |
| 474 #endif // defined(OS_CHROMEOS) | 471 #endif // defined(OS_CHROMEOS) |
| 475 | 472 |
| 476 PolicyUIHandler::PolicyUIHandler() | 473 PolicyUIHandler::PolicyUIHandler() |
| 477 : weak_factory_(this) { | 474 : weak_factory_(this) { |
| 478 } | 475 } |
| 479 | 476 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 source->SetJsonPath("strings.js"); | 518 source->SetJsonPath("strings.js"); |
| 522 } | 519 } |
| 523 | 520 |
| 524 void PolicyUIHandler::RegisterMessages() { | 521 void PolicyUIHandler::RegisterMessages() { |
| 525 #if defined(OS_CHROMEOS) | 522 #if defined(OS_CHROMEOS) |
| 526 policy::BrowserPolicyConnectorChromeOS* connector = | 523 policy::BrowserPolicyConnectorChromeOS* connector = |
| 527 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 524 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 528 if (connector->IsEnterpriseManaged()) { | 525 if (connector->IsEnterpriseManaged()) { |
| 529 if (connector->GetDeviceActiveDirectoryPolicyManager()) { | 526 if (connector->GetDeviceActiveDirectoryPolicyManager()) { |
| 530 device_status_provider_ = | 527 device_status_provider_ = |
| 531 base::MakeUnique<DeviceActiveDirectoryPolicyStatusProvider>( | 528 base::MakeUnique<ActiveDirectoryPolicyStatusProvider>( |
| 532 connector->GetDeviceActiveDirectoryPolicyManager()); | 529 connector->GetDeviceActiveDirectoryPolicyManager()->store()); |
| 533 } else { | 530 } else { |
| 534 device_status_provider_ = | 531 device_status_provider_ = |
| 535 base::MakeUnique<DevicePolicyStatusProvider>(connector); | 532 base::MakeUnique<DevicePolicyStatusProvider>(connector); |
| 536 } | 533 } |
| 537 } | 534 } |
| 538 | 535 |
| 539 const user_manager::UserManager* user_manager = | 536 const user_manager::UserManager* user_manager = |
| 540 user_manager::UserManager::Get(); | 537 user_manager::UserManager::Get(); |
| 541 if (user_manager->IsLoggedInAsPublicAccount()) { | 538 if (user_manager->IsLoggedInAsPublicAccount()) { |
| 542 policy::DeviceLocalAccountPolicyService* local_account_service = | 539 policy::DeviceLocalAccountPolicyService* local_account_service = |
| 543 connector->GetDeviceLocalAccountPolicyService(); | 540 connector->GetDeviceLocalAccountPolicyService(); |
| 544 if (local_account_service) { | 541 if (local_account_service) { |
| 545 user_status_provider_ = | 542 user_status_provider_ = |
| 546 base::MakeUnique<DeviceLocalAccountPolicyStatusProvider>( | 543 base::MakeUnique<DeviceLocalAccountPolicyStatusProvider>( |
| 547 user_manager->GetActiveUser()->GetAccountId().GetUserEmail(), | 544 user_manager->GetActiveUser()->GetAccountId().GetUserEmail(), |
| 548 local_account_service); | 545 local_account_service); |
| 549 } | 546 } |
| 550 } else { | 547 } else { |
| 551 policy::UserCloudPolicyManagerChromeOS* user_cloud_policy_manager = | 548 Profile* profile = Profile::FromWebUI(web_ui()); |
| 552 policy::UserCloudPolicyManagerFactoryChromeOS::GetForProfile( | 549 policy::UserCloudPolicyManagerChromeOS* user_cloud_policy = |
| 553 Profile::FromWebUI(web_ui())); | 550 policy::UserCloudPolicyManagerFactoryChromeOS:: |
| 554 if (user_cloud_policy_manager) { | 551 GetCloudPolicyManagerForProfile(profile); |
| 555 user_status_provider_ = | 552 if (user_cloud_policy) { |
| 556 base::MakeUnique<UserPolicyStatusProvider>( | 553 user_status_provider_ = base::MakeUnique<UserCloudPolicyStatusProvider>( |
| 557 user_cloud_policy_manager->core()); | 554 user_cloud_policy->core()); |
| 555 } else { |
| 556 policy::UserActiveDirectoryPolicyManager* active_directory_policy = |
| 557 policy::UserCloudPolicyManagerFactoryChromeOS:: |
| 558 GetActiveDirectoryPolicyManagerForProfile(profile); |
| 559 if (active_directory_policy) { |
| 560 user_status_provider_ = |
| 561 base::MakeUnique<ActiveDirectoryPolicyStatusProvider>( |
| 562 active_directory_policy->store()); |
| 563 } |
| 558 } | 564 } |
| 559 } | 565 } |
| 560 #else | 566 #else |
| 561 policy::UserCloudPolicyManager* user_cloud_policy_manager = | 567 policy::UserCloudPolicyManager* user_cloud_policy_manager = |
| 562 policy::UserCloudPolicyManagerFactory::GetForBrowserContext( | 568 policy::UserCloudPolicyManagerFactory::GetForBrowserContext( |
| 563 web_ui()->GetWebContents()->GetBrowserContext()); | 569 web_ui()->GetWebContents()->GetBrowserContext()); |
| 564 if (user_cloud_policy_manager) { | 570 if (user_cloud_policy_manager) { |
| 565 user_status_provider_ = base::MakeUnique<UserPolicyStatusProvider>( | 571 user_status_provider_ = base::MakeUnique<UserCloudPolicyStatusProvider>( |
| 566 user_cloud_policy_manager->core()); | 572 user_cloud_policy_manager->core()); |
| 567 } | 573 } |
| 568 #endif | 574 #endif |
| 569 | 575 |
| 570 if (!user_status_provider_.get()) | 576 if (!user_status_provider_.get()) |
| 571 user_status_provider_ = base::MakeUnique<PolicyStatusProvider>(); | 577 user_status_provider_ = base::MakeUnique<PolicyStatusProvider>(); |
| 572 if (!device_status_provider_.get()) | 578 if (!device_status_provider_.get()) |
| 573 device_status_provider_ = base::MakeUnique<PolicyStatusProvider>(); | 579 device_status_provider_ = base::MakeUnique<PolicyStatusProvider>(); |
| 574 | 580 |
| 575 base::Closure update_callback(base::Bind(&PolicyUIHandler::SendStatus, | 581 base::Closure update_callback(base::Bind(&PolicyUIHandler::SendStatus, |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 } | 820 } |
| 815 | 821 |
| 816 void PolicyUIHandler::OnRefreshPoliciesDone() const { | 822 void PolicyUIHandler::OnRefreshPoliciesDone() const { |
| 817 web_ui()->CallJavascriptFunctionUnsafe("policy.Page.reloadPoliciesDone"); | 823 web_ui()->CallJavascriptFunctionUnsafe("policy.Page.reloadPoliciesDone"); |
| 818 } | 824 } |
| 819 | 825 |
| 820 policy::PolicyService* PolicyUIHandler::GetPolicyService() const { | 826 policy::PolicyService* PolicyUIHandler::GetPolicyService() const { |
| 821 return policy::ProfilePolicyConnectorFactory::GetForBrowserContext( | 827 return policy::ProfilePolicyConnectorFactory::GetForBrowserContext( |
| 822 web_ui()->GetWebContents()->GetBrowserContext())->policy_service(); | 828 web_ui()->GetWebContents()->GetBrowserContext())->policy_service(); |
| 823 } | 829 } |
| OLD | NEW |