| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #ifndef CHROME_BROWSER_CHROMEOS_ATTESTATION_ATTESTATION_POLICY_OBSERVER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_ATTESTATION_ATTESTATION_POLICY_OBSERVER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_ATTESTATION_ATTESTATION_POLICY_OBSERVER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_ATTESTATION_ATTESTATION_POLICY_OBSERVER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "content/public/browser/notification_observer.h" | 14 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 15 | 15 |
| 16 namespace policy { | 16 namespace policy { |
| 17 class CloudPolicyClient; | 17 class CloudPolicyClient; |
| 18 } | 18 } |
| 19 | 19 |
| 20 namespace chromeos { | 20 namespace chromeos { |
| 21 | 21 |
| 22 class CrosSettings; | 22 class CrosSettings; |
| 23 class CryptohomeClient; | 23 class CryptohomeClient; |
| 24 | 24 |
| 25 namespace attestation { | 25 namespace attestation { |
| 26 | 26 |
| 27 class AttestationFlow; | 27 class AttestationFlow; |
| 28 | 28 |
| 29 // A class which observes policy changes and triggers device attestation work if | 29 // A class which observes policy changes and triggers device attestation work if |
| 30 // necessary. | 30 // necessary. |
| 31 class AttestationPolicyObserver : public content::NotificationObserver { | 31 class AttestationPolicyObserver { |
| 32 public: | 32 public: |
| 33 // The observer immediately connects with CrosSettings to listen for policy | 33 // The observer immediately connects with CrosSettings to listen for policy |
| 34 // changes. The CloudPolicyClient is used to upload the device certificate to | 34 // changes. The CloudPolicyClient is used to upload the device certificate to |
| 35 // the server if one is created in response to policy changes; it must be in | 35 // the server if one is created in response to policy changes; it must be in |
| 36 // the registered state. This class does not take ownership of | 36 // the registered state. This class does not take ownership of |
| 37 // |policy_client|. | 37 // |policy_client|. |
| 38 explicit AttestationPolicyObserver(policy::CloudPolicyClient* policy_client); | 38 explicit AttestationPolicyObserver(policy::CloudPolicyClient* policy_client); |
| 39 | 39 |
| 40 // A constructor which allows custom CryptohomeClient and AttestationFlow | 40 // A constructor which allows custom CryptohomeClient and AttestationFlow |
| 41 // implementations. Useful for testing. | 41 // implementations. Useful for testing. |
| 42 AttestationPolicyObserver(policy::CloudPolicyClient* policy_client, | 42 AttestationPolicyObserver(policy::CloudPolicyClient* policy_client, |
| 43 CryptohomeClient* cryptohome_client, | 43 CryptohomeClient* cryptohome_client, |
| 44 AttestationFlow* attestation_flow); | 44 AttestationFlow* attestation_flow); |
| 45 | 45 |
| 46 virtual ~AttestationPolicyObserver(); | 46 ~AttestationPolicyObserver(); |
| 47 | |
| 48 // content::NotificationObserver: | |
| 49 virtual void Observe(int type, | |
| 50 const content::NotificationSource& source, | |
| 51 const content::NotificationDetails& details) OVERRIDE; | |
| 52 | 47 |
| 53 // Sets the retry delay in seconds; useful in testing. | 48 // Sets the retry delay in seconds; useful in testing. |
| 54 void set_retry_delay(int retry_delay) { | 49 void set_retry_delay(int retry_delay) { |
| 55 retry_delay_ = retry_delay; | 50 retry_delay_ = retry_delay; |
| 56 } | 51 } |
| 57 | 52 |
| 58 private: | 53 private: |
| 54 // Called when the attestation setting changes. |
| 55 void AttestationSettingChanged(); |
| 56 |
| 59 // Checks attestation policy and starts any necessary work. | 57 // Checks attestation policy and starts any necessary work. |
| 60 void Start(); | 58 void Start(); |
| 61 | 59 |
| 62 // Gets a new certificate for the Enterprise Machine Key (EMK). | 60 // Gets a new certificate for the Enterprise Machine Key (EMK). |
| 63 void GetNewCertificate(); | 61 void GetNewCertificate(); |
| 64 | 62 |
| 65 // Gets the existing EMK certificate and sends it to CheckCertificateExpiry. | 63 // Gets the existing EMK certificate and sends it to CheckCertificateExpiry. |
| 66 void GetExistingCertificate(); | 64 void GetExistingCertificate(); |
| 67 | 65 |
| 68 // Checks if the given certificate is expired and, if so, get a new one. | 66 // Checks if the given certificate is expired and, if so, get a new one. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 91 void Reschedule(); | 89 void Reschedule(); |
| 92 | 90 |
| 93 CrosSettings* cros_settings_; | 91 CrosSettings* cros_settings_; |
| 94 policy::CloudPolicyClient* policy_client_; | 92 policy::CloudPolicyClient* policy_client_; |
| 95 CryptohomeClient* cryptohome_client_; | 93 CryptohomeClient* cryptohome_client_; |
| 96 AttestationFlow* attestation_flow_; | 94 AttestationFlow* attestation_flow_; |
| 97 scoped_ptr<AttestationFlow> default_attestation_flow_; | 95 scoped_ptr<AttestationFlow> default_attestation_flow_; |
| 98 int num_retries_; | 96 int num_retries_; |
| 99 int retry_delay_; | 97 int retry_delay_; |
| 100 | 98 |
| 99 scoped_ptr<CrosSettings::ObserverSubscription> attestation_subscription_; |
| 100 |
| 101 // Note: This should remain the last member so it'll be destroyed and | 101 // Note: This should remain the last member so it'll be destroyed and |
| 102 // invalidate the weak pointers before any other members are destroyed. | 102 // invalidate the weak pointers before any other members are destroyed. |
| 103 base::WeakPtrFactory<AttestationPolicyObserver> weak_factory_; | 103 base::WeakPtrFactory<AttestationPolicyObserver> weak_factory_; |
| 104 | 104 |
| 105 DISALLOW_COPY_AND_ASSIGN(AttestationPolicyObserver); | 105 DISALLOW_COPY_AND_ASSIGN(AttestationPolicyObserver); |
| 106 }; | 106 }; |
| 107 | 107 |
| 108 } // namespace attestation | 108 } // namespace attestation |
| 109 } // namespace chromeos | 109 } // namespace chromeos |
| 110 | 110 |
| 111 #endif // CHROME_BROWSER_CHROMEOS_ATTESTATION_ATTESTATION_POLICY_OBSERVER_H_ | 111 #endif // CHROME_BROWSER_CHROMEOS_ATTESTATION_ATTESTATION_POLICY_OBSERVER_H_ |
| OLD | NEW |