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

Side by Side Diff: components/policy/core/common/cloud/cloud_policy_service.h

Issue 751703003: Implemented consumer management unenrollment. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dcpm
Patch Set: Created 6 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
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 COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_SERVICE_H_ 5 #ifndef COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_SERVICE_H_
6 #define COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_SERVICE_H_ 6 #define COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_SERVICE_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 11 matching lines...) Expand all
22 // Coordinates cloud policy handling, moving downloaded policy from the client 22 // Coordinates cloud policy handling, moving downloaded policy from the client
23 // to the store, and setting up client registrations from cached data in the 23 // to the store, and setting up client registrations from cached data in the
24 // store. Also coordinates actions on policy refresh triggers. 24 // store. Also coordinates actions on policy refresh triggers.
25 class POLICY_EXPORT CloudPolicyService : public CloudPolicyClient::Observer, 25 class POLICY_EXPORT CloudPolicyService : public CloudPolicyClient::Observer,
26 public CloudPolicyStore::Observer { 26 public CloudPolicyStore::Observer {
27 public: 27 public:
28 // Callback invoked once the policy refresh attempt has completed. Passed 28 // Callback invoked once the policy refresh attempt has completed. Passed
29 // bool parameter is true if the refresh was successful (no error). 29 // bool parameter is true if the refresh was successful (no error).
30 typedef base::Callback<void(bool)> RefreshPolicyCallback; 30 typedef base::Callback<void(bool)> RefreshPolicyCallback;
31 31
32 // Callback invoked once the unregister attempt has completed. Passed bool
33 // parameter is true if unregistering was successful (no error).
34 typedef base::Callback<void(bool)> UnregisterCallback;
bartfab (slow) 2014/11/28 13:25:19 Nit: Use C++11 using = instead of typedef.
davidyu 2014/12/01 17:05:23 Done.
35
32 class POLICY_EXPORT Observer { 36 class POLICY_EXPORT Observer {
33 public: 37 public:
34 // Invoked when CloudPolicyService has finished initializing (any initial 38 // Invoked when CloudPolicyService has finished initializing (any initial
35 // policy load activity has completed and the CloudPolicyClient has 39 // policy load activity has completed and the CloudPolicyClient has
36 // been registered, if possible). 40 // been registered, if possible).
37 virtual void OnInitializationCompleted(CloudPolicyService* service) = 0; 41 virtual void OnInitializationCompleted(CloudPolicyService* service) = 0;
38 virtual ~Observer() {} 42 virtual ~Observer() {}
39 }; 43 };
40 44
41 // |client| and |store| must remain valid for the object life time. 45 // |client| and |store| must remain valid for the object life time.
42 CloudPolicyService(const PolicyNamespaceKey& policy_ns_key, 46 CloudPolicyService(const PolicyNamespaceKey& policy_ns_key,
43 CloudPolicyClient* client, 47 CloudPolicyClient* client,
44 CloudPolicyStore* store); 48 CloudPolicyStore* store);
45 ~CloudPolicyService() override; 49 ~CloudPolicyService() override;
46 50
47 // Returns the domain that manages this user/device, according to the current 51 // Returns the domain that manages this user/device, according to the current
48 // policy blob. Empty if not managed/not available. 52 // policy blob. Empty if not managed/not available.
49 std::string ManagedBy() const; 53 std::string ManagedBy() const;
50 54
51 // Refreshes policy. |callback| will be invoked after the operation completes 55 // Refreshes policy. |callback| will be invoked after the operation completes
52 // or aborts because of errors. 56 // or aborts because of errors.
53 void RefreshPolicy(const RefreshPolicyCallback& callback); 57 void RefreshPolicy(const RefreshPolicyCallback& callback);
54 58
59 // Unregisters the device. |callback| will be invoked after the operation
60 // completes or aborts because of errors. All pending refresh policy requests
61 // will be aborted, and no further refresh policy requests will be allowed.
62 void Unregister(const UnregisterCallback& callback);
63
55 // Adds/Removes an Observer for this object. 64 // Adds/Removes an Observer for this object.
56 void AddObserver(Observer* observer); 65 void AddObserver(Observer* observer);
57 void RemoveObserver(Observer* observer); 66 void RemoveObserver(Observer* observer);
58 67
59 // CloudPolicyClient::Observer: 68 // CloudPolicyClient::Observer:
60 void OnPolicyFetched(CloudPolicyClient* client) override; 69 void OnPolicyFetched(CloudPolicyClient* client) override;
61 void OnRegistrationStateChanged(CloudPolicyClient* client) override; 70 void OnRegistrationStateChanged(CloudPolicyClient* client) override;
62 void OnClientError(CloudPolicyClient* client) override; 71 void OnClientError(CloudPolicyClient* client) override;
63 72
64 // CloudPolicyStore::Observer: 73 // CloudPolicyStore::Observer:
65 void OnStoreLoaded(CloudPolicyStore* store) override; 74 void OnStoreLoaded(CloudPolicyStore* store) override;
66 void OnStoreError(CloudPolicyStore* store) override; 75 void OnStoreError(CloudPolicyStore* store) override;
67 76
68 bool IsInitializationComplete() const { return initialization_complete_; } 77 bool IsInitializationComplete() const { return initialization_complete_; }
69 78
70 private: 79 private:
71 // Helper function that is called when initialization may be complete, and 80 // Helper function that is called when initialization may be complete, and
72 // which is responsible for notifying observers. 81 // which is responsible for notifying observers.
73 void CheckInitializationCompleted(); 82 void CheckInitializationCompleted();
74 83
75 // Invokes the refresh callbacks and clears refresh state. The |success| flag 84 // Invokes the refresh callbacks and clears refresh state. The |success| flag
76 // is passed through to the refresh callbacks. 85 // is passed through to the refresh callbacks.
77 void RefreshCompleted(bool success); 86 void RefreshCompleted(bool success);
78 87
88 // Invokes the unregister callback and clears unregister state. The |success|
89 // flag is passed through to the unregister callback.
90 void UnregisterCompleted(bool success);
91
79 // The policy namespace fetched by |client_| and expected by |store_|. 92 // The policy namespace fetched by |client_| and expected by |store_|.
80 PolicyNamespaceKey policy_ns_key_; 93 PolicyNamespaceKey policy_ns_key_;
81 94
82 // The client used to talk to the cloud. 95 // The client used to talk to the cloud.
83 CloudPolicyClient* client_; 96 CloudPolicyClient* client_;
84 97
85 // Takes care of persisting and decoding cloud policy. 98 // Takes care of persisting and decoding cloud policy.
86 CloudPolicyStore* store_; 99 CloudPolicyStore* store_;
87 100
88 // Tracks the state of a pending refresh operation, if any. 101 // Tracks the state of a pending refresh operation, if any.
89 enum { 102 enum {
90 // No refresh pending. 103 // No refresh pending.
91 REFRESH_NONE, 104 REFRESH_NONE,
92 // Policy fetch is pending. 105 // Policy fetch is pending.
93 REFRESH_POLICY_FETCH, 106 REFRESH_POLICY_FETCH,
94 // Policy store is pending. 107 // Policy store is pending.
95 REFRESH_POLICY_STORE, 108 REFRESH_POLICY_STORE,
96 } refresh_state_; 109 } refresh_state_;
97 110
111 // Tracks the state of a pending unregister operation, if any.
112 enum {
113 UNREGISTER_NONE,
114 UNREGISTER_PENDING,
115 } unregister_state_;
116
98 // Callbacks to invoke upon policy refresh. 117 // Callbacks to invoke upon policy refresh.
99 std::vector<RefreshPolicyCallback> refresh_callbacks_; 118 std::vector<RefreshPolicyCallback> refresh_callbacks_;
100 119
120 UnregisterCallback unregister_callback_;
121
101 // Set to true once the service is initialized (initial policy load/refresh 122 // Set to true once the service is initialized (initial policy load/refresh
102 // is complete). 123 // is complete).
103 bool initialization_complete_; 124 bool initialization_complete_;
104 125
105 // Observers who will receive notifications when the service has finished 126 // Observers who will receive notifications when the service has finished
106 // initializing. 127 // initializing.
107 ObserverList<Observer, true> observers_; 128 ObserverList<Observer, true> observers_;
108 129
109 DISALLOW_COPY_AND_ASSIGN(CloudPolicyService); 130 DISALLOW_COPY_AND_ASSIGN(CloudPolicyService);
110 }; 131 };
111 132
112 } // namespace policy 133 } // namespace policy
113 134
114 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_SERVICE_H_ 135 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698