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

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: Rebase. 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 typedef base::Callback<void(bool)> RefreshPolicyCallback; 29 using RefreshPolicyCallback = base::Callback<void(bool)>;
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)>;
30 34
31 class POLICY_EXPORT Observer { 35 class POLICY_EXPORT Observer {
32 public: 36 public:
33 // Invoked when CloudPolicyService has finished initializing (any initial 37 // Invoked when CloudPolicyService has finished initializing (any initial
34 // policy load activity has completed and the CloudPolicyClient has 38 // policy load activity has completed and the CloudPolicyClient has
35 // been registered, if possible). 39 // been registered, if possible).
36 virtual void OnInitializationCompleted(CloudPolicyService* service) = 0; 40 virtual void OnInitializationCompleted(CloudPolicyService* service) = 0;
37 virtual ~Observer() {} 41 virtual ~Observer() {}
38 }; 42 };
39 43
40 // |client| and |store| must remain valid for the object life time. 44 // |client| and |store| must remain valid for the object life time.
41 CloudPolicyService(const std::string& policy_type, 45 CloudPolicyService(const std::string& policy_type,
42 const std::string& settings_entity_id, 46 const std::string& settings_entity_id,
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 type that will be fetched by the |client_|, with the optional 92 // The policy type that will be fetched by the |client_|, with the optional
80 // |settings_entity_id_|. 93 // |settings_entity_id_|.
81 std::string policy_type_; 94 std::string policy_type_;
82 std::string settings_entity_id_; 95 std::string settings_entity_id_;
83 96
84 // The client used to talk to the cloud. 97 // The client used to talk to the cloud.
85 CloudPolicyClient* client_; 98 CloudPolicyClient* client_;
86 99
87 // Takes care of persisting and decoding cloud policy. 100 // Takes care of persisting and decoding cloud policy.
88 CloudPolicyStore* store_; 101 CloudPolicyStore* store_;
89 102
90 // Tracks the state of a pending refresh operation, if any. 103 // Tracks the state of a pending refresh operation, if any.
91 enum { 104 enum {
92 // No refresh pending. 105 // No refresh pending.
93 REFRESH_NONE, 106 REFRESH_NONE,
94 // Policy fetch is pending. 107 // Policy fetch is pending.
95 REFRESH_POLICY_FETCH, 108 REFRESH_POLICY_FETCH,
96 // Policy store is pending. 109 // Policy store is pending.
97 REFRESH_POLICY_STORE, 110 REFRESH_POLICY_STORE,
98 } refresh_state_; 111 } refresh_state_;
99 112
113 // Tracks the state of a pending unregister operation, if any.
114 enum {
115 UNREGISTER_NONE,
116 UNREGISTER_PENDING,
117 } unregister_state_;
118
100 // Callbacks to invoke upon policy refresh. 119 // Callbacks to invoke upon policy refresh.
101 std::vector<RefreshPolicyCallback> refresh_callbacks_; 120 std::vector<RefreshPolicyCallback> refresh_callbacks_;
102 121
122 UnregisterCallback unregister_callback_;
123
103 // Set to true once the service is initialized (initial policy load/refresh 124 // Set to true once the service is initialized (initial policy load/refresh
104 // is complete). 125 // is complete).
105 bool initialization_complete_; 126 bool initialization_complete_;
106 127
107 // Observers who will receive notifications when the service has finished 128 // Observers who will receive notifications when the service has finished
108 // initializing. 129 // initializing.
109 ObserverList<Observer, true> observers_; 130 ObserverList<Observer, true> observers_;
110 131
111 DISALLOW_COPY_AND_ASSIGN(CloudPolicyService); 132 DISALLOW_COPY_AND_ASSIGN(CloudPolicyService);
112 }; 133 };
113 134
114 } // namespace policy 135 } // namespace policy
115 136
116 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_SERVICE_H_ 137 #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