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

Side by Side Diff: chrome/browser/policy/async_policy_loader.cc

Issue 22493010: policy: load JSON schema into domain descriptor at start time. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add comments and clean up includes Created 7 years, 3 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/policy/async_policy_loader.h" 5 #include "chrome/browser/policy/async_policy_loader.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/sequenced_task_runner.h" 9 #include "base/sequenced_task_runner.h"
10 #include "chrome/browser/policy/policy_bundle.h" 10 #include "chrome/browser/policy/policy_bundle.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 it != descriptor_map_.end(); ++it) { 63 it != descriptor_map_.end(); ++it) {
64 it->second->FilterBundle(bundle.get()); 64 it->second->FilterBundle(bundle.get());
65 } 65 }
66 66
67 update_callback_.Run(bundle.Pass()); 67 update_callback_.Run(bundle.Pass());
68 ScheduleNextReload(TimeDelta::FromSeconds(kReloadIntervalSeconds)); 68 ScheduleNextReload(TimeDelta::FromSeconds(kReloadIntervalSeconds));
69 } 69 }
70 70
71 void AsyncPolicyLoader::RegisterPolicyDomain( 71 void AsyncPolicyLoader::RegisterPolicyDomain(
72 scoped_refptr<const PolicyDomainDescriptor> descriptor) { 72 scoped_refptr<const PolicyDomainDescriptor> descriptor) {
73 if (descriptor->domain() != POLICY_DOMAIN_CHROME) { 73 InitialRegisterPolicyDomain(descriptor);
74 descriptor_map_[descriptor->domain()] = descriptor; 74 Reload(true);
75 Reload(true);
76 }
77 } 75 }
78 76
79 scoped_ptr<PolicyBundle> AsyncPolicyLoader::InitialLoad() { 77 scoped_ptr<PolicyBundle> AsyncPolicyLoader::InitialLoad() {
80 // This is the first load, early during startup. Use this to record the 78 // This is the first load, early during startup. Use this to record the
81 // initial |last_modification_time_|, so that potential changes made before 79 // initial |last_modification_time_|, so that potential changes made before
82 // installing the watches can be detected. 80 // installing the watches can be detected.
83 last_modification_time_ = LastModificationTime(); 81 last_modification_time_ = LastModificationTime();
84 return Load(); 82 return Load();
85 } 83 }
86 84
85 void AsyncPolicyLoader::InitialRegisterPolicyDomain(
86 scoped_refptr<const PolicyDomainDescriptor> descriptor) {
87 descriptor_map_[descriptor->domain()] = descriptor;
88 }
89
87 void AsyncPolicyLoader::Init(const UpdateCallback& update_callback) { 90 void AsyncPolicyLoader::Init(const UpdateCallback& update_callback) {
88 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 91 DCHECK(task_runner_->RunsTasksOnCurrentThread());
89 DCHECK(update_callback_.is_null()); 92 DCHECK(update_callback_.is_null());
90 DCHECK(!update_callback.is_null()); 93 DCHECK(!update_callback.is_null());
91 update_callback_ = update_callback; 94 update_callback_ = update_callback;
92 95
93 InitOnBackgroundThread(); 96 InitOnBackgroundThread();
94 97
95 // There might have been changes to the underlying files since the initial 98 // There might have been changes to the underlying files since the initial
96 // load and before the watchers have been created. 99 // load and before the watchers have been created.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 const base::TimeDelta age = now - last_modification_clock_; 133 const base::TimeDelta age = now - last_modification_clock_;
131 if (age < kSettleInterval) { 134 if (age < kSettleInterval) {
132 *delay = kSettleInterval - age; 135 *delay = kSettleInterval - age;
133 return false; 136 return false;
134 } 137 }
135 138
136 return true; 139 return true;
137 } 140 }
138 141
139 } // namespace policy 142 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698