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 "components/policy/core/common/cloud/component_cloud_policy_updater.h" | 5 #include "components/policy/core/common/cloud/component_cloud_policy_updater.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <utility> |
9 | 10 |
10 #include "base/bind.h" | 11 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
12 #include "base/logging.h" | 13 #include "base/logging.h" |
13 #include "base/sequenced_task_runner.h" | 14 #include "base/sequenced_task_runner.h" |
14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
15 #include "components/policy/core/common/cloud/component_cloud_policy_store.h" | 16 #include "components/policy/core/common/cloud/component_cloud_policy_store.h" |
16 #include "components/policy/core/common/cloud/external_policy_data_fetcher.h" | 17 #include "components/policy/core/common/cloud/external_policy_data_fetcher.h" |
17 #include "policy/proto/chrome_extension_policy.pb.h" | 18 #include "policy/proto/chrome_extension_policy.pb.h" |
18 #include "policy/proto/device_management_backend.pb.h" | 19 #include "policy/proto/device_management_backend.pb.h" |
(...skipping 14 matching lines...) Expand all Loading... |
33 const int64_t kMaxParallelPolicyDataFetches = 2; | 34 const int64_t kMaxParallelPolicyDataFetches = 2; |
34 | 35 |
35 } // namespace | 36 } // namespace |
36 | 37 |
37 ComponentCloudPolicyUpdater::ComponentCloudPolicyUpdater( | 38 ComponentCloudPolicyUpdater::ComponentCloudPolicyUpdater( |
38 scoped_refptr<base::SequencedTaskRunner> task_runner, | 39 scoped_refptr<base::SequencedTaskRunner> task_runner, |
39 scoped_ptr<ExternalPolicyDataFetcher> external_policy_data_fetcher, | 40 scoped_ptr<ExternalPolicyDataFetcher> external_policy_data_fetcher, |
40 ComponentCloudPolicyStore* store) | 41 ComponentCloudPolicyStore* store) |
41 : store_(store), | 42 : store_(store), |
42 external_policy_data_updater_(task_runner, | 43 external_policy_data_updater_(task_runner, |
43 external_policy_data_fetcher.Pass(), | 44 std::move(external_policy_data_fetcher), |
44 kMaxParallelPolicyDataFetches) { | 45 kMaxParallelPolicyDataFetches) {} |
45 } | |
46 | 46 |
47 ComponentCloudPolicyUpdater::~ComponentCloudPolicyUpdater() { | 47 ComponentCloudPolicyUpdater::~ComponentCloudPolicyUpdater() { |
48 } | 48 } |
49 | 49 |
50 void ComponentCloudPolicyUpdater::UpdateExternalPolicy( | 50 void ComponentCloudPolicyUpdater::UpdateExternalPolicy( |
51 scoped_ptr<em::PolicyFetchResponse> response) { | 51 scoped_ptr<em::PolicyFetchResponse> response) { |
52 // Keep a serialized copy of |response|, to cache it later. | 52 // Keep a serialized copy of |response|, to cache it later. |
53 // The policy is also rejected if it exceeds the maximum size. | 53 // The policy is also rejected if it exceeds the maximum size. |
54 std::string serialized_response; | 54 std::string serialized_response; |
55 if (!response->SerializeToString(&serialized_response) || | 55 if (!response->SerializeToString(&serialized_response) || |
56 serialized_response.size() > kPolicyProtoMaxSize) { | 56 serialized_response.size() > kPolicyProtoMaxSize) { |
57 return; | 57 return; |
58 } | 58 } |
59 | 59 |
60 // Validate the policy before doing anything else. | 60 // Validate the policy before doing anything else. |
61 PolicyNamespace ns; | 61 PolicyNamespace ns; |
62 em::ExternalPolicyData data; | 62 em::ExternalPolicyData data; |
63 if (!store_->ValidatePolicy(response.Pass(), &ns, &data)) { | 63 if (!store_->ValidatePolicy(std::move(response), &ns, &data)) { |
64 LOG(ERROR) << "Failed to validate component policy fetched from DMServer"; | 64 LOG(ERROR) << "Failed to validate component policy fetched from DMServer"; |
65 return; | 65 return; |
66 } | 66 } |
67 | 67 |
68 // Maybe the data for this hash has already been downloaded and cached. | 68 // Maybe the data for this hash has already been downloaded and cached. |
69 const std::string& cached_hash = store_->GetCachedHash(ns); | 69 const std::string& cached_hash = store_->GetCachedHash(ns); |
70 if (!cached_hash.empty() && data.secure_hash() == cached_hash) | 70 if (!cached_hash.empty() && data.secure_hash() == cached_hash) |
71 return; | 71 return; |
72 | 72 |
73 // TODO(joaodasilva): implement the other two auth methods. | 73 // TODO(joaodasilva): implement the other two auth methods. |
(...skipping 29 matching lines...) Expand all Loading... |
103 } | 103 } |
104 | 104 |
105 std::string ComponentCloudPolicyUpdater::NamespaceToKey( | 105 std::string ComponentCloudPolicyUpdater::NamespaceToKey( |
106 const PolicyNamespace& ns) { | 106 const PolicyNamespace& ns) { |
107 const std::string domain = base::IntToString(ns.domain); | 107 const std::string domain = base::IntToString(ns.domain); |
108 const std::string size = base::SizeTToString(domain.size()); | 108 const std::string size = base::SizeTToString(domain.size()); |
109 return size + ":" + domain + ":" + ns.component_id; | 109 return size + ":" + domain + ":" + ns.component_id; |
110 } | 110 } |
111 | 111 |
112 } // namespace policy | 112 } // namespace policy |
OLD | NEW |