OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_POLICY_CLOUD_POLICY_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_POLICY_CLOUD_POLICY_CONTROLLER_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/observer_list.h" |
| 13 |
| 14 namespace policy { |
| 15 |
| 16 // Manages a device management token, i.e. an identifier that represents a |
| 17 // registration with the device management service. |
| 18 class CloudPolicyController { |
| 19 public: |
| 20 class Observer { |
| 21 public: |
| 22 virtual ~Observer() {} |
| 23 |
| 24 // Notifies observers that the effective token for fetching policy has |
| 25 // changed. The token can be queried by calling GetDeviceToken(). |
| 26 virtual void OnTokenChanged() = 0; |
| 27 |
| 28 // Authentication credentials for talking to the device management service |
| 29 // changed. New auth data is available through GetCredentials(). |
| 30 virtual void OnCredentialsChanged() = 0; |
| 31 }; |
| 32 |
| 33 CloudPolicyController() {} |
| 34 virtual ~CloudPolicyController() {} |
| 35 |
| 36 void AddObserver(Observer* obs) { |
| 37 observer_list_.AddObserver(obs); |
| 38 } |
| 39 |
| 40 void RemoveObserver(Observer* obs) { |
| 41 observer_list_.RemoveObserver(obs); |
| 42 } |
| 43 |
| 44 // Returns the device management token, if available. Returns the empty string |
| 45 // if the device token is currently unavailable. |
| 46 virtual std::string GetDeviceToken() = 0; |
| 47 |
| 48 // Returns the device ID for this device. |
| 49 virtual std::string GetDeviceID() = 0; |
| 50 |
| 51 // Retrieves authentication credentials to use when talking to the device |
| 52 // management service. Returns true if the data is available and writes the |
| 53 // values to the provided pointers. |
| 54 virtual bool GetCredentials(std::string* username, |
| 55 std::string* auth_token) = 0; |
| 56 |
| 57 // Notifies the provider that a new token has been fetched. It is up to the |
| 58 // provider to decide that token is going to be used, in which case it should |
| 59 // send a OnTokenChanged() notification an return the new token in |
| 60 // GetDeviceToken() calls. |
| 61 virtual void OnTokenAvailable(const std::string& token) = 0; |
| 62 |
| 63 protected: |
| 64 // Notify observers that the effective token has changed. |
| 65 void NotifyTokenChanged() { |
| 66 FOR_EACH_OBSERVER(Observer, observer_list_, OnTokenChanged()); |
| 67 } |
| 68 |
| 69 // Notify observers about authentication data change. |
| 70 void NotifyAuthChanged() { |
| 71 FOR_EACH_OBSERVER(Observer, observer_list_, OnCredentialsChanged()); |
| 72 } |
| 73 |
| 74 private: |
| 75 ObserverList<Observer, true> observer_list_; |
| 76 |
| 77 DISALLOW_COPY_AND_ASSIGN(CloudPolicyController); |
| 78 }; |
| 79 |
| 80 } // namespace policy |
| 81 |
| 82 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_CONTROLLER_H_ |
OLD | NEW |