Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(335)

Side by Side Diff: components/policy/core/common/async_policy_loader.cc

Issue 1902633006: Convert //components/policy from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 44 DCHECK(task_runner_->RunsTasksOnCurrentThread());
45 45
46 TimeDelta delay; 46 TimeDelta delay;
47 Time now = Time::Now(); 47 Time now = Time::Now();
48 // Check if there was a recent modification to the underlying files. 48 // Check if there was a recent modification to the underlying files.
49 if (!force && !IsSafeToReload(now, &delay)) { 49 if (!force && !IsSafeToReload(now, &delay)) {
50 ScheduleNextReload(delay); 50 ScheduleNextReload(delay);
51 return; 51 return;
52 } 52 }
53 53
54 scoped_ptr<PolicyBundle> bundle(Load()); 54 std::unique_ptr<PolicyBundle> bundle(Load());
55 55
56 // Check if there was a modification while reading. 56 // Check if there was a modification while reading.
57 if (!force && !IsSafeToReload(now, &delay)) { 57 if (!force && !IsSafeToReload(now, &delay)) {
58 ScheduleNextReload(delay); 58 ScheduleNextReload(delay);
59 return; 59 return;
60 } 60 }
61 61
62 // Filter out mismatching policies. 62 // Filter out mismatching policies.
63 schema_map_->FilterBundle(bundle.get()); 63 schema_map_->FilterBundle(bundle.get());
64 64
65 update_callback_.Run(std::move(bundle)); 65 update_callback_.Run(std::move(bundle));
66 ScheduleNextReload(TimeDelta::FromSeconds(kReloadIntervalSeconds)); 66 ScheduleNextReload(TimeDelta::FromSeconds(kReloadIntervalSeconds));
67 } 67 }
68 68
69 scoped_ptr<PolicyBundle> AsyncPolicyLoader::InitialLoad( 69 std::unique_ptr<PolicyBundle> AsyncPolicyLoader::InitialLoad(
70 const scoped_refptr<SchemaMap>& schema_map) { 70 const scoped_refptr<SchemaMap>& schema_map) {
71 // 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
72 // initial |last_modification_time_|, so that potential changes made before 72 // initial |last_modification_time_|, so that potential changes made before
73 // installing the watches can be detected. 73 // installing the watches can be detected.
74 last_modification_time_ = LastModificationTime(); 74 last_modification_time_ = LastModificationTime();
75 schema_map_ = schema_map; 75 schema_map_ = schema_map;
76 scoped_ptr<PolicyBundle> bundle(Load()); 76 std::unique_ptr<PolicyBundle> bundle(Load());
77 // Filter out mismatching policies. 77 // Filter out mismatching policies.
78 schema_map_->FilterBundle(bundle.get()); 78 schema_map_->FilterBundle(bundle.get());
79 return bundle; 79 return bundle;
80 } 80 }
81 81
82 void AsyncPolicyLoader::Init(const UpdateCallback& update_callback) { 82 void AsyncPolicyLoader::Init(const UpdateCallback& update_callback) {
83 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 83 DCHECK(task_runner_->RunsTasksOnCurrentThread());
84 DCHECK(update_callback_.is_null()); 84 DCHECK(update_callback_.is_null());
85 DCHECK(!update_callback.is_null()); 85 DCHECK(!update_callback.is_null());
86 update_callback_ = update_callback; 86 update_callback_ = update_callback;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 const TimeDelta age = now - last_modification_clock_; 131 const TimeDelta age = now - last_modification_clock_;
132 if (age < kSettleInterval) { 132 if (age < kSettleInterval) {
133 *delay = kSettleInterval - age; 133 *delay = kSettleInterval - age;
134 return false; 134 return false;
135 } 135 }
136 136
137 return true; 137 return true;
138 } 138 }
139 139
140 } // namespace policy 140 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698