Chromium Code Reviews| Index: chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h |
| diff --git a/chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h b/chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h |
| index 8f47b4d968582b8e0ed8a6a907ea2cc25d325ddf..014863999d1f14a285d234f332a323b19718e115 100644 |
| --- a/chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h |
| +++ b/chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h |
| @@ -5,12 +5,14 @@ |
| #ifndef CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_CHROMEOS_H_ |
| #define CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_CHROMEOS_H_ |
| -#include <deque> |
| +#include <queue> |
| +#include <utility> |
| #include <vector> |
| #include "base/callback_forward.h" |
| -#include "base/compiler_specific.h" |
| #include "base/macros.h" |
| +#include "base/memory/linked_ptr.h" |
| +#include "base/observer_list.h" |
| #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| #include "chromeos/dbus/session_manager_client.h" |
| #include "components/keyed_service/core/keyed_service.h" |
| @@ -27,8 +29,6 @@ class OwnerKeyUtil; |
| namespace chromeos { |
| -class SessionManagerOperation; |
| - |
| // The class is a profile-keyed service which holds public/private |
| // keypair corresponds to a profile. The keypair is reloaded automatically when |
| // profile is created and TPM token is ready. Note that the private part of a |
| @@ -38,16 +38,23 @@ class SessionManagerOperation; |
| // (crbug.com/230018). |
| class OwnerSettingsServiceChromeOS : public ownership::OwnerSettingsService, |
| public content::NotificationObserver, |
| - public SessionManagerClient::Observer { |
| + public SessionManagerClient::Observer, |
| + public DeviceSettingsService::Observer { |
| public: |
| + class Observer { |
| + public: |
| + virtual ~Observer() {} |
| + virtual void OnSetCompleted(bool success) = 0; |
| + }; |
| + |
| virtual ~OwnerSettingsServiceChromeOS(); |
| void OnTPMTokenReady(bool tpm_token_enabled); |
| // ownership::OwnerSettingsService implementation: |
| - virtual void SignAndStorePolicyAsync( |
| - scoped_ptr<enterprise_management::PolicyData> policy, |
| - const base::Closure& callback) override; |
| + virtual bool HandlesSetting(const std::string& setting) override; |
| + virtual void Set(const std::string& setting, |
| + const base::Value& value) override; |
| // NotificationObserver implementation: |
| virtual void Observe(int type, |
| @@ -57,6 +64,10 @@ class OwnerSettingsServiceChromeOS : public ownership::OwnerSettingsService, |
| // SessionManagerClient::Observer: |
| virtual void OwnerKeySet(bool success) override; |
| + // DeviceSettingsService::Observer: |
| + virtual void OwnershipStatusChanged() override; |
| + virtual void DeviceSettingsUpdated() override; |
| + |
| // Checks if the user is the device owner, without the user profile having to |
| // been initialized. Should be used only if login state is in safe mode. |
| static void IsOwnerForSafeModeAsync( |
| @@ -64,13 +75,18 @@ class OwnerSettingsServiceChromeOS : public ownership::OwnerSettingsService, |
| const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util, |
| const IsOwnerCallback& callback); |
| - static void SetDeviceSettingsServiceForTesting( |
| - DeviceSettingsService* device_settings_service); |
| + void AddObserver(Observer* observer); |
| + |
| + void RemoveObserver(Observer* observer); |
| private: |
| + // Scoped lock for DeviceSettingsService processing loop. |
| + class ProcessingLoopAutoBlocker; |
| + |
| friend class OwnerSettingsServiceChromeOSFactory; |
| OwnerSettingsServiceChromeOS( |
| + DeviceSettingsService* device_settings_service, |
| Profile* profile, |
| const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util); |
| @@ -85,13 +101,34 @@ class OwnerSettingsServiceChromeOS : public ownership::OwnerSettingsService, |
| // Possibly notifies DeviceSettingsService that owner's keypair is loaded. |
| virtual void OnPostKeypairLoadedActions() override; |
| - // Performs next operation in the queue. |
| - void StartNextOperation(); |
| + // Posts task on the current thread to process next set |
| + // request. |
| + void ProcessNextSetRequestAsync(); |
| + |
| + // Tries to process next set request when DeviceSettingsService is not busy |
| + // with session manager operations. If it's the case, temprorary stops |
|
Mattias Nissler (ping if slow)
2014/10/20 12:41:30
*temporarily
ygorshenin1
2014/10/22 09:20:11
Acknowledged.
|
| + // DeviceSettingsService's processing loop to prevent changes in device |
| + // settings, modifies current device settings and sends them for signing. |
| + // When device settings are correctly signed, OnPolicyAssembledAndSigned() is |
| + // called, otherwise, HandleError() is called. |
| + void ProcessNextSetRequest(); |
| + |
| + // Called when current device settings are successfully signed. |
| + // Runs DeviceSettingsService's processing loop and sends signed |
| + // settings for storage. |
| + void OnPolicyAssembledAndSigned( |
| + scoped_ptr<ProcessingLoopAutoBlocker> blocker, |
| + scoped_ptr<enterprise_management::PolicyFetchResponse> policy_response); |
| - // Called when sign-and-store operation completes it's work. |
| - void HandleCompletedOperation(const base::Closure& callback, |
| - SessionManagerOperation* operation, |
| - DeviceSettingsService::Status status); |
| + // Called by DeviceSettingsService when modified and signed device settings |
| + // are stored. Notifies observers and tries to process next set request. |
| + void OnSignedPolicyStored(); |
| + |
| + // Called when modified device settings wasn't successfully signed. Notifies |
| + // observers and tries to process next set request. |
| + void HandleError(); |
| + |
| + DeviceSettingsService* device_settings_service_; |
| // Profile this service instance belongs to. |
| Profile* profile_; |
| @@ -105,14 +142,29 @@ class OwnerSettingsServiceChromeOS : public ownership::OwnerSettingsService, |
| // Whether TPM token still needs to be initialized. |
| bool waiting_for_tpm_token_; |
| - // The queue of pending sign-and-store operations. The first operation on the |
| - // queue is currently active; it gets removed and destroyed once it completes. |
| - std::deque<SessionManagerOperation*> pending_operations_; |
| + // A structure used to represent set request for a particular device |
| + // setting. |
| + struct SetRequest { |
| + SetRequest(const std::string& setting, linked_ptr<base::Value> value); |
| + ~SetRequest(); |
| + |
| + const std::string setting; |
| + const linked_ptr<base::Value> value; |
| + }; |
| + |
| + // A queue of serialized set requests, which should be processed in FIFO |
| + // order. |
| + std::queue<SetRequest> set_requests_; |
| + |
| + ObserverList<Observer> observers_; |
| content::NotificationRegistrar registrar_; |
| base::WeakPtrFactory<OwnerSettingsServiceChromeOS> weak_factory_; |
| + base::WeakPtrFactory<OwnerSettingsServiceChromeOS> |
| + set_requests_callback_factory_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(OwnerSettingsServiceChromeOS); |
| }; |