| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "components/policy/core/common/cloud/policy_header_service.h" | 5 #include "components/policy/core/common/cloud/policy_header_service.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "components/policy/core/common/cloud/cloud_policy_store.h" | 10 #include "components/policy/core/common/cloud/cloud_policy_store.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 if (user_policy_store_->policy()->has_policy_token()) { | 67 if (user_policy_store_->policy()->has_policy_token()) { |
| 68 value.SetString(kUserPolicyTokenKey, | 68 value.SetString(kUserPolicyTokenKey, |
| 69 user_policy_store_->policy()->policy_token()); | 69 user_policy_store_->policy()->policy_token()); |
| 70 } | 70 } |
| 71 if (!verification_key_hash_.empty()) | 71 if (!verification_key_hash_.empty()) |
| 72 value.SetString(kVerificationKeyHashKey, verification_key_hash_); | 72 value.SetString(kVerificationKeyHashKey, verification_key_hash_); |
| 73 | 73 |
| 74 // TODO(atwilson): add user_policy_token once the server starts sending it | 74 // TODO(atwilson): add user_policy_token once the server starts sending it |
| 75 // down (http://crbug.com/326799). | 75 // down (http://crbug.com/326799). |
| 76 std::string json; | 76 std::string json; |
| 77 base::JSONWriter::Write(&value, &json); | 77 base::JSONWriter::Write(value, &json); |
| 78 DCHECK(!json.empty()); | 78 DCHECK(!json.empty()); |
| 79 | 79 |
| 80 // Base64-encode the result so we can include it in a header. | 80 // Base64-encode the result so we can include it in a header. |
| 81 std::string encoded; | 81 std::string encoded; |
| 82 base::Base64Encode(json, &encoded); | 82 base::Base64Encode(json, &encoded); |
| 83 return encoded; | 83 return encoded; |
| 84 } | 84 } |
| 85 | 85 |
| 86 void PolicyHeaderService::OnStoreLoaded(CloudPolicyStore* store) { | 86 void PolicyHeaderService::OnStoreLoaded(CloudPolicyStore* store) { |
| 87 // If we have a PolicyHeaderIOHelper, notify it of the new header value. | 87 // If we have a PolicyHeaderIOHelper, notify it of the new header value. |
| 88 if (!helpers_.empty()) { | 88 if (!helpers_.empty()) { |
| 89 std::string new_header = CreateHeaderValue(); | 89 std::string new_header = CreateHeaderValue(); |
| 90 for (std::vector<PolicyHeaderIOHelper*>::const_iterator it = | 90 for (std::vector<PolicyHeaderIOHelper*>::const_iterator it = |
| 91 helpers_.begin(); it != helpers_.end(); ++it) { | 91 helpers_.begin(); it != helpers_.end(); ++it) { |
| 92 (*it)->UpdateHeader(new_header); | 92 (*it)->UpdateHeader(new_header); |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 | 96 |
| 97 void PolicyHeaderService::OnStoreError(CloudPolicyStore* store) { | 97 void PolicyHeaderService::OnStoreError(CloudPolicyStore* store) { |
| 98 // Do nothing on errors. | 98 // Do nothing on errors. |
| 99 } | 99 } |
| 100 | 100 |
| 101 std::vector<PolicyHeaderIOHelper*> PolicyHeaderService::GetHelpersForTest() { | 101 std::vector<PolicyHeaderIOHelper*> PolicyHeaderService::GetHelpersForTest() { |
| 102 return helpers_; | 102 return helpers_; |
| 103 } | 103 } |
| 104 | 104 |
| 105 } // namespace policy | 105 } // namespace policy |
| OLD | NEW |