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_IDENTITY_STRATEGY_H_ | |
6 #define CHROME_BROWSER_POLICY_CLOUD_POLICY_IDENTITY_STRATEGY_H_ | |
7 #pragma once | |
8 | |
9 #include <string> | |
10 #include <vector> | |
gfeher
2011/02/15 13:17:01
Do you actually need vector here?
Jakob Kummerow
2011/02/21 12:12:15
Done.
| |
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, and the associated | |
18 // credentials. Responsibilities include storing and loading the token from | |
19 // disk, observing and triggering relevant notifications. | |
20 class CloudPolicyIdentityStrategy { | |
21 public: | |
22 class Observer { | |
23 public: | |
24 virtual ~Observer() {} | |
25 | |
26 // Notifies observers that the effective token for fetching policy has | |
27 // changed. The token can be queried by calling GetDeviceToken(). | |
28 virtual void OnDeviceTokenChanged() = 0; | |
29 | |
30 // Authentication credentials for talking to the device management service | |
31 // changed. New auth data is available through GetCredentials(). | |
32 virtual void OnCredentialsChanged() = 0; | |
33 }; | |
34 | |
35 CloudPolicyIdentityStrategy() {} | |
36 virtual ~CloudPolicyIdentityStrategy() {} | |
37 | |
38 void AddObserver(Observer* obs) { | |
39 observer_list_.AddObserver(obs); | |
40 } | |
41 | |
42 void RemoveObserver(Observer* obs) { | |
43 observer_list_.RemoveObserver(obs); | |
44 } | |
45 | |
46 // Returns the device management token, if available. Returns the empty string | |
47 // if the device token is currently unavailable. | |
48 virtual std::string GetDeviceToken() = 0; | |
49 | |
50 // Returns the device ID for this device. | |
51 virtual std::string GetDeviceID() = 0; | |
52 | |
53 // Retrieves authentication credentials to use when talking to the device | |
54 // management service. Returns true if the data is available and writes the | |
55 // values to the provided pointers. | |
56 virtual bool GetCredentials(std::string* username, | |
57 std::string* auth_token) = 0; | |
58 | |
59 // Notifies the identity strategy that a new token has been fetched. It is up | |
60 // to the identity strategy to store the token, decide whether it is going | |
61 // to be used, send out an appropriate OnDeviceTokenChanged() notification | |
62 // and return the new token in GetDeviceToken() calls. | |
63 virtual void OnDeviceTokenAvailable(const std::string& token) = 0; | |
64 | |
65 protected: | |
66 // Notify observers that the effective token has changed. | |
67 void NotifyDeviceTokenChanged() { | |
68 FOR_EACH_OBSERVER(Observer, observer_list_, OnDeviceTokenChanged()); | |
69 } | |
70 | |
71 // Notify observers about authentication data change. | |
72 void NotifyAuthChanged() { | |
73 FOR_EACH_OBSERVER(Observer, observer_list_, OnCredentialsChanged()); | |
74 } | |
75 | |
76 private: | |
77 ObserverList<Observer, true> observer_list_; | |
78 | |
79 DISALLOW_COPY_AND_ASSIGN(CloudPolicyIdentityStrategy); | |
80 }; | |
81 | |
82 } // namespace policy | |
83 | |
84 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_IDENTITY_STRATEGY_H_ | |
OLD | NEW |