OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/policy/asynchronous_policy_loader.h" | |
6 | |
7 #include "base/message_loop.h" | |
8 #include "base/task.h" | |
9 #include "chrome/browser/browser_thread.h" | |
10 | |
11 namespace policy { | |
12 | |
13 AsynchronousPolicyLoader::AsynchronousPolicyLoader( | |
14 AsynchronousPolicyProvider::Delegate* delegate) | |
15 : delegate_(delegate), | |
16 origin_loop_(MessageLoop::current()) {} | |
17 | |
18 void AsynchronousPolicyLoader::Init() { | |
19 policy_.reset(delegate_->Load()); | |
20 } | |
21 | |
22 void AsynchronousPolicyLoader::Stop() { | |
23 DCHECK_EQ(MessageLoop::current(), origin_loop_); | |
Mattias Nissler (ping if slow)
2010/12/09 09:27:17
Why did you remove this?
danno
2010/12/09 10:23:02
For the singleton policy provider in the real app,
| |
24 delegate_.reset(); | |
25 } | |
26 | |
27 void AsynchronousPolicyLoader::SetProvider( | |
28 AsynchronousPolicyProvider* provider) { | |
29 provider_ = provider; | |
30 } | |
31 | |
32 // Manages the life cycle of a new policy map during until it's life cycle is | |
33 // taken over by the policy loader. | |
34 class UpdatePolicyTask : public Task { | |
35 public: | |
36 UpdatePolicyTask(scoped_refptr<AsynchronousPolicyLoader> loader, | |
37 DictionaryValue* new_policy) | |
38 : loader_(loader), | |
39 new_policy_(new_policy) {} | |
40 | |
41 virtual void Run() { | |
42 loader_->UpdatePolicy(new_policy_.release()); | |
43 } | |
44 | |
45 private: | |
46 scoped_refptr<AsynchronousPolicyLoader> loader_; | |
47 scoped_ptr<DictionaryValue> new_policy_; | |
48 DISALLOW_COPY_AND_ASSIGN(UpdatePolicyTask); | |
49 }; | |
50 | |
51 void AsynchronousPolicyLoader::Reload() { | |
52 if (delegate_.get()) { | |
53 DictionaryValue* new_policy = delegate_->Load(); | |
54 PostUpdatePolicyTask(new_policy); | |
55 } | |
56 } | |
57 | |
58 void AsynchronousPolicyLoader::PostUpdatePolicyTask( | |
59 DictionaryValue* new_policy) { | |
60 origin_loop_->PostTask(FROM_HERE, new UpdatePolicyTask(this, new_policy)); | |
61 } | |
62 | |
63 void AsynchronousPolicyLoader::UpdatePolicy(DictionaryValue* new_policy_raw) { | |
64 DCHECK(policy_.get()); | |
65 if (!policy_->Equals(new_policy_raw)) { | |
66 policy_.reset(new_policy_raw); | |
67 // TODO(danno): Change the notification between the provider and the | |
68 // PrefStore into a notification mechanism, removing the need for the | |
69 // WeakPtr for the provider. | |
70 if (provider_) | |
71 provider_->NotifyStoreOfPolicyChange(); | |
72 } | |
73 } | |
74 | |
75 } // namespace policy | |
OLD | NEW |