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

Side by Side Diff: chrome/browser/policy/component_cloud_policy_service.h

Issue 12189011: Split up chrome/browser/policy subdirectory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase, add chrome/browser/chromeos/policy/OWNERS Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 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 #ifndef CHROME_BROWSER_POLICY_COMPONENT_CLOUD_POLICY_SERVICE_H_
6 #define CHROME_BROWSER_POLICY_COMPONENT_CLOUD_POLICY_SERVICE_H_
7
8 #include <map>
9 #include <set>
10 #include <string>
11
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/weak_ptr.h"
17 #include "chrome/browser/policy/cloud_policy_client.h"
18 #include "chrome/browser/policy/cloud_policy_store.h"
19 #include "chrome/browser/policy/policy_bundle.h"
20 #include "chrome/browser/policy/policy_service.h"
21
22 namespace base {
23 class SequencedTaskRunner;
24 }
25
26 namespace net {
27 class URLRequestContextGetter;
28 }
29
30 namespace policy {
31
32 class ResourceCache;
33
34 // Manages cloud policy for components.
35 //
36 // This class takes care of fetching, validating, storing and updating policy
37 // for components. The components to manage have to be explicitly registered.
38 class ComponentCloudPolicyService : public CloudPolicyClient::Observer,
39 public CloudPolicyStore::Observer {
40 public:
41 // Key for the ResourceCache where the list of known components is cached.
42 static const char kComponentNamespaceCache[];
43
44 class Delegate {
45 public:
46 virtual ~Delegate();
47
48 // Invoked whenever the service has appended new namespaces to fetch to
49 // the CloudPolicyClient, signaling that a policy fetch should be done soon.
50 virtual void OnComponentCloudPolicyRefreshNeeded() = 0;
51
52 // Invoked whenever the policy served by policy() changes. This is also
53 // invoked for the first time once the backend is initialized, and
54 // is_initialized() becomes true.
55 virtual void OnComponentCloudPolicyUpdated() = 0;
56 };
57
58 // |store| is used to get the current DMToken and the username.
59 // |cache| is used to load and store local copies of the downloaded policies.
60 ComponentCloudPolicyService(Delegate* delegate,
61 CloudPolicyStore* store,
62 scoped_ptr<ResourceCache> cache);
63 virtual ~ComponentCloudPolicyService();
64
65 // Returns true if |domain| is supported by the service.
66 static bool SupportsDomain(PolicyDomain domain);
67
68 // Returns true if the backend is initialized, and the initial policies and
69 // components are being served.
70 bool is_initialized() const { return is_initialized_; }
71
72 // Returns the current policies for components.
73 const PolicyBundle& policy() const { return policy_; }
74
75 // Connects to the cloud policy service using |client|. |client| must outlive
76 // this object. Only cached policies will be served until a |client| is
77 // connected.
78 // |request_context| is used with the URLFetchers triggered by the updater.
79 void Connect(CloudPolicyClient* client,
80 scoped_refptr<net::URLRequestContextGetter> request_context);
81
82 // Disconnects from the cloud policy service and stops trying to download
83 // remote policy data.
84 void Disconnect();
85
86 // |component_ids| is the complete set of components to track for the given
87 // |domain|. This purges unused components from the cache, and starts
88 // updating the components in |component_ids|.
89 // It's only valid to call this for domains that are supported, i.e.
90 // SupportsDomain(domain) is true.
91 void RegisterPolicyDomain(PolicyDomain domain,
92 const std::set<std::string>& component_ids);
93
94 // CloudPolicyClient::Observer implementation:
95 virtual void OnPolicyFetched(CloudPolicyClient* client) OVERRIDE;
96 virtual void OnRegistrationStateChanged(CloudPolicyClient* client) OVERRIDE;
97 virtual void OnClientError(CloudPolicyClient* client) OVERRIDE;
98
99 // CloudPolicyStore::Observer implementation:
100 virtual void OnStoreLoaded(CloudPolicyStore* store) OVERRIDE;
101 virtual void OnStoreError(CloudPolicyStore* store) OVERRIDE;
102
103 private:
104 class Backend;
105 typedef std::set<std::string> StringSet;
106 typedef std::map<PolicyDomain, StringSet> ComponentMap;
107
108 void InitializeBackend();
109 void OnBackendInitialized(scoped_ptr<ComponentMap> components,
110 scoped_ptr<PolicyBundle> initial_policy);
111 void InitializeClient();
112 void OnPolicyUpdated(scoped_ptr<PolicyBundle> policy);
113
114 void SetCredentialsAndReloadClient();
115 bool UpdateClientNamespaces(PolicyDomain domain,
116 const StringSet& old_set,
117 const StringSet& new_set);
118 void AddNamespacesToFetch(PolicyDomain domain, const StringSet& set);
119 void RemoveNamespacesToFetch(PolicyDomain domain, const StringSet& set);
120
121 Delegate* delegate_;
122
123 // This class manages others that live on a background thread; those are
124 // managed by |backend_|. |backend_| lives in the thread that backs
125 // |backend_task_runner_|, but is owned by |this|. It is created on UI, but
126 // from then on it only receives calls on the background thread, including
127 // destruction. So it's always safe to post tasks to |backend_|, since its
128 // deletion is posted after the deletion of |this|.
129 Backend* backend_;
130 scoped_refptr<base::SequencedTaskRunner> backend_task_runner_;
131
132 CloudPolicyClient* client_;
133 CloudPolicyStore* store_;
134
135 // The currently registered components for each policy domain. If a policy
136 // domain doesn't have an entry in this map then it hasn't registered its
137 // component yet. A domain in this map with an empty set of components means
138 // that the domain is registered, but has no components.
139 ComponentMap registered_components_;
140
141 // Contains all the current policies for components.
142 PolicyBundle policy_;
143
144 bool is_initialized_;
145 base::WeakPtrFactory<ComponentCloudPolicyService> weak_ptr_factory_;
146
147 DISALLOW_COPY_AND_ASSIGN(ComponentCloudPolicyService);
148 };
149
150 } // namespace policy
151
152 #endif // CHROME_BROWSER_POLICY_COMPONENT_CLOUD_POLICY_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/policy/component_cloud_policy_browsertest.cc ('k') | chrome/browser/policy/component_cloud_policy_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698