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/async_policy_loader.h" | 5 #include "components/policy/core/common/async_policy_loader.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/location.h" | 10 #include "base/location.h" |
9 #include "base/sequenced_task_runner.h" | 11 #include "base/sequenced_task_runner.h" |
10 #include "components/policy/core/common/policy_bundle.h" | 12 #include "components/policy/core/common/policy_bundle.h" |
11 | 13 |
12 using base::Time; | 14 using base::Time; |
13 using base::TimeDelta; | 15 using base::TimeDelta; |
14 | 16 |
15 namespace policy { | 17 namespace policy { |
16 | 18 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 55 |
54 // Check if there was a modification while reading. | 56 // Check if there was a modification while reading. |
55 if (!force && !IsSafeToReload(now, &delay)) { | 57 if (!force && !IsSafeToReload(now, &delay)) { |
56 ScheduleNextReload(delay); | 58 ScheduleNextReload(delay); |
57 return; | 59 return; |
58 } | 60 } |
59 | 61 |
60 // Filter out mismatching policies. | 62 // Filter out mismatching policies. |
61 schema_map_->FilterBundle(bundle.get()); | 63 schema_map_->FilterBundle(bundle.get()); |
62 | 64 |
63 update_callback_.Run(bundle.Pass()); | 65 update_callback_.Run(std::move(bundle)); |
64 ScheduleNextReload(TimeDelta::FromSeconds(kReloadIntervalSeconds)); | 66 ScheduleNextReload(TimeDelta::FromSeconds(kReloadIntervalSeconds)); |
65 } | 67 } |
66 | 68 |
67 scoped_ptr<PolicyBundle> AsyncPolicyLoader::InitialLoad( | 69 scoped_ptr<PolicyBundle> AsyncPolicyLoader::InitialLoad( |
68 const scoped_refptr<SchemaMap>& schema_map) { | 70 const scoped_refptr<SchemaMap>& schema_map) { |
69 // This is the first load, early during startup. Use this to record the | 71 // This is the first load, early during startup. Use this to record the |
70 // initial |last_modification_time_|, so that potential changes made before | 72 // initial |last_modification_time_|, so that potential changes made before |
71 // installing the watches can be detected. | 73 // installing the watches can be detected. |
72 last_modification_time_ = LastModificationTime(); | 74 last_modification_time_ = LastModificationTime(); |
73 schema_map_ = schema_map; | 75 schema_map_ = schema_map; |
74 scoped_ptr<PolicyBundle> bundle(Load()); | 76 scoped_ptr<PolicyBundle> bundle(Load()); |
75 // Filter out mismatching policies. | 77 // Filter out mismatching policies. |
76 schema_map_->FilterBundle(bundle.get()); | 78 schema_map_->FilterBundle(bundle.get()); |
77 return bundle.Pass(); | 79 return bundle; |
78 } | 80 } |
79 | 81 |
80 void AsyncPolicyLoader::Init(const UpdateCallback& update_callback) { | 82 void AsyncPolicyLoader::Init(const UpdateCallback& update_callback) { |
81 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 83 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
82 DCHECK(update_callback_.is_null()); | 84 DCHECK(update_callback_.is_null()); |
83 DCHECK(!update_callback.is_null()); | 85 DCHECK(!update_callback.is_null()); |
84 update_callback_ = update_callback; | 86 update_callback_ = update_callback; |
85 | 87 |
86 InitOnBackgroundThread(); | 88 InitOnBackgroundThread(); |
87 | 89 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 const TimeDelta age = now - last_modification_clock_; | 131 const TimeDelta age = now - last_modification_clock_; |
130 if (age < kSettleInterval) { | 132 if (age < kSettleInterval) { |
131 *delay = kSettleInterval - age; | 133 *delay = kSettleInterval - age; |
132 return false; | 134 return false; |
133 } | 135 } |
134 | 136 |
135 return true; | 137 return true; |
136 } | 138 } |
137 | 139 |
138 } // namespace policy | 140 } // namespace policy |
OLD | NEW |