OLD | NEW |
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 "chrome/browser/policy/policy_bundle.h" | 8 #include "chrome/browser/policy/policy_bundle.h" |
| 9 #include "chrome/browser/policy/policy_domain_descriptor.h" |
9 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
10 | 11 |
11 using base::Time; | 12 using base::Time; |
12 using base::TimeDelta; | 13 using base::TimeDelta; |
13 using content::BrowserThread; | 14 using content::BrowserThread; |
14 | 15 |
15 namespace policy { | 16 namespace policy { |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
(...skipping 29 matching lines...) Expand all Loading... |
48 } | 49 } |
49 | 50 |
50 scoped_ptr<PolicyBundle> bundle(Load()); | 51 scoped_ptr<PolicyBundle> bundle(Load()); |
51 | 52 |
52 // Check if there was a modification while reading. | 53 // Check if there was a modification while reading. |
53 if (!force && !IsSafeToReload(now, &delay)) { | 54 if (!force && !IsSafeToReload(now, &delay)) { |
54 ScheduleNextReload(delay); | 55 ScheduleNextReload(delay); |
55 return; | 56 return; |
56 } | 57 } |
57 | 58 |
| 59 // Filter out mismatching policies. |
| 60 for (DescriptorMap::iterator it = descriptor_map_.begin(); |
| 61 it != descriptor_map_.end(); ++it) { |
| 62 it->second->FilterBundle(bundle.get()); |
| 63 } |
| 64 |
58 update_callback_.Run(bundle.Pass()); | 65 update_callback_.Run(bundle.Pass()); |
59 ScheduleNextReload(TimeDelta::FromSeconds(kReloadIntervalSeconds)); | 66 ScheduleNextReload(TimeDelta::FromSeconds(kReloadIntervalSeconds)); |
60 } | 67 } |
61 | 68 |
| 69 void AsyncPolicyLoader::RegisterPolicyDomain( |
| 70 scoped_refptr<const PolicyDomainDescriptor> descriptor) { |
| 71 if (descriptor->domain() != POLICY_DOMAIN_CHROME) { |
| 72 descriptor_map_[descriptor->domain()] = descriptor; |
| 73 Reload(true); |
| 74 } |
| 75 } |
| 76 |
62 scoped_ptr<PolicyBundle> AsyncPolicyLoader::InitialLoad() { | 77 scoped_ptr<PolicyBundle> AsyncPolicyLoader::InitialLoad() { |
63 // 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 |
64 // initial |last_modification_time_|, so that potential changes made before | 79 // initial |last_modification_time_|, so that potential changes made before |
65 // installing the watches can be detected. | 80 // installing the watches can be detected. |
66 last_modification_time_ = LastModificationTime(); | 81 last_modification_time_ = LastModificationTime(); |
67 return Load(); | 82 return Load(); |
68 } | 83 } |
69 | 84 |
70 void AsyncPolicyLoader::Init(const UpdateCallback& update_callback) { | 85 void AsyncPolicyLoader::Init(const UpdateCallback& update_callback) { |
71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 86 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 const base::TimeDelta age = now - last_modification_clock_; | 129 const base::TimeDelta age = now - last_modification_clock_; |
115 if (age < kSettleInterval) { | 130 if (age < kSettleInterval) { |
116 *delay = kSettleInterval - age; | 131 *delay = kSettleInterval - age; |
117 return false; | 132 return false; |
118 } | 133 } |
119 | 134 |
120 return true; | 135 return true; |
121 } | 136 } |
122 | 137 |
123 } // namespace policy | 138 } // namespace policy |
OLD | NEW |