| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_CLOUD_EXTERNAL_DATA_POLICY_OBSERVER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_CLOUD_EXTERNAL_DATA_POLICY_OBSERVER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_POLICY_CLOUD_EXTERNAL_DATA_POLICY_OBSERVER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_POLICY_CLOUD_EXTERNAL_DATA_POLICY_OBSERVER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 // be emitted that an external data reference has been set and the referenced | 31 // be emitted that an external data reference has been set and the referenced |
| 32 // external data to be fetched. | 32 // external data to be fetched. |
| 33 class CloudExternalDataPolicyObserver | 33 class CloudExternalDataPolicyObserver |
| 34 : public content::NotificationObserver, | 34 : public content::NotificationObserver, |
| 35 public DeviceLocalAccountPolicyService::Observer { | 35 public DeviceLocalAccountPolicyService::Observer { |
| 36 public: | 36 public: |
| 37 class Delegate { | 37 class Delegate { |
| 38 public: | 38 public: |
| 39 // Invoked when an external data reference is set for |user_id|. | 39 // Invoked when an external data reference is set for |user_id|. |
| 40 virtual void OnExternalDataSet(const std::string& policy, | 40 virtual void OnExternalDataSet(const std::string& policy, |
| 41 const std::string& user_id); | 41 const user_manager::UserID& user_id); |
| 42 | 42 |
| 43 // Invoked when the external data reference is cleared for |user_id|. | 43 // Invoked when the external data reference is cleared for |user_id|. |
| 44 virtual void OnExternalDataCleared(const std::string& policy, | 44 virtual void OnExternalDataCleared(const std::string& policy, |
| 45 const std::string& user_id); | 45 const user_manager::UserID& user_id); |
| 46 | 46 |
| 47 // Invoked when the external data referenced for |user_id| has been fetched. | 47 // Invoked when the external data referenced for |user_id| has been fetched. |
| 48 // Failed fetches are retried and the method is called only when a fetch | 48 // Failed fetches are retried and the method is called only when a fetch |
| 49 // eventually succeeds. If a fetch fails permanently (e.g. because the | 49 // eventually succeeds. If a fetch fails permanently (e.g. because the |
| 50 // external data reference specifies an invalid URL), the method is not | 50 // external data reference specifies an invalid URL), the method is not |
| 51 // called at all. | 51 // called at all. |
| 52 virtual void OnExternalDataFetched(const std::string& policy, | 52 virtual void OnExternalDataFetched(const std::string& policy, |
| 53 const std::string& user_id, | 53 const user_manager::UserID& user_id, |
| 54 scoped_ptr<std::string> data); | 54 scoped_ptr<std::string> data); |
| 55 | 55 |
| 56 protected: | 56 protected: |
| 57 virtual ~Delegate(); | 57 virtual ~Delegate(); |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 CloudExternalDataPolicyObserver( | 60 CloudExternalDataPolicyObserver( |
| 61 chromeos::CrosSettings* cros_settings, | 61 chromeos::CrosSettings* cros_settings, |
| 62 DeviceLocalAccountPolicyService* device_local_account_policy_service, | 62 DeviceLocalAccountPolicyService* device_local_account_policy_service, |
| 63 const std::string& policy, | 63 const std::string& policy, |
| 64 Delegate* delegate); | 64 Delegate* delegate); |
| 65 ~CloudExternalDataPolicyObserver() override; | 65 ~CloudExternalDataPolicyObserver() override; |
| 66 | 66 |
| 67 void Init(); | 67 void Init(); |
| 68 | 68 |
| 69 // content::NotificationObserver: | 69 // content::NotificationObserver: |
| 70 void Observe(int type, | 70 void Observe(int type, |
| 71 const content::NotificationSource& source, | 71 const content::NotificationSource& source, |
| 72 const content::NotificationDetails& details) override; | 72 const content::NotificationDetails& details) override; |
| 73 | 73 |
| 74 // DeviceLocalAccountPolicyService::Observer: | 74 // DeviceLocalAccountPolicyService::Observer: |
| 75 void OnPolicyUpdated(const std::string& user_id) override; | 75 void OnPolicyUpdated(const user_manager::UserID& user_id) override; |
| 76 void OnDeviceLocalAccountsChanged() override; | 76 void OnDeviceLocalAccountsChanged() override; |
| 77 | 77 |
| 78 private: | 78 private: |
| 79 // Helper class that observes |policy_| for a logged-in user. | 79 // Helper class that observes |policy_| for a logged-in user. |
| 80 class PolicyServiceObserver; | 80 class PolicyServiceObserver; |
| 81 | 81 |
| 82 void RetrieveDeviceLocalAccounts(); | 82 void RetrieveDeviceLocalAccounts(); |
| 83 | 83 |
| 84 // Handles the new policy map |entry| for |user_id| by canceling any external | 84 // Handles the new policy map |entry| for |user_id| by canceling any external |
| 85 // data fetch currently in progress, emitting a notification that an external | 85 // data fetch currently in progress, emitting a notification that an external |
| 86 // data reference has been cleared (if |entry| is NULL) or set (otherwise), | 86 // data reference has been cleared (if |entry| is NULL) or set (otherwise), |
| 87 // starting a new external data fetch in the latter case. | 87 // starting a new external data fetch in the latter case. |
| 88 void HandleExternalDataPolicyUpdate(const std::string& user_id, | 88 void HandleExternalDataPolicyUpdate(const user_manager::UserID& user_id, |
| 89 const PolicyMap::Entry* entry); | 89 const PolicyMap::Entry* entry); |
| 90 | 90 |
| 91 void OnExternalDataFetched(const std::string& user_id, | 91 void OnExternalDataFetched(const user_manager::UserID& user_id, |
| 92 scoped_ptr<std::string> data); | 92 scoped_ptr<std::string> data); |
| 93 | 93 |
| 94 // A map from each device-local account user ID to its current policy map | 94 // A map from each device-local account user ID to its current policy map |
| 95 // entry for |policy_|. | 95 // entry for |policy_|. |
| 96 typedef std::map<std::string, PolicyMap::Entry> DeviceLocalAccountEntryMap; | 96 typedef std::map<user_manager::UserID, PolicyMap::Entry> DeviceLocalAccountEnt
ryMap; |
| 97 DeviceLocalAccountEntryMap device_local_account_entries_; | 97 DeviceLocalAccountEntryMap device_local_account_entries_; |
| 98 | 98 |
| 99 // A map from each logged-in user to the helper that observes |policy_| in the | 99 // A map from each logged-in user to the helper that observes |policy_| in the |
| 100 // user's PolicyService. | 100 // user's PolicyService. |
| 101 typedef std::map<std::string, linked_ptr<PolicyServiceObserver> > | 101 typedef std::map<user_manager::UserID, linked_ptr<PolicyServiceObserver> > |
| 102 LoggedInUserObserverMap; | 102 LoggedInUserObserverMap; |
| 103 LoggedInUserObserverMap logged_in_user_observers_; | 103 LoggedInUserObserverMap logged_in_user_observers_; |
| 104 | 104 |
| 105 chromeos::CrosSettings* cros_settings_; | 105 chromeos::CrosSettings* cros_settings_; |
| 106 DeviceLocalAccountPolicyService* device_local_account_policy_service_; | 106 DeviceLocalAccountPolicyService* device_local_account_policy_service_; |
| 107 | 107 |
| 108 // The policy that |this| observes. | 108 // The policy that |this| observes. |
| 109 std::string policy_; | 109 std::string policy_; |
| 110 | 110 |
| 111 Delegate* delegate_; | 111 Delegate* delegate_; |
| 112 | 112 |
| 113 content::NotificationRegistrar notification_registrar_; | 113 content::NotificationRegistrar notification_registrar_; |
| 114 scoped_ptr<chromeos::CrosSettings::ObserverSubscription> | 114 scoped_ptr<chromeos::CrosSettings::ObserverSubscription> |
| 115 device_local_accounts_subscription_; | 115 device_local_accounts_subscription_; |
| 116 | 116 |
| 117 // A map from user ID to a base::WeakPtr for each external data fetch | 117 // A map from user ID to a base::WeakPtr for each external data fetch |
| 118 // currently in progress. This allows fetches to be effectively be canceled by | 118 // currently in progress. This allows fetches to be effectively be canceled by |
| 119 // invalidating the pointers. | 119 // invalidating the pointers. |
| 120 typedef base::WeakPtrFactory<CloudExternalDataPolicyObserver> | 120 typedef base::WeakPtrFactory<CloudExternalDataPolicyObserver> |
| 121 WeakPtrFactory; | 121 WeakPtrFactory; |
| 122 typedef std::map<std::string, linked_ptr<WeakPtrFactory> > FetchWeakPtrMap; | 122 typedef std::map<user_manager::UserID, linked_ptr<WeakPtrFactory> > FetchWeakP
trMap; |
| 123 FetchWeakPtrMap fetch_weak_ptrs_; | 123 FetchWeakPtrMap fetch_weak_ptrs_; |
| 124 | 124 |
| 125 base::WeakPtrFactory<CloudExternalDataPolicyObserver> weak_factory_; | 125 base::WeakPtrFactory<CloudExternalDataPolicyObserver> weak_factory_; |
| 126 | 126 |
| 127 DISALLOW_COPY_AND_ASSIGN(CloudExternalDataPolicyObserver); | 127 DISALLOW_COPY_AND_ASSIGN(CloudExternalDataPolicyObserver); |
| 128 }; | 128 }; |
| 129 | 129 |
| 130 } // namespace policy | 130 } // namespace policy |
| 131 | 131 |
| 132 #endif // CHROME_BROWSER_CHROMEOS_POLICY_CLOUD_EXTERNAL_DATA_POLICY_OBSERVER_H_ | 132 #endif // CHROME_BROWSER_CHROMEOS_POLICY_CLOUD_EXTERNAL_DATA_POLICY_OBSERVER_H_ |
| OLD | NEW |