Chromium Code Reviews| 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_DATA_H_ | |
| 6 #define CHROME_BROWSER_POLICY_CLOUD_POLICY_DATA_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/memory/scoped_ptr.h" | |
|
Joao da Silva
2011/07/06 16:45:14
Nit: scoped_ptr.h not used
gfeher
2011/07/07 13:51:00
Done.
| |
| 12 #include "base/observer_list.h" | |
| 13 #include "chrome/browser/policy/device_management_backend.h" | |
|
pastarmovj
2011/07/06 12:11:57
What do you use from the last include?
gfeher
2011/07/06 15:14:20
I am using, em::DeviceRegisterRequest_Type, but th
| |
| 14 | |
| 15 namespace policy { | |
| 16 | |
| 17 // Stores in memory all the data that is used in the cloud policy subsystem, | |
| 18 // and manages notification about changes to these fields. | |
| 19 // TODO(gfeher): The policy data stored in CloudPolicyCacheBase is currently | |
| 20 // an exception, move that here. | |
| 21 class CloudPolicyData { | |
| 22 public: | |
| 23 class Observer { | |
| 24 public: | |
| 25 virtual ~Observer() {} | |
| 26 | |
| 27 // Notifies observers that the effective token for fetching policy | |
| 28 // (device_token_, token_cache_loaded_) has changed. | |
| 29 virtual void OnDeviceTokenChanged() = 0; | |
| 30 | |
| 31 // Authentication credentials for talking to the device management service | |
| 32 // (gaia_token_) changed. | |
| 33 virtual void OnCredentialsChanged() = 0; | |
| 34 | |
| 35 // Called from the destructor of CloudPolicyData. | |
| 36 virtual void OnPolicyDataGoingAway() = 0; | |
| 37 }; | |
| 38 | |
| 39 // Create CloudPolicyData with constants initialized for fetching user | |
| 40 // policies. | |
| 41 static CloudPolicyData* CreateForUserPolicies(); | |
| 42 | |
| 43 // Create CloudPolicyData with constants initialized for fetching device | |
| 44 // policies. | |
| 45 static CloudPolicyData* CreateForDevicePolicies(); | |
| 46 | |
| 47 virtual ~CloudPolicyData(); | |
| 48 | |
| 49 // Sets the device token, and token_policy_cache_loaded and sends out | |
| 50 // notifications. Also ensures that setting the token should first happen | |
| 51 // from the cache. | |
| 52 void SetDeviceToken(const std::string& device_token, | |
| 53 bool from_cache); | |
| 54 | |
| 55 // Sets the gaia token and sends out notifications. | |
| 56 void SetGaiaToken(const std::string& gaia_token); | |
| 57 | |
| 58 // Clears device and user credentials. | |
| 59 void Reset(); | |
| 60 | |
| 61 // Only used in tests. | |
| 62 void SetupForTesting(const std::string& device_token, | |
| 63 const std::string& device_id, | |
| 64 const std::string& user_name, | |
| 65 const std::string& gaia_token, | |
| 66 bool token_cache_loaded); | |
| 67 | |
| 68 void set_device_id(const std::string& device_id); | |
| 69 void set_user_name(const std::string& user_name); | |
| 70 | |
| 71 std::string device_id() const; | |
| 72 std::string device_token() const; | |
| 73 std::string gaia_token() const; | |
| 74 std::string machine_id() const; | |
| 75 std::string machine_model() const; | |
|
Joao da Silva
2011/07/06 16:45:14
What do you think about returning these as const s
gfeher
2011/07/07 13:51:00
Well, in theory, CloudPolicyData should outlive al
Joao da Silva
2011/07/07 16:54:16
Agree, thanks for making that clear.
| |
| 76 em::DeviceRegisterRequest_Type policy_register_type() const; | |
| 77 std::string policy_type() const; | |
| 78 bool token_cache_loaded() const; | |
| 79 std::string user_name() const; | |
| 80 | |
| 81 void AddObserver(Observer* observer); | |
| 82 void RemoveObserver(Observer* observer); | |
| 83 | |
| 84 void NotifyCredentialsChanged(); | |
| 85 void NotifyDeviceTokenChanged(); | |
| 86 | |
| 87 private: | |
| 88 CloudPolicyData(const em::DeviceRegisterRequest_Type policy_register_type, | |
| 89 const std::string& policy_type, | |
| 90 const std::string& machine_model, | |
| 91 const std::string& machine_id); | |
| 92 | |
| 93 // Data necessary for constructing register requests. | |
| 94 std::string gaia_token_; | |
| 95 std::string user_name_; | |
| 96 | |
| 97 // Data necessary for constructing policy requests. | |
| 98 std::string device_token_; | |
| 99 | |
| 100 // Constants that won't change over the life-time of a cloud policy | |
| 101 // subsystem. | |
| 102 em::DeviceRegisterRequest_Type policy_register_type_; | |
| 103 std::string policy_type_; | |
|
pastarmovj
2011/07/06 12:11:57
If these are initialized only by the constructor t
gfeher
2011/07/06 15:14:20
Done.
| |
| 104 std::string machine_model_; | |
| 105 std::string machine_id_; | |
| 106 | |
| 107 // Data used for constructiong both register and policy requests. | |
| 108 std::string device_id_; | |
| 109 | |
| 110 bool token_cache_loaded_; | |
| 111 | |
| 112 ObserverList<Observer, true> observer_list_; | |
| 113 | |
| 114 DISALLOW_COPY_AND_ASSIGN(CloudPolicyData); | |
| 115 }; | |
| 116 | |
| 117 } // namespace policy | |
| 118 | |
| 119 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_DATA_H_ | |
| OLD | NEW |