| 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.h" | 5 #include "chrome/browser/ui/webui/policy_ui.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 | 269 |
| 270 // policy::CloudPolicyStore::Observer implementation. | 270 // policy::CloudPolicyStore::Observer implementation. |
| 271 virtual void OnStoreLoaded(policy::CloudPolicyStore* store) override; | 271 virtual void OnStoreLoaded(policy::CloudPolicyStore* store) override; |
| 272 virtual void OnStoreError(policy::CloudPolicyStore* store) override; | 272 virtual void OnStoreError(policy::CloudPolicyStore* store) override; |
| 273 | 273 |
| 274 protected: | 274 protected: |
| 275 // Policy status is read from the CloudPolicyClient, CloudPolicyStore and | 275 // Policy status is read from the CloudPolicyClient, CloudPolicyStore and |
| 276 // CloudPolicyRefreshScheduler hosted by this |core_|. | 276 // CloudPolicyRefreshScheduler hosted by this |core_|. |
| 277 policy::CloudPolicyCore* core_; | 277 policy::CloudPolicyCore* core_; |
| 278 | 278 |
| 279 private: |
| 279 DISALLOW_COPY_AND_ASSIGN(CloudPolicyCoreStatusProvider); | 280 DISALLOW_COPY_AND_ASSIGN(CloudPolicyCoreStatusProvider); |
| 280 }; | 281 }; |
| 281 | 282 |
| 282 // A cloud policy status provider for user policy. | 283 // A cloud policy status provider for user policy. |
| 283 class UserPolicyStatusProvider : public CloudPolicyCoreStatusProvider { | 284 class UserPolicyStatusProvider : public CloudPolicyCoreStatusProvider { |
| 284 public: | 285 public: |
| 285 explicit UserPolicyStatusProvider(policy::CloudPolicyCore* core); | 286 explicit UserPolicyStatusProvider(policy::CloudPolicyCore* core); |
| 286 virtual ~UserPolicyStatusProvider(); | 287 virtual ~UserPolicyStatusProvider(); |
| 287 | 288 |
| 288 // CloudPolicyCoreStatusProvider implementation. | 289 // CloudPolicyCoreStatusProvider implementation. |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 | 392 |
| 392 bool initialized_; | 393 bool initialized_; |
| 393 std::string device_domain_; | 394 std::string device_domain_; |
| 394 | 395 |
| 395 // Providers that supply status dictionaries for user and device policy, | 396 // Providers that supply status dictionaries for user and device policy, |
| 396 // respectively. These are created on initialization time as appropriate for | 397 // respectively. These are created on initialization time as appropriate for |
| 397 // the platform (Chrome OS / desktop) and type of policy that is in effect. | 398 // the platform (Chrome OS / desktop) and type of policy that is in effect. |
| 398 scoped_ptr<CloudPolicyStatusProvider> user_status_provider_; | 399 scoped_ptr<CloudPolicyStatusProvider> user_status_provider_; |
| 399 scoped_ptr<CloudPolicyStatusProvider> device_status_provider_; | 400 scoped_ptr<CloudPolicyStatusProvider> device_status_provider_; |
| 400 | 401 |
| 402 #if defined(ENABLE_EXTENSIONS) |
| 401 content::NotificationRegistrar registrar_; | 403 content::NotificationRegistrar registrar_; |
| 404 #endif |
| 402 | 405 |
| 403 base::WeakPtrFactory<PolicyUIHandler> weak_factory_; | 406 base::WeakPtrFactory<PolicyUIHandler> weak_factory_; |
| 404 | 407 |
| 405 DISALLOW_COPY_AND_ASSIGN(PolicyUIHandler); | 408 DISALLOW_COPY_AND_ASSIGN(PolicyUIHandler); |
| 406 }; | 409 }; |
| 407 | 410 |
| 408 CloudPolicyStatusProvider::CloudPolicyStatusProvider() { | 411 CloudPolicyStatusProvider::CloudPolicyStatusProvider() { |
| 409 } | 412 } |
| 410 | 413 |
| 411 CloudPolicyStatusProvider::~CloudPolicyStatusProvider() { | 414 CloudPolicyStatusProvider::~CloudPolicyStatusProvider() { |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 if (!device_status_provider_.get()) | 572 if (!device_status_provider_.get()) |
| 570 device_status_provider_.reset(new CloudPolicyStatusProvider()); | 573 device_status_provider_.reset(new CloudPolicyStatusProvider()); |
| 571 | 574 |
| 572 base::Closure update_callback(base::Bind(&PolicyUIHandler::SendStatus, | 575 base::Closure update_callback(base::Bind(&PolicyUIHandler::SendStatus, |
| 573 base::Unretained(this))); | 576 base::Unretained(this))); |
| 574 user_status_provider_->SetStatusChangeCallback(update_callback); | 577 user_status_provider_->SetStatusChangeCallback(update_callback); |
| 575 device_status_provider_->SetStatusChangeCallback(update_callback); | 578 device_status_provider_->SetStatusChangeCallback(update_callback); |
| 576 GetPolicyService()->AddObserver(policy::POLICY_DOMAIN_CHROME, this); | 579 GetPolicyService()->AddObserver(policy::POLICY_DOMAIN_CHROME, this); |
| 577 GetPolicyService()->AddObserver(policy::POLICY_DOMAIN_EXTENSIONS, this); | 580 GetPolicyService()->AddObserver(policy::POLICY_DOMAIN_EXTENSIONS, this); |
| 578 | 581 |
| 582 #if defined(ENABLE_EXTENSIONS) |
| 579 registrar_.Add(this, | 583 registrar_.Add(this, |
| 580 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, | 584 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, |
| 581 content::NotificationService::AllSources()); | 585 content::NotificationService::AllSources()); |
| 582 registrar_.Add(this, | 586 registrar_.Add(this, |
| 583 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, | 587 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, |
| 584 content::NotificationService::AllSources()); | 588 content::NotificationService::AllSources()); |
| 589 #endif |
| 585 | 590 |
| 586 web_ui()->RegisterMessageCallback( | 591 web_ui()->RegisterMessageCallback( |
| 587 "initialized", | 592 "initialized", |
| 588 base::Bind(&PolicyUIHandler::HandleInitialized, base::Unretained(this))); | 593 base::Bind(&PolicyUIHandler::HandleInitialized, base::Unretained(this))); |
| 589 web_ui()->RegisterMessageCallback( | 594 web_ui()->RegisterMessageCallback( |
| 590 "reloadPolicies", | 595 "reloadPolicies", |
| 591 base::Bind(&PolicyUIHandler::HandleReloadPolicies, | 596 base::Bind(&PolicyUIHandler::HandleReloadPolicies, |
| 592 base::Unretained(this))); | 597 base::Unretained(this))); |
| 593 } | 598 } |
| 594 | 599 |
| 595 void PolicyUIHandler::Observe(int type, | 600 void PolicyUIHandler::Observe(int type, |
| 596 const content::NotificationSource& source, | 601 const content::NotificationSource& source, |
| 597 const content::NotificationDetails& details) { | 602 const content::NotificationDetails& details) { |
| 603 #if defined(ENABLE_EXTENSIONS) |
| 598 DCHECK(type == extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED || | 604 DCHECK(type == extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED || |
| 599 type == extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED); | 605 type == extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED); |
| 600 SendPolicyNames(); | 606 SendPolicyNames(); |
| 601 SendPolicyValues(); | 607 SendPolicyValues(); |
| 608 #endif |
| 602 } | 609 } |
| 603 | 610 |
| 604 void PolicyUIHandler::OnPolicyUpdated(const policy::PolicyNamespace& ns, | 611 void PolicyUIHandler::OnPolicyUpdated(const policy::PolicyNamespace& ns, |
| 605 const policy::PolicyMap& previous, | 612 const policy::PolicyMap& previous, |
| 606 const policy::PolicyMap& current) { | 613 const policy::PolicyMap& current) { |
| 607 SendPolicyValues(); | 614 SendPolicyValues(); |
| 608 } | 615 } |
| 609 | 616 |
| 610 void PolicyUIHandler::SendPolicyNames() const { | 617 void PolicyUIHandler::SendPolicyNames() const { |
| 611 base::DictionaryValue names; | 618 base::DictionaryValue names; |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 788 } | 795 } |
| 789 | 796 |
| 790 PolicyUI::PolicyUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 797 PolicyUI::PolicyUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
| 791 web_ui->AddMessageHandler(new PolicyUIHandler); | 798 web_ui->AddMessageHandler(new PolicyUIHandler); |
| 792 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), | 799 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), |
| 793 CreatePolicyUIHTMLSource()); | 800 CreatePolicyUIHTMLSource()); |
| 794 } | 801 } |
| 795 | 802 |
| 796 PolicyUI::~PolicyUI() { | 803 PolicyUI::~PolicyUI() { |
| 797 } | 804 } |
| OLD | NEW |