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

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

Issue 11444029: Added UserPolicySigninService::FetchPolicyForSignedInUser(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review feedback Created 8 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
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/observer_list.h" 14 #include "base/observer_list.h"
15 #include "chrome/browser/policy/cloud_policy_client.h" 15 #include "chrome/browser/policy/cloud_policy_client.h"
16 #include "chrome/browser/policy/cloud_policy_constants.h" 16 #include "chrome/browser/policy/cloud_policy_constants.h"
17 #include "chrome/browser/policy/cloud_policy_store.h" 17 #include "chrome/browser/policy/cloud_policy_store.h"
18 18
19 namespace policy { 19 namespace policy {
20 20
21 // Coordinates cloud policy handling, moving downloaded policy from the client 21 // Coordinates cloud policy handling, moving downloaded policy from the client
22 // to the store, and setting up client registrations from cached data in the 22 // to the store, and setting up client registrations from cached data in the
23 // store. Also coordinates actions on policy refresh triggers. 23 // store. Also coordinates actions on policy refresh triggers.
24 class CloudPolicyService : public CloudPolicyClient::Observer, 24 class CloudPolicyService : public CloudPolicyClient::Observer,
25 public CloudPolicyStore::Observer { 25 public CloudPolicyStore::Observer {
26 public: 26 public:
27 // Callback invoked once the policy refresh attempt has completed. Passed
28 // bool parameter is true if the refresh was successful (no error).
29 typedef base::Callback<void(bool)> RefreshPolicyCallback;
30
27 class Observer { 31 class Observer {
28 public: 32 public:
29 // Invoked when CloudPolicyService has finished initializing (any initial 33 // Invoked when CloudPolicyService has finished initializing (any initial
30 // policy load activity has completed and the CloudPolicyClient has 34 // policy load activity has completed and the CloudPolicyClient has
31 // been registered, if possible). 35 // been registered, if possible).
32 virtual void OnInitializationCompleted(CloudPolicyService* service) = 0; 36 virtual void OnInitializationCompleted(CloudPolicyService* service) = 0;
33 virtual ~Observer() {} 37 virtual ~Observer() {}
34 }; 38 };
35 39
36 // |client| and |store| must remain valid for the object life time. 40 // |client| and |store| must remain valid for the object life time.
37 CloudPolicyService(CloudPolicyClient* client, CloudPolicyStore* store); 41 CloudPolicyService(CloudPolicyClient* client, CloudPolicyStore* store);
38 virtual ~CloudPolicyService(); 42 virtual ~CloudPolicyService();
39 43
40 // Returns the domain that manages this user/device, according to the current 44 // Returns the domain that manages this user/device, according to the current
41 // policy blob. Empty if not managed/not available. 45 // policy blob. Empty if not managed/not available.
42 std::string ManagedBy() const; 46 std::string ManagedBy() const;
43 47
44 // Refreshes policy. |callback| will be invoked after the operation completes 48 // Refreshes policy. |callback| will be invoked after the operation completes
45 // or aborts because of errors. 49 // or aborts because of errors.
46 void RefreshPolicy(const base::Closure& callback); 50 void RefreshPolicy(const RefreshPolicyCallback& callback);
47 51
48 // Adds/Removes an Observer for this object. 52 // Adds/Removes an Observer for this object.
49 void AddObserver(Observer* observer); 53 void AddObserver(Observer* observer);
50 void RemoveObserver(Observer* observer); 54 void RemoveObserver(Observer* observer);
51 55
52 // CloudPolicyClient::Observer: 56 // CloudPolicyClient::Observer:
53 virtual void OnPolicyFetched(CloudPolicyClient* client) OVERRIDE; 57 virtual void OnPolicyFetched(CloudPolicyClient* client) OVERRIDE;
54 virtual void OnRegistrationStateChanged(CloudPolicyClient* client) OVERRIDE; 58 virtual void OnRegistrationStateChanged(CloudPolicyClient* client) OVERRIDE;
55 virtual void OnClientError(CloudPolicyClient* client) OVERRIDE; 59 virtual void OnClientError(CloudPolicyClient* client) OVERRIDE;
56 60
57 // CloudPolicyStore::Observer: 61 // CloudPolicyStore::Observer:
58 virtual void OnStoreLoaded(CloudPolicyStore* store) OVERRIDE; 62 virtual void OnStoreLoaded(CloudPolicyStore* store) OVERRIDE;
59 virtual void OnStoreError(CloudPolicyStore* store) OVERRIDE; 63 virtual void OnStoreError(CloudPolicyStore* store) OVERRIDE;
60 64
61 bool IsInitializationComplete() const { return initialization_complete_; } 65 bool IsInitializationComplete() const { return initialization_complete_; }
62 66
63 private: 67 private:
64 // Helper function that is called when initialization may be complete, and 68 // Helper function that is called when initialization may be complete, and
65 // which is responsible for notifying observers. 69 // which is responsible for notifying observers.
66 void CheckInitializationCompleted(); 70 void CheckInitializationCompleted();
67 71
68 // Invokes the refresh callbacks and clears refresh state. 72 // Invokes the refresh callbacks and clears refresh state. The |success| flag
69 void RefreshCompleted(); 73 // is passed through to the refresh callbacks.
74 void RefreshCompleted(bool success);
70 75
71 // The client used to talk to the cloud. 76 // The client used to talk to the cloud.
72 CloudPolicyClient* client_; 77 CloudPolicyClient* client_;
73 78
74 // Takes care of persisting and decoding cloud policy. 79 // Takes care of persisting and decoding cloud policy.
75 CloudPolicyStore* store_; 80 CloudPolicyStore* store_;
76 81
77 // Tracks the state of a pending refresh operation, if any. 82 // Tracks the state of a pending refresh operation, if any.
78 enum { 83 enum {
79 // No refresh pending. 84 // No refresh pending.
80 REFRESH_NONE, 85 REFRESH_NONE,
81 // Policy fetch is pending. 86 // Policy fetch is pending.
82 REFRESH_POLICY_FETCH, 87 REFRESH_POLICY_FETCH,
83 // Policy store is pending. 88 // Policy store is pending.
84 REFRESH_POLICY_STORE, 89 REFRESH_POLICY_STORE,
85 } refresh_state_; 90 } refresh_state_;
86 91
87 // Callbacks to invoke upon policy refresh. 92 // Callbacks to invoke upon policy refresh.
88 std::vector<base::Closure> refresh_callbacks_; 93 std::vector<RefreshPolicyCallback> refresh_callbacks_;
89 94
90 // Set to true once the service is initialized (initial policy load/refresh 95 // Set to true once the service is initialized (initial policy load/refresh
91 // is complete). 96 // is complete).
92 bool initialization_complete_; 97 bool initialization_complete_;
93 98
94 // Observers who will receive notifications when the service has finished 99 // Observers who will receive notifications when the service has finished
95 // initializing. 100 // initializing.
96 ObserverList<Observer, true> observers_; 101 ObserverList<Observer, true> observers_;
97 102
98 DISALLOW_COPY_AND_ASSIGN(CloudPolicyService); 103 DISALLOW_COPY_AND_ASSIGN(CloudPolicyService);
99 }; 104 };
100 105
101 } // namespace policy 106 } // namespace policy
102 107
103 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_SERVICE_H_ 108 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/policy/cloud_policy_manager.cc ('k') | chrome/browser/policy/cloud_policy_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698