OLD | NEW |
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_constants.h" | |
17 #include "components/policy/core/common/cloud/cloud_policy_store.h" | 16 #include "components/policy/core/common/cloud/cloud_policy_store.h" |
18 #include "components/policy/policy_export.h" | 17 #include "components/policy/policy_export.h" |
19 | 18 |
20 namespace policy { | 19 namespace policy { |
21 | 20 |
22 // Coordinates cloud policy handling, moving downloaded policy from the client | 21 // Coordinates cloud policy handling, moving downloaded policy from the client |
23 // 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 |
24 // store. Also coordinates actions on policy refresh triggers. | 23 // store. Also coordinates actions on policy refresh triggers. |
25 class POLICY_EXPORT CloudPolicyService : public CloudPolicyClient::Observer, | 24 class POLICY_EXPORT CloudPolicyService : public CloudPolicyClient::Observer, |
26 public CloudPolicyStore::Observer { | 25 public CloudPolicyStore::Observer { |
27 public: | 26 public: |
28 // Callback invoked once the policy refresh attempt has completed. Passed | 27 // Callback invoked once the policy refresh attempt has completed. Passed |
29 // bool parameter is true if the refresh was successful (no error). | 28 // bool parameter is true if the refresh was successful (no error). |
30 typedef base::Callback<void(bool)> RefreshPolicyCallback; | 29 typedef base::Callback<void(bool)> RefreshPolicyCallback; |
31 | 30 |
32 class POLICY_EXPORT Observer { | 31 class POLICY_EXPORT Observer { |
33 public: | 32 public: |
34 // Invoked when CloudPolicyService has finished initializing (any initial | 33 // Invoked when CloudPolicyService has finished initializing (any initial |
35 // policy load activity has completed and the CloudPolicyClient has | 34 // policy load activity has completed and the CloudPolicyClient has |
36 // been registered, if possible). | 35 // been registered, if possible). |
37 virtual void OnInitializationCompleted(CloudPolicyService* service) = 0; | 36 virtual void OnInitializationCompleted(CloudPolicyService* service) = 0; |
38 virtual ~Observer() {} | 37 virtual ~Observer() {} |
39 }; | 38 }; |
40 | 39 |
41 // |client| and |store| must remain valid for the object life time. | 40 // |client| and |store| must remain valid for the object life time. |
42 CloudPolicyService(const PolicyNamespaceKey& policy_ns_key, | 41 CloudPolicyService(const std::string& policy_type, |
| 42 const std::string& settings_entity_id, |
43 CloudPolicyClient* client, | 43 CloudPolicyClient* client, |
44 CloudPolicyStore* store); | 44 CloudPolicyStore* store); |
45 ~CloudPolicyService() override; | 45 ~CloudPolicyService() override; |
46 | 46 |
47 // 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 |
48 // policy blob. Empty if not managed/not available. | 48 // policy blob. Empty if not managed/not available. |
49 std::string ManagedBy() const; | 49 std::string ManagedBy() const; |
50 | 50 |
51 // Refreshes policy. |callback| will be invoked after the operation completes | 51 // Refreshes policy. |callback| will be invoked after the operation completes |
52 // or aborts because of errors. | 52 // or aborts because of errors. |
(...skipping 16 matching lines...) Expand all Loading... |
69 | 69 |
70 private: | 70 private: |
71 // Helper function that is called when initialization may be complete, and | 71 // Helper function that is called when initialization may be complete, and |
72 // which is responsible for notifying observers. | 72 // which is responsible for notifying observers. |
73 void CheckInitializationCompleted(); | 73 void CheckInitializationCompleted(); |
74 | 74 |
75 // Invokes the refresh callbacks and clears refresh state. The |success| flag | 75 // Invokes the refresh callbacks and clears refresh state. The |success| flag |
76 // is passed through to the refresh callbacks. | 76 // is passed through to the refresh callbacks. |
77 void RefreshCompleted(bool success); | 77 void RefreshCompleted(bool success); |
78 | 78 |
79 // The policy namespace fetched by |client_| and expected by |store_|. | 79 // The policy type that will be fetched by the |client_|, with the optional |
80 PolicyNamespaceKey policy_ns_key_; | 80 // |settings_entity_id_|. |
| 81 std::string policy_type_; |
| 82 std::string settings_entity_id_; |
81 | 83 |
82 // The client used to talk to the cloud. | 84 // The client used to talk to the cloud. |
83 CloudPolicyClient* client_; | 85 CloudPolicyClient* client_; |
84 | 86 |
85 // Takes care of persisting and decoding cloud policy. | 87 // Takes care of persisting and decoding cloud policy. |
86 CloudPolicyStore* store_; | 88 CloudPolicyStore* store_; |
87 | 89 |
88 // Tracks the state of a pending refresh operation, if any. | 90 // Tracks the state of a pending refresh operation, if any. |
89 enum { | 91 enum { |
90 // No refresh pending. | 92 // No refresh pending. |
(...skipping 14 matching lines...) Expand all Loading... |
105 // Observers who will receive notifications when the service has finished | 107 // Observers who will receive notifications when the service has finished |
106 // initializing. | 108 // initializing. |
107 ObserverList<Observer, true> observers_; | 109 ObserverList<Observer, true> observers_; |
108 | 110 |
109 DISALLOW_COPY_AND_ASSIGN(CloudPolicyService); | 111 DISALLOW_COPY_AND_ASSIGN(CloudPolicyService); |
110 }; | 112 }; |
111 | 113 |
112 } // namespace policy | 114 } // namespace policy |
113 | 115 |
114 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_SERVICE_H_ | 116 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_SERVICE_H_ |
OLD | NEW |