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

Side by Side Diff: chrome/browser/policy/cloud_policy_identity_strategy.h

Issue 6520008: Device policy infrastructure (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix nits Created 9 years, 10 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 | Annotate | Revision Log
OLDNEW
(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
11 #include "base/observer_list.h"
12
13 namespace policy {
14
15 // Manages a device management token, i.e. an identifier that represents a
16 // registration with the device management service, and the associated
17 // credentials. Responsibilities include storing and loading the token from
18 // disk, observing and triggering relevant notifications.
19 class CloudPolicyIdentityStrategy {
20 public:
21 class Observer {
22 public:
23 virtual ~Observer() {}
24
25 // Notifies observers that the effective token for fetching policy has
26 // changed. The token can be queried by calling GetDeviceToken().
27 virtual void OnDeviceTokenChanged() = 0;
28
29 // Authentication credentials for talking to the device management service
30 // changed. New auth data is available through GetCredentials().
31 virtual void OnCredentialsChanged() = 0;
32 };
33
34 CloudPolicyIdentityStrategy() {}
35 virtual ~CloudPolicyIdentityStrategy() {}
36
37 void AddObserver(Observer* obs) {
38 observer_list_.AddObserver(obs);
39 }
40
41 void RemoveObserver(Observer* obs) {
42 observer_list_.RemoveObserver(obs);
43 }
44
45 // Returns the device management token, if available. Returns the empty string
46 // if the device token is currently unavailable.
47 virtual std::string GetDeviceToken() = 0;
48
49 // Returns the device ID for this device.
50 virtual std::string GetDeviceID() = 0;
51
52 // Retrieves authentication credentials to use when talking to the device
53 // management service. Returns true if the data is available and writes the
54 // values to the provided pointers.
55 virtual bool GetCredentials(std::string* username,
56 std::string* auth_token) = 0;
57
58 // Notifies the identity strategy that a new token has been fetched. It is up
59 // to the identity strategy to store the token, decide whether it is going
60 // to be used, send out an appropriate OnDeviceTokenChanged() notification
61 // and return the new token in GetDeviceToken() calls.
62 virtual void OnDeviceTokenAvailable(const std::string& token) = 0;
63
64 protected:
65 // Notify observers that the effective token has changed.
66 void NotifyDeviceTokenChanged() {
67 FOR_EACH_OBSERVER(Observer, observer_list_, OnDeviceTokenChanged());
68 }
69
70 // Notify observers about authentication data change.
71 void NotifyAuthChanged() {
72 FOR_EACH_OBSERVER(Observer, observer_list_, OnCredentialsChanged());
73 }
74
75 private:
76 ObserverList<Observer, true> observer_list_;
77
78 DISALLOW_COPY_AND_ASSIGN(CloudPolicyIdentityStrategy);
79 };
80
81 } // namespace policy
82
83 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_IDENTITY_STRATEGY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698