| Index: chrome/browser/policy/device_token_fetcher.h
|
| diff --git a/chrome/browser/policy/device_token_fetcher.h b/chrome/browser/policy/device_token_fetcher.h
|
| index 7704d35cdc0c4391fbba84be422896a6ed321de8..91ef3b2c5c10484aad667d655a206738bb8fd7d1 100644
|
| --- a/chrome/browser/policy/device_token_fetcher.h
|
| +++ b/chrome/browser/policy/device_token_fetcher.h
|
| @@ -9,6 +9,7 @@
|
| #include <string>
|
|
|
| #include "base/file_path.h"
|
| +#include "base/observer_list.h"
|
| #include "base/ref_counted.h"
|
| #include "base/waitable_event.h"
|
| #include "chrome/browser/policy/device_management_backend.h"
|
| @@ -31,6 +32,13 @@ class DeviceTokenFetcher
|
| public DeviceManagementBackend::DeviceRegisterResponseDelegate,
|
| public base::RefCountedThreadSafe<DeviceTokenFetcher> {
|
| public:
|
| + class Observer {
|
| + public:
|
| + virtual void OnTokenSuccess() = 0;
|
| + virtual void OnTokenError() = 0;
|
| + virtual ~Observer() {}
|
| + };
|
| +
|
| // Requests to the device management server are sent through |backend|. It
|
| // obtains the authentication token from |token_service|. The fetcher stores
|
| // the device token to |token_path| once it's retrieved from the server.
|
| @@ -49,6 +57,9 @@ class DeviceTokenFetcher
|
| const em::DeviceRegisterResponse& response);
|
| virtual void OnError(DeviceManagementBackend::ErrorCode code);
|
|
|
| + // Re-initializes this DeviceTokenFetcher
|
| + void Restart();
|
| +
|
| // Called by subscribers of the device management token to indicate that they
|
| // will need the token in the future. Must be called on the UI thread.
|
| void StartFetching();
|
| @@ -76,6 +87,14 @@ class DeviceTokenFetcher
|
| // True if the device token has been fetched and is valid.
|
| bool IsTokenValid() const;
|
|
|
| + void AddObserver(Observer* obs) {
|
| + observer_list_.AddObserver(obs);
|
| + }
|
| +
|
| + void RemoveObserver(Observer* obs) {
|
| + observer_list_.RemoveObserver(obs);
|
| + }
|
| +
|
| private:
|
| friend class DeviceTokenFetcherTest;
|
|
|
| @@ -114,6 +133,14 @@ class DeviceTokenFetcher
|
| // available.
|
| void SendServerRequestIfPossible();
|
|
|
| + void NotifyTokenSuccess() {
|
| + FOR_EACH_OBSERVER(Observer, observer_list_, OnTokenSuccess());
|
| + }
|
| +
|
| + void NotifyTokenError() {
|
| + FOR_EACH_OBSERVER(Observer, observer_list_, OnTokenError());
|
| + }
|
| +
|
| // Saves the device management token to disk once it has been retrieved from
|
| // the server. Must be called on the FILE thread.
|
| static void WriteDeviceTokenToDisk(const FilePath& path,
|
| @@ -124,6 +151,7 @@ class DeviceTokenFetcher
|
| // management server and generate the device token.
|
| static std::string GenerateNewDeviceID();
|
|
|
| + ObserverList<Observer> observer_list_;
|
| FilePath token_path_;
|
| DeviceManagementBackend* backend_; // weak
|
| TokenService* token_service_;
|
|
|