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

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

Issue 10919131: Break out base functionality of UserCloudPolicyManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase, address comments, fix compilation. Created 8 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 | Annotate | Revision Log
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 #ifndef CHROME_BROWSER_POLICY_CLOUD_POLICY_SERVICE_H_ 5 #ifndef CHROME_BROWSER_POLICY_CLOUD_POLICY_SERVICE_H_
6 #define CHROME_BROWSER_POLICY_CLOUD_POLICY_SERVICE_H_ 6 #define CHROME_BROWSER_POLICY_CLOUD_POLICY_SERVICE_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/callback_forward.h" 12 #include "base/callback_forward.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "chrome/browser/policy/cloud_policy_client.h" 14 #include "chrome/browser/policy/cloud_policy_client.h"
16 #include "chrome/browser/policy/cloud_policy_constants.h" 15 #include "chrome/browser/policy/cloud_policy_constants.h"
17 #include "chrome/browser/policy/cloud_policy_store.h" 16 #include "chrome/browser/policy/cloud_policy_store.h"
18 17
19 namespace policy { 18 namespace policy {
20 19
21 // Coordinates cloud policy handling, hosting the cloud policy client, fetching 20 // Coordinates cloud policy handling, moving downloaded policy from the client
22 // new policy, and updating the local policy cache when new policy becomes 21 // to the store, and setting up client registrations from cached data in the
23 // available. 22 // store. Also coordinates actions on policy refresh triggers.
24 class CloudPolicyService : public CloudPolicyClient::Observer, 23 class CloudPolicyService : public CloudPolicyClient::Observer,
25 public CloudPolicyStore::Observer { 24 public CloudPolicyStore::Observer {
26 public: 25 public:
27 CloudPolicyService(scoped_ptr<CloudPolicyClient> client, 26 // |client| and |store| must remain valid for the object life time.
28 CloudPolicyStore* store); 27 CloudPolicyService(CloudPolicyClient* client, CloudPolicyStore* store);
29 virtual ~CloudPolicyService(); 28 virtual ~CloudPolicyService();
30 29
31 // Returns the domain that manages this user/device, according to the current 30 // Returns the domain that manages this user/device, according to the current
32 // policy blob. Empty if not managed/not available. 31 // policy blob. Empty if not managed/not available.
33 std::string ManagedBy() const; 32 std::string ManagedBy() const;
34 33
35 // Refreshes policy. |callback| will be invoked after the operation completes 34 // Refreshes policy. |callback| will be invoked after the operation completes
36 // or aborts because of errors. 35 // or aborts because of errors.
37 void RefreshPolicy(const base::Closure& callback); 36 void RefreshPolicy(const base::Closure& callback);
38 37
39 CloudPolicyClient* client() { return client_.get(); }
40 CloudPolicyStore* store() { return store_; }
41
42 // CloudPolicyClient::Observer: 38 // CloudPolicyClient::Observer:
43 virtual void OnPolicyFetched(CloudPolicyClient* client) OVERRIDE; 39 virtual void OnPolicyFetched(CloudPolicyClient* client) OVERRIDE;
44 virtual void OnRegistrationStateChanged(CloudPolicyClient* client) OVERRIDE; 40 virtual void OnRegistrationStateChanged(CloudPolicyClient* client) OVERRIDE;
45 virtual void OnClientError(CloudPolicyClient* client) OVERRIDE; 41 virtual void OnClientError(CloudPolicyClient* client) OVERRIDE;
46 42
47 // CloudPolicyStore::Observer: 43 // CloudPolicyStore::Observer:
48 virtual void OnStoreLoaded(CloudPolicyStore* store) OVERRIDE; 44 virtual void OnStoreLoaded(CloudPolicyStore* store) OVERRIDE;
49 virtual void OnStoreError(CloudPolicyStore* store) OVERRIDE; 45 virtual void OnStoreError(CloudPolicyStore* store) OVERRIDE;
50 46
51 private: 47 private:
52 // Invokes the refresh callbacks and clears refresh state. 48 // Invokes the refresh callbacks and clears refresh state.
53 void RefreshCompleted(); 49 void RefreshCompleted();
54 50
55 // The client used to talk to the cloud. 51 // The client used to talk to the cloud.
56 scoped_ptr<CloudPolicyClient> client_; 52 CloudPolicyClient* client_;
57 53
58 // Takes care of persisting and decoding cloud policy. 54 // Takes care of persisting and decoding cloud policy.
59 CloudPolicyStore* store_; 55 CloudPolicyStore* store_;
60 56
61 // Tracks the state of a pending refresh operation, if any. 57 // Tracks the state of a pending refresh operation, if any.
62 enum { 58 enum {
63 // No refresh pending. 59 // No refresh pending.
64 REFRESH_NONE, 60 REFRESH_NONE,
65 // Policy fetch is pending. 61 // Policy fetch is pending.
66 REFRESH_POLICY_FETCH, 62 REFRESH_POLICY_FETCH,
67 // Policy store is pending. 63 // Policy store is pending.
68 REFRESH_POLICY_STORE, 64 REFRESH_POLICY_STORE,
69 } refresh_state_; 65 } refresh_state_;
70 66
71 // Callbacks to invoke upon policy refresh. 67 // Callbacks to invoke upon policy refresh.
72 std::vector<base::Closure> refresh_callbacks_; 68 std::vector<base::Closure> refresh_callbacks_;
73 69
74 DISALLOW_COPY_AND_ASSIGN(CloudPolicyService); 70 DISALLOW_COPY_AND_ASSIGN(CloudPolicyService);
75 }; 71 };
76 72
77 } // namespace policy 73 } // namespace policy
78 74
79 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_SERVICE_H_ 75 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698