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

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

Issue 7298012: Consolidate data storage and notifications in the cloud policy subsystem (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 9 years, 5 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_DATA_STORE_H_
6 #define CHROME_BROWSER_POLICY_CLOUD_POLICY_DATA_STORE_H_
7 #pragma once
8
9 #include <string>
10
11 #include "base/memory/weak_ptr.h"
12 #include "base/observer_list.h"
13 #include "chrome/browser/policy/proto/device_management_backend.pb.h"
14
15 namespace policy {
16
17 namespace em = enterprise_management;
18
19 // Stores in memory all the data that is used in the cloud policy subsystem,
20 // and manages notification about changes to these fields.
21 // TODO(gfeher): The policy data stored in CloudPolicyCacheBase is currently
22 // an exception, move that here.
23 class CloudPolicyDataStore {
24 public:
25 class Observer {
26 public:
27 virtual ~Observer() {}
28
29 // Notifies observers that the effective token for fetching policy
30 // (device_token_, token_cache_loaded_) has changed.
31 virtual void OnDeviceTokenChanged() = 0;
32
33 // Authentication credentials for talking to the device management service
34 // (gaia_token_) changed.
35 virtual void OnCredentialsChanged() = 0;
36
37 // Called from the destructor of CloudPolicyData.
38 virtual void OnDataStoreGoingAway() = 0;
39 };
40
41 // Create CloudPolicyData with constants initialized for fetching user
42 // policies.
43 static CloudPolicyDataStore* CreateForUserPolicies();
44
45 // Create CloudPolicyData with constants initialized for fetching device
46 // policies.
47 static CloudPolicyDataStore* CreateForDevicePolicies();
48
49 virtual ~CloudPolicyDataStore();
50
51 base::WeakPtr<CloudPolicyDataStore> GetWeakPtr();
52
53 // Sets the device token, and token_policy_cache_loaded and sends out
54 // notifications. Also ensures that setting the token should first happen
55 // from the cache.
56 void SetDeviceToken(const std::string& device_token,
57 bool from_cache);
58
59 // Sets the gaia token and sends out notifications.
60 void SetGaiaToken(const std::string& gaia_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_user_name(const std::string& user_name);
74
75 std::string device_id() const;
76 std::string device_token() const;
77 std::string gaia_token() const;
78 std::string machine_id() const;
79 std::string machine_model() const;
80 em::DeviceRegisterRequest_Type policy_register_type() const;
81 std::string policy_type() const;
82 bool token_cache_loaded() const;
83 std::string user_name() const;
84
85 void AddObserver(Observer* observer);
86 void RemoveObserver(Observer* observer);
87
88 void NotifyCredentialsChanged();
89 void NotifyDeviceTokenChanged();
90
91 private:
92 CloudPolicyDataStore(
93 const em::DeviceRegisterRequest_Type policy_register_type,
94 const std::string& policy_type,
95 const std::string& machine_model,
96 const std::string& machine_id);
97
98 // Data necessary for constructing register requests.
99 std::string gaia_token_;
100 std::string user_name_;
101
102 // Data necessary for constructing policy requests.
103 std::string device_token_;
104
105 // Constants that won't change over the life-time of a cloud policy
106 // subsystem.
107 const em::DeviceRegisterRequest_Type policy_register_type_;
108 const std::string policy_type_;
109 const std::string machine_model_;
110 const std::string machine_id_;
111
112 // Data used for constructiong both register and policy requests.
113 std::string device_id_;
114
115 bool token_cache_loaded_;
116
117 ObserverList<Observer, true> observer_list_;
118
119 base::WeakPtrFactory<CloudPolicyDataStore> weak_ptr_factory_;
120
121 DISALLOW_COPY_AND_ASSIGN(CloudPolicyDataStore);
122 };
123
124 } // namespace policy
125
126 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_DATA_STORE_H_
OLDNEW
« no previous file with comments | « chrome/browser/policy/cloud_policy_controller_unittest.cc ('k') | chrome/browser/policy/cloud_policy_data_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698