OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_POLICY_CLOUD_POLICY_DATA_STORE_H_ | |
6 #define CHROME_BROWSER_POLICY_CLOUD_POLICY_DATA_STORE_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "base/observer_list.h" | |
12 #include "chrome/browser/policy/cloud_policy_constants.h" | |
13 #include "chrome/browser/policy/proto/device_management_backend.pb.h" | |
14 | |
15 #if defined(OS_CHROMEOS) | |
16 #include "chrome/browser/policy/device_status_collector.h" | |
17 #endif | |
18 | |
19 namespace policy { | |
20 | |
21 // Stores in memory all the data that is used in the cloud policy subsystem, | |
22 // and manages notification about changes to these fields. | |
23 // TODO(gfeher): The policy data stored in CloudPolicyCacheBase is currently | |
24 // an exception, move that here. | |
25 class CloudPolicyDataStore { | |
26 public: | |
27 class Observer { | |
28 public: | |
29 virtual ~Observer() {} | |
30 | |
31 // Notifies observers that the effective token for fetching policy | |
32 // (device_token_, token_cache_loaded_) has changed. | |
33 virtual void OnDeviceTokenChanged() = 0; | |
34 | |
35 // Authentication credentials for talking to the device management service | |
36 // (gaia_token_) changed. | |
37 virtual void OnCredentialsChanged() = 0; | |
38 }; | |
39 | |
40 ~CloudPolicyDataStore(); | |
41 | |
42 // Create CloudPolicyData with constants initialized for fetching user | |
43 // policies. | |
44 static CloudPolicyDataStore* CreateForUserPolicies(); | |
45 | |
46 // Create CloudPolicyData with constants initialized for fetching device | |
47 // policies. | |
48 static CloudPolicyDataStore* CreateForDevicePolicies(); | |
49 | |
50 // Sets the device token, and token_policy_cache_loaded and sends out | |
51 // notifications. Also ensures that setting the token should first happen | |
52 // from the cache. | |
53 void SetDeviceToken(const std::string& device_token, | |
54 bool from_cache); | |
55 | |
56 // Sets the gaia token and sends out notifications. | |
57 void SetGaiaToken(const std::string& gaia_token); | |
58 | |
59 // Sets an OAuth token to be used for registration. | |
60 void SetOAuthToken(const std::string& oauth_token); | |
61 | |
62 // Clears device and user credentials. | |
63 void Reset(); | |
64 | |
65 // Only used in tests. | |
66 void SetupForTesting(const std::string& device_token, | |
67 const std::string& device_id, | |
68 const std::string& user_name, | |
69 const std::string& gaia_token, | |
70 bool token_cache_loaded); | |
71 | |
72 void set_device_id(const std::string& device_id); | |
73 void set_machine_id(const std::string& machine_id); | |
74 void set_machine_model(const std::string& machine_model); | |
75 void set_user_name(const std::string& user_name); | |
76 void set_user_affiliation(UserAffiliation user_affiliation); | |
77 void set_known_machine_id(bool known_machine_id); | |
78 void set_policy_fetching_enabled(bool policy_fetching_enabled); | |
79 void set_device_mode(DeviceMode device_mode); | |
80 void set_reregister(bool reregister); | |
81 | |
82 #if defined(OS_CHROMEOS) | |
83 void set_device_status_collector(DeviceStatusCollector* collector); | |
84 DeviceStatusCollector* device_status_collector(); | |
85 #endif | |
86 | |
87 const std::string& device_id() const; | |
88 const std::string& device_token() const; | |
89 const std::string& gaia_token() const; | |
90 const std::string& oauth_token() const; | |
91 bool has_auth_token() const; | |
92 const std::string& machine_id() const; | |
93 const std::string& machine_model() const; | |
94 enterprise_management::DeviceRegisterRequest_Type | |
95 policy_register_type() const; | |
96 const std::string& policy_type() const; | |
97 bool token_cache_loaded() const; | |
98 bool policy_fetching_enabled() const; | |
99 const std::string& user_name() const; | |
100 UserAffiliation user_affiliation() const; | |
101 bool known_machine_id() const; | |
102 DeviceMode device_mode() const; | |
103 bool reregister() const; | |
104 | |
105 void AddObserver(Observer* observer); | |
106 void RemoveObserver(Observer* observer); | |
107 | |
108 void NotifyCredentialsChanged(); | |
109 void NotifyDeviceTokenChanged(); | |
110 | |
111 private: | |
112 CloudPolicyDataStore( | |
113 const enterprise_management::DeviceRegisterRequest_Type register_type, | |
114 const std::string& policy_type); | |
115 | |
116 // Data necessary for constructing register requests. | |
117 std::string gaia_token_; | |
118 std::string oauth_token_; | |
119 std::string user_name_; | |
120 | |
121 // Data necessary for constructing policy requests. | |
122 std::string device_token_; | |
123 UserAffiliation user_affiliation_; | |
124 | |
125 // Constants that won't change over the life-time of a cloud policy | |
126 // subsystem. | |
127 const enterprise_management::DeviceRegisterRequest_Type policy_register_type_; | |
128 const std::string policy_type_; | |
129 | |
130 // Data used for constructiong both register and policy requests. | |
131 std::string device_id_; | |
132 std::string machine_model_; | |
133 std::string machine_id_; | |
134 bool known_machine_id_; | |
135 bool reregister_; | |
136 | |
137 bool token_cache_loaded_; | |
138 bool policy_fetching_enabled_; | |
139 | |
140 DeviceMode device_mode_; | |
141 | |
142 #if defined(OS_CHROMEOS) | |
143 scoped_ptr<DeviceStatusCollector> device_status_collector_; | |
144 #endif | |
145 | |
146 ObserverList<Observer, true> observer_list_; | |
147 | |
148 DISALLOW_COPY_AND_ASSIGN(CloudPolicyDataStore); | |
149 }; | |
150 | |
151 } // namespace policy | |
152 | |
153 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_DATA_STORE_H_ | |
OLD | NEW |