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

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

Issue 814123006: Revert of Implemented consumer management unenrollment. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dcpm
Patch Set: Created 5 years, 11 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
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
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 "components/policy/core/common/cloud/cloud_policy_client.h" 15 #include "components/policy/core/common/cloud/cloud_policy_client.h"
16 #include "components/policy/core/common/cloud/cloud_policy_store.h" 16 #include "components/policy/core/common/cloud/cloud_policy_store.h"
17 #include "components/policy/policy_export.h" 17 #include "components/policy/policy_export.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 POLICY_EXPORT CloudPolicyService : public CloudPolicyClient::Observer, 24 class POLICY_EXPORT 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 27 // Callback invoked once the policy refresh attempt has completed. Passed
28 // bool parameter is true if the refresh was successful (no error). 28 // bool parameter is true if the refresh was successful (no error).
29 using RefreshPolicyCallback = base::Callback<void(bool)>; 29 typedef base::Callback<void(bool)> RefreshPolicyCallback;
30
31 // Callback invoked once the unregister attempt has completed. Passed bool
32 // parameter is true if unregistering was successful (no error).
33 using UnregisterCallback = base::Callback<void(bool)>;
34 30
35 class POLICY_EXPORT Observer { 31 class POLICY_EXPORT Observer {
36 public: 32 public:
37 // Invoked when CloudPolicyService has finished initializing (any initial 33 // Invoked when CloudPolicyService has finished initializing (any initial
38 // policy load activity has completed and the CloudPolicyClient has 34 // policy load activity has completed and the CloudPolicyClient has
39 // been registered, if possible). 35 // been registered, if possible).
40 virtual void OnInitializationCompleted(CloudPolicyService* service) = 0; 36 virtual void OnInitializationCompleted(CloudPolicyService* service) = 0;
41 virtual ~Observer() {} 37 virtual ~Observer() {}
42 }; 38 };
43 39
44 // |client| and |store| must remain valid for the object life time. 40 // |client| and |store| must remain valid for the object life time.
45 CloudPolicyService(const std::string& policy_type, 41 CloudPolicyService(const std::string& policy_type,
46 const std::string& settings_entity_id, 42 const std::string& settings_entity_id,
47 CloudPolicyClient* client, 43 CloudPolicyClient* client,
48 CloudPolicyStore* store); 44 CloudPolicyStore* store);
49 ~CloudPolicyService() override; 45 ~CloudPolicyService() override;
50 46
51 // Returns the domain that manages this user/device, according to the current 47 // Returns the domain that manages this user/device, according to the current
52 // policy blob. Empty if not managed/not available. 48 // policy blob. Empty if not managed/not available.
53 std::string ManagedBy() const; 49 std::string ManagedBy() const;
54 50
55 // Refreshes policy. |callback| will be invoked after the operation completes 51 // Refreshes policy. |callback| will be invoked after the operation completes
56 // or aborts because of errors. 52 // or aborts because of errors.
57 void RefreshPolicy(const RefreshPolicyCallback& callback); 53 void RefreshPolicy(const RefreshPolicyCallback& callback);
58 54
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
64 // Adds/Removes an Observer for this object. 55 // Adds/Removes an Observer for this object.
65 void AddObserver(Observer* observer); 56 void AddObserver(Observer* observer);
66 void RemoveObserver(Observer* observer); 57 void RemoveObserver(Observer* observer);
67 58
68 // CloudPolicyClient::Observer: 59 // CloudPolicyClient::Observer:
69 void OnPolicyFetched(CloudPolicyClient* client) override; 60 void OnPolicyFetched(CloudPolicyClient* client) override;
70 void OnRegistrationStateChanged(CloudPolicyClient* client) override; 61 void OnRegistrationStateChanged(CloudPolicyClient* client) override;
71 void OnClientError(CloudPolicyClient* client) override; 62 void OnClientError(CloudPolicyClient* client) override;
72 63
73 // CloudPolicyStore::Observer: 64 // CloudPolicyStore::Observer:
74 void OnStoreLoaded(CloudPolicyStore* store) override; 65 void OnStoreLoaded(CloudPolicyStore* store) override;
75 void OnStoreError(CloudPolicyStore* store) override; 66 void OnStoreError(CloudPolicyStore* store) override;
76 67
77 bool IsInitializationComplete() const { return initialization_complete_; } 68 bool IsInitializationComplete() const { return initialization_complete_; }
78 69
79 private: 70 private:
80 // Helper function that is called when initialization may be complete, and 71 // Helper function that is called when initialization may be complete, and
81 // which is responsible for notifying observers. 72 // which is responsible for notifying observers.
82 void CheckInitializationCompleted(); 73 void CheckInitializationCompleted();
83 74
84 // Invokes the refresh callbacks and clears refresh state. The |success| flag 75 // Invokes the refresh callbacks and clears refresh state. The |success| flag
85 // is passed through to the refresh callbacks. 76 // is passed through to the refresh callbacks.
86 void RefreshCompleted(bool success); 77 void RefreshCompleted(bool success);
87 78
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
92 // The policy type that will be fetched by the |client_|, with the optional 79 // The policy type that will be fetched by the |client_|, with the optional
93 // |settings_entity_id_|. 80 // |settings_entity_id_|.
94 std::string policy_type_; 81 std::string policy_type_;
95 std::string settings_entity_id_; 82 std::string settings_entity_id_;
96 83
97 // The client used to talk to the cloud. 84 // The client used to talk to the cloud.
98 CloudPolicyClient* client_; 85 CloudPolicyClient* client_;
99 86
100 // Takes care of persisting and decoding cloud policy. 87 // Takes care of persisting and decoding cloud policy.
101 CloudPolicyStore* store_; 88 CloudPolicyStore* store_;
102 89
103 // Tracks the state of a pending refresh operation, if any. 90 // Tracks the state of a pending refresh operation, if any.
104 enum { 91 enum {
105 // No refresh pending. 92 // No refresh pending.
106 REFRESH_NONE, 93 REFRESH_NONE,
107 // Policy fetch is pending. 94 // Policy fetch is pending.
108 REFRESH_POLICY_FETCH, 95 REFRESH_POLICY_FETCH,
109 // Policy store is pending. 96 // Policy store is pending.
110 REFRESH_POLICY_STORE, 97 REFRESH_POLICY_STORE,
111 } refresh_state_; 98 } refresh_state_;
112 99
113 // Tracks the state of a pending unregister operation, if any.
114 enum {
115 UNREGISTER_NONE,
116 UNREGISTER_PENDING,
117 } unregister_state_;
118
119 // Callbacks to invoke upon policy refresh. 100 // Callbacks to invoke upon policy refresh.
120 std::vector<RefreshPolicyCallback> refresh_callbacks_; 101 std::vector<RefreshPolicyCallback> refresh_callbacks_;
121 102
122 UnregisterCallback unregister_callback_;
123
124 // Set to true once the service is initialized (initial policy load/refresh 103 // Set to true once the service is initialized (initial policy load/refresh
125 // is complete). 104 // is complete).
126 bool initialization_complete_; 105 bool initialization_complete_;
127 106
128 // Observers who will receive notifications when the service has finished 107 // Observers who will receive notifications when the service has finished
129 // initializing. 108 // initializing.
130 ObserverList<Observer, true> observers_; 109 ObserverList<Observer, true> observers_;
131 110
132 DISALLOW_COPY_AND_ASSIGN(CloudPolicyService); 111 DISALLOW_COPY_AND_ASSIGN(CloudPolicyService);
133 }; 112 };
134 113
135 } // namespace policy 114 } // namespace policy
136 115
137 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_SERVICE_H_ 116 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/chrome_tests_unit.gypi ('k') | components/policy/core/common/cloud/cloud_policy_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698