Chromium Code Reviews| Index: chrome/browser/chromeos/policy/cloud_external_data_policy_observer_chromeos.h |
| diff --git a/chrome/browser/chromeos/policy/cloud_external_data_policy_observer_chromeos.h b/chrome/browser/chromeos/policy/cloud_external_data_policy_observer_chromeos.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c248e0715e1b0b1efac3855601dde34e2c9fa0ea |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/policy/cloud_external_data_policy_observer_chromeos.h |
| @@ -0,0 +1,123 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_CHROMEOS_POLICY_CLOUD_EXTERNAL_DATA_POLICY_OBSERVER_CHROMEOS_H_ |
| +#define CHROME_BROWSER_CHROMEOS_POLICY_CLOUD_EXTERNAL_DATA_POLICY_OBSERVER_CHROMEOS_H_ |
|
Joao da Silva
2013/11/27 14:33:59
The _chromeos part of the filename is a bit redund
bartfab (slow)
2013/11/27 20:10:15
I modeled this after things like device_cloud_poli
|
| + |
| +#include <map> |
| +#include <string> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/compiler_specific.h" |
| +#include "base/memory/linked_ptr.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" |
| +#include "chrome/browser/chromeos/settings/cros_settings.h" |
| +#include "components/policy/core/common/policy_map.h" |
| +#include "content/public/browser/notification_observer.h" |
| +#include "content/public/browser/notification_registrar.h" |
| + |
| +namespace chromeos { |
| +class UserManager; |
| +} |
| + |
| +namespace policy { |
| + |
| +// Helper for implementing policies referencing external data: This class |
| +// observes a given |policy_| and fetches the external data that it references |
| +// for all users on the device. Notifications are emitted when an external data |
| +// reference is set, cleared or an external data fetch completes successfully. |
| +// |
| +// State is kept at runtime only: External data references that already exist |
| +// when the class is instantiated are considered new, causing a notification to |
| +// be emitted that an external data reference has been set and the referenced |
| +// external data to be fetched. |
| +class CloudExternalDataPolicyObserverChromeOS |
| + : public content::NotificationObserver, |
| + public DeviceLocalAccountPolicyService::Observer { |
| + public: |
| + CloudExternalDataPolicyObserverChromeOS( |
| + chromeos::CrosSettings* cros_settings, |
| + chromeos::UserManager* user_manager, |
| + DeviceLocalAccountPolicyService* device_local_account_policy_service, |
| + const std::string& policy); |
| + virtual ~CloudExternalDataPolicyObserverChromeOS(); |
| + |
| + void Init(); |
| + |
| + virtual void Shutdown(); |
|
Joao da Silva
2013/11/27 14:33:59
Who is going to own this? When is this going to be
bartfab (slow)
2013/11/27 20:10:15
No longer relevant - there is a Delegate interface
|
| + |
| + // Invoked when an external data reference is set for |user_id|. |
| + virtual void OnExternalDataSet(const std::string& user_id) = 0; |
| + |
| + // Invoked when the external data reference is cleared for |user_id|. |
| + virtual void OnExternalDataCleared(const std::string& user_id) = 0; |
| + |
| + // Invoked when the external data referenced for |user_id| has been fetched. |
| + // Failed fetches are retried and the method is called only when a fetch |
| + // eventually succeeds. If a fetch fails permanently (e.g. because the |
| + // external data reference specifies an invalid URL), the method is not called |
| + // at all. |
| + virtual void OnExternalDataFetched(const std::string& user_id, |
| + scoped_ptr<std::string> data) = 0; |
|
Joao da Silva
2013/11/27 14:33:59
WDYT of putting these in a Delegate interface inst
bartfab (slow)
2013/11/27 20:10:15
Done.
|
| + |
| + // content::NotificationObserver: |
| + virtual void Observe(int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) OVERRIDE; |
| + |
| + // DeviceLocalAccountPolicyService: |
| + virtual void OnPolicyUpdated(const std::string& user_id) OVERRIDE; |
| + virtual void OnDeviceLocalAccountsChanged() OVERRIDE; |
| + |
| + private: |
| + // Helper class that observes |policy_| for a logged-in user. |
| + class PolicyServiceObserver; |
| + |
| + void RetrieveDeviceLocalAccounts(); |
| + |
| + // Handles the new policy map |entry| for |user_id| by canceling any external |
| + // data fetch currently in progress, emitting a notification that an external |
| + // data reference has been cleared (if |entry| is NULL) or set (otherwise), |
| + // starting a new external data fetch in the latter case. |
| + void HandleExternalDataPolicyUpdate(const std::string& user_id, |
| + const PolicyMap::Entry* entry); |
| + |
| + // A map from each device-local account user ID to its current policy map |
| + // entry for |policy_|. |
| + typedef std::map<std::string, PolicyMap::Entry> DeviceLocalAccountEntryMap; |
| + DeviceLocalAccountEntryMap device_local_account_entries_; |
| + |
| + // A map from each logged-in user to the helper that observes |policy_| in the |
| + // user's PolicyService. |
| + typedef std::map<std::string, linked_ptr<PolicyServiceObserver> > |
|
Joao da Silva
2013/11/27 14:33:59
I've been asked to use maps of linked_ptrs before;
bartfab (slow)
2013/11/27 20:10:15
I prefer linked_ptrs: The overhead is negligible h
|
| + LoggedInUserObserverMap; |
| + LoggedInUserObserverMap logged_in_user_observers_; |
| + |
| + chromeos::CrosSettings* cros_settings_; |
| + chromeos::UserManager* user_manager_; |
| + DeviceLocalAccountPolicyService* device_local_account_policy_service_; |
| + |
| + // The policy that |this| observes. |
| + std::string policy_; |
| + |
| + content::NotificationRegistrar notification_registrar_; |
| + scoped_ptr<chromeos::CrosSettings::ObserverSubscription> |
| + device_local_accounts_subscription_; |
| + |
| + // A map from user ID to a base::WeakPtr for each external data fetch |
| + // currently in progress. This allows fetches to be effectively be canceled by |
| + // invalidating the pointers. |
| + typedef base::WeakPtrFactory<CloudExternalDataPolicyObserverChromeOS> |
| + WeakPtrFactory; |
| + typedef std::map<std::string, linked_ptr<WeakPtrFactory> > FetchWeakPtrMap; |
| + FetchWeakPtrMap fetch_weak_ptrs_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(CloudExternalDataPolicyObserverChromeOS); |
| +}; |
| + |
| +} // namespace policy |
| + |
| +#endif // CHROME_BROWSER_CHROMEOS_POLICY_CLOUD_EXTERNAL_DATA_POLICY_OBSERVER_CHROMEOS_H_ |