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

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

Issue 5562002: Refactor FileBasedPolicyProvider, introduce AsynchronousPolicyProvider. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review feedback Created 10 years 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 | Annotate | Revision Log
OLDNEW
(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()) {}
Mattias Nissler (ping if slow) 2010/12/06 10:26:20 Move closing brace to next line for scanability :)
danno 2010/12/06 14:05:12 Actually, in my readability review, my reviewer su
17
18 void AsynchronousPolicyLoader::Init() {
19 policy_.reset(delegate_->Load());
20 }
21
22 void AsynchronousPolicyLoader::Stop() {
23 DCHECK_EQ(MessageLoop::current(), origin_loop_);
24 delegate_.reset();
25 }
26
27 void AsynchronousPolicyLoader::SetProvider(
28 base::WeakPtr<AsynchronousPolicyProvider> provider) {
29 provider_ = provider;
30 }
31
32 // Manages the life cycle of a new policy while is pending on the message
Mattias Nissler (ping if slow) 2010/12/06 10:26:20 What is pending?
danno 2010/12/06 14:05:12 Done.
33 // loop waiting to be updated.
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_.get())
71 provider_->NotifyStoreOfPolicyChange();
72 }
73 }
74
75 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698