| 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 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "chrome/browser/policy/cloud_policy_client.h" | 16 #include "chrome/browser/policy/cloud_policy_client.h" |
| 17 #include "chrome/browser/policy/cloud_policy_constants.h" | 17 #include "chrome/browser/policy/cloud_policy_constants.h" |
| 18 #include "chrome/browser/policy/cloud_policy_store.h" | 18 #include "chrome/browser/policy/cloud_policy_store.h" |
| 19 | 19 |
| 20 namespace policy { | 20 namespace policy { |
| 21 | 21 |
| 22 // Coordinates cloud policy handling, hosting the cloud policy client, fetching | 22 // Coordinates cloud policy handling, hosting the cloud policy client, fetching |
| 23 // new policy, and updating the local policy cache when new policy becomes | 23 // new policy, and updating the local policy cache when new policy becomes |
| 24 // available. | 24 // available. |
| 25 class CloudPolicyService : public CloudPolicyClient::Observer, | 25 class CloudPolicyService : public CloudPolicyClient::Observer, |
| 26 public CloudPolicyStore::Observer { | 26 public CloudPolicyStore::Observer { |
| 27 public: | 27 public: |
| 28 CloudPolicyService(scoped_ptr<CloudPolicyClient> client, | 28 CloudPolicyService(scoped_ptr<CloudPolicyClient> client, |
| 29 scoped_ptr<CloudPolicyStore> store); | 29 CloudPolicyStore* store); |
| 30 virtual ~CloudPolicyService(); | 30 virtual ~CloudPolicyService(); |
| 31 | 31 |
| 32 // Returns the domain that manages this user/device, according to the current | 32 // Returns the domain that manages this user/device, according to the current |
| 33 // policy blob. Empty if not managed/not available. | 33 // policy blob. Empty if not managed/not available. |
| 34 std::string ManagedBy() const; | 34 std::string ManagedBy() const; |
| 35 | 35 |
| 36 // Refreshes policy. |callback| will be invoked after the operation completes | 36 // Refreshes policy. |callback| will be invoked after the operation completes |
| 37 // or aborts because of errors. | 37 // or aborts because of errors. |
| 38 void RefreshPolicy(const base::Closure& callback); | 38 void RefreshPolicy(const base::Closure& callback); |
| 39 | 39 |
| 40 CloudPolicyClient* client() { return client_.get(); } | 40 CloudPolicyClient* client() { return client_.get(); } |
| 41 CloudPolicyStore* store() { return store_.get(); } | 41 CloudPolicyStore* store() { return store_; } |
| 42 | 42 |
| 43 // CloudPolicyClient::Observer: | 43 // CloudPolicyClient::Observer: |
| 44 virtual void OnPolicyFetched(CloudPolicyClient* client) OVERRIDE; | 44 virtual void OnPolicyFetched(CloudPolicyClient* client) OVERRIDE; |
| 45 virtual void OnRegistrationStateChanged(CloudPolicyClient* client) OVERRIDE; | 45 virtual void OnRegistrationStateChanged(CloudPolicyClient* client) OVERRIDE; |
| 46 virtual void OnClientError(CloudPolicyClient* client) OVERRIDE; | 46 virtual void OnClientError(CloudPolicyClient* client) OVERRIDE; |
| 47 | 47 |
| 48 // CloudPolicyStore::Observer: | 48 // CloudPolicyStore::Observer: |
| 49 virtual void OnStoreLoaded(CloudPolicyStore* store) OVERRIDE; | 49 virtual void OnStoreLoaded(CloudPolicyStore* store) OVERRIDE; |
| 50 virtual void OnStoreError(CloudPolicyStore* store) OVERRIDE; | 50 virtual void OnStoreError(CloudPolicyStore* store) OVERRIDE; |
| 51 | 51 |
| 52 private: | 52 private: |
| 53 // Invokes the refresh callbacks and clears refresh state. | 53 // Invokes the refresh callbacks and clears refresh state. |
| 54 void RefreshCompleted(); | 54 void RefreshCompleted(); |
| 55 | 55 |
| 56 // The client used to talk to the cloud. | 56 // The client used to talk to the cloud. |
| 57 scoped_ptr<CloudPolicyClient> client_; | 57 scoped_ptr<CloudPolicyClient> client_; |
| 58 | 58 |
| 59 // Takes care of persisting and decoding cloud policy. | 59 // Takes care of persisting and decoding cloud policy. |
| 60 scoped_ptr<CloudPolicyStore> store_; | 60 CloudPolicyStore* store_; |
| 61 | 61 |
| 62 // Tracks the state of a pending refresh operation, if any. | 62 // Tracks the state of a pending refresh operation, if any. |
| 63 enum { | 63 enum { |
| 64 // No refresh pending. | 64 // No refresh pending. |
| 65 REFRESH_NONE, | 65 REFRESH_NONE, |
| 66 // Policy fetch is pending. | 66 // Policy fetch is pending. |
| 67 REFRESH_POLICY_FETCH, | 67 REFRESH_POLICY_FETCH, |
| 68 // Policy store is pending. | 68 // Policy store is pending. |
| 69 REFRESH_POLICY_STORE, | 69 REFRESH_POLICY_STORE, |
| 70 } refresh_state_; | 70 } refresh_state_; |
| 71 | 71 |
| 72 // Callbacks to invoke upon policy refresh. | 72 // Callbacks to invoke upon policy refresh. |
| 73 std::vector<base::Closure> refresh_callbacks_; | 73 std::vector<base::Closure> refresh_callbacks_; |
| 74 | 74 |
| 75 DISALLOW_COPY_AND_ASSIGN(CloudPolicyService); | 75 DISALLOW_COPY_AND_ASSIGN(CloudPolicyService); |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 } // namespace policy | 78 } // namespace policy |
| 79 | 79 |
| 80 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_SERVICE_H_ | 80 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_SERVICE_H_ |
| OLD | NEW |