| 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 #include "chrome/browser/chromeos/attestation/attestation_policy_observer.h" | 5 #include "chrome/browser/chromeos/attestation/attestation_policy_observer.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 AttestationPolicyObserver::AttestationPolicyObserver( | 95 AttestationPolicyObserver::AttestationPolicyObserver( |
| 96 policy::CloudPolicyClient* policy_client) | 96 policy::CloudPolicyClient* policy_client) |
| 97 : cros_settings_(CrosSettings::Get()), | 97 : cros_settings_(CrosSettings::Get()), |
| 98 policy_client_(policy_client), | 98 policy_client_(policy_client), |
| 99 cryptohome_client_(NULL), | 99 cryptohome_client_(NULL), |
| 100 attestation_flow_(NULL), | 100 attestation_flow_(NULL), |
| 101 num_retries_(0), | 101 num_retries_(0), |
| 102 retry_delay_(kRetryDelay), | 102 retry_delay_(kRetryDelay), |
| 103 weak_factory_(this) { | 103 weak_factory_(this) { |
| 104 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 104 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 105 cros_settings_->AddSettingsObserver(kDeviceAttestationEnabled, this); | 105 attestation_subscription_ = cros_settings_->AddSettingsObserver( |
| 106 kDeviceAttestationEnabled, |
| 107 base::Bind(&AttestationPolicyObserver::AttestationSettingChanged, |
| 108 base::Unretained(this))); |
| 106 Start(); | 109 Start(); |
| 107 } | 110 } |
| 108 | 111 |
| 109 AttestationPolicyObserver::AttestationPolicyObserver( | 112 AttestationPolicyObserver::AttestationPolicyObserver( |
| 110 policy::CloudPolicyClient* policy_client, | 113 policy::CloudPolicyClient* policy_client, |
| 111 CryptohomeClient* cryptohome_client, | 114 CryptohomeClient* cryptohome_client, |
| 112 AttestationFlow* attestation_flow) | 115 AttestationFlow* attestation_flow) |
| 113 : cros_settings_(CrosSettings::Get()), | 116 : cros_settings_(CrosSettings::Get()), |
| 114 policy_client_(policy_client), | 117 policy_client_(policy_client), |
| 115 cryptohome_client_(cryptohome_client), | 118 cryptohome_client_(cryptohome_client), |
| 116 attestation_flow_(attestation_flow), | 119 attestation_flow_(attestation_flow), |
| 117 num_retries_(0), | 120 num_retries_(0), |
| 118 retry_delay_(kRetryDelay), | 121 retry_delay_(kRetryDelay), |
| 119 weak_factory_(this) { | 122 weak_factory_(this) { |
| 120 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 123 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 121 cros_settings_->AddSettingsObserver(kDeviceAttestationEnabled, this); | 124 attestation_subscription_ = cros_settings_->AddSettingsObserver( |
| 125 kDeviceAttestationEnabled, |
| 126 base::Bind(&AttestationPolicyObserver::AttestationSettingChanged, |
| 127 base::Unretained(this))); |
| 122 Start(); | 128 Start(); |
| 123 } | 129 } |
| 124 | 130 |
| 125 AttestationPolicyObserver::~AttestationPolicyObserver() { | 131 AttestationPolicyObserver::~AttestationPolicyObserver() { |
| 126 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 132 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 127 cros_settings_->RemoveSettingsObserver(kDeviceAttestationEnabled, this); | |
| 128 } | 133 } |
| 129 | 134 |
| 130 void AttestationPolicyObserver::Observe( | 135 void AttestationPolicyObserver::AttestationSettingChanged() { |
| 131 int type, | |
| 132 const content::NotificationSource& source, | |
| 133 const content::NotificationDetails& details) { | |
| 134 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 136 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 135 std::string* path = content::Details<std::string>(details).ptr(); | |
| 136 if (type != chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED || | |
| 137 *path != kDeviceAttestationEnabled) { | |
| 138 LOG(WARNING) << "AttestationPolicyObserver: Unexpected event received."; | |
| 139 return; | |
| 140 } | |
| 141 num_retries_ = 0; | 137 num_retries_ = 0; |
| 142 Start(); | 138 Start(); |
| 143 } | 139 } |
| 144 | 140 |
| 145 void AttestationPolicyObserver::Start() { | 141 void AttestationPolicyObserver::Start() { |
| 146 // If attestation is not enabled, there is nothing to do. | 142 // If attestation is not enabled, there is nothing to do. |
| 147 bool enabled = false; | 143 bool enabled = false; |
| 148 if (!cros_settings_->GetBoolean(kDeviceAttestationEnabled, &enabled) || | 144 if (!cros_settings_->GetBoolean(kDeviceAttestationEnabled, &enabled) || |
| 149 !enabled) | 145 !enabled) |
| 150 return; | 146 return; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 base::Bind(&AttestationPolicyObserver::Start, | 301 base::Bind(&AttestationPolicyObserver::Start, |
| 306 weak_factory_.GetWeakPtr()), | 302 weak_factory_.GetWeakPtr()), |
| 307 base::TimeDelta::FromSeconds(retry_delay_)); | 303 base::TimeDelta::FromSeconds(retry_delay_)); |
| 308 } else { | 304 } else { |
| 309 LOG(WARNING) << "AttestationPolicyObserver: Retry limit exceeded."; | 305 LOG(WARNING) << "AttestationPolicyObserver: Retry limit exceeded."; |
| 310 } | 306 } |
| 311 } | 307 } |
| 312 | 308 |
| 313 } // namespace attestation | 309 } // namespace attestation |
| 314 } // namespace chromeos | 310 } // namespace chromeos |
| OLD | NEW |