| Index: chrome/browser/policy/cloud_policy_client.h
|
| diff --git a/chrome/browser/policy/cloud_policy_client.h b/chrome/browser/policy/cloud_policy_client.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..b0b03f65addb870802e89970ef9e8f24935757c1
|
| --- /dev/null
|
| +++ b/chrome/browser/policy/cloud_policy_client.h
|
| @@ -0,0 +1,143 @@
|
| +// Copyright (c) 2011 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_POLICY_CLOUD_POLICY_CLIENT_H_
|
| +#define CHROME_BROWSER_POLICY_CLOUD_POLICY_CLIENT_H_
|
| +#pragma once
|
| +
|
| +#include <string>
|
| +
|
| +#include "base/file_path.h"
|
| +#include "base/observer_list.h"
|
| +#include "base/scoped_ptr.h"
|
| +#include "base/task.h"
|
| +#include "base/time.h"
|
| +#include "chrome/browser/policy/cloud_policy_controller.h"
|
| +#include "chrome/browser/policy/configuration_policy_provider.h"
|
| +#include "chrome/browser/policy/device_management_backend.h"
|
| +#include "chrome/browser/policy/device_token_fetcher.h"
|
| +
|
| +class Profile;
|
| +class TokenService;
|
| +
|
| +namespace policy {
|
| +
|
| +class CloudPolicyCache;
|
| +class DeviceManagementBackend;
|
| +
|
| +// Provides policy fetched from the device management server. With the exception
|
| +// of the Provide method, which can be called on the FILE thread, all public
|
| +// methods must be called on the UI thread.
|
| +class CloudPolicyClient
|
| + : public DeviceManagementBackend::DevicePolicyResponseDelegate,
|
| + public DeviceTokenFetcher::Observer,
|
| + public CloudPolicyController::Observer {
|
| + public:
|
| + class Observer {
|
| + public:
|
| + virtual ~Observer() {}
|
| + virtual void OnPolicyUpdated() {}
|
| + };
|
| +
|
| + CloudPolicyClient(CloudPolicyCache* cache,
|
| + DeviceManagementBackend* backend,
|
| + DeviceTokenFetcher* token_fetcher,
|
| + CloudPolicyController* controller);
|
| + virtual ~CloudPolicyClient();
|
| +
|
| + // Sets the refresh rate at which to re-fetch policy information.
|
| + void SetRefreshRate(int64 refresh_rate_milliseconds);
|
| +
|
| + // DevicePolicyResponseDelegate implementation:
|
| + virtual void HandlePolicyResponse(
|
| + const em::DevicePolicyResponse& response);
|
| + virtual void OnError(DeviceManagementBackend::ErrorCode code);
|
| +
|
| + // DeviceTokenFetcher::Observer implementation:
|
| + virtual void OnTokenAvailable();
|
| +
|
| + // CloudPolicyController::Observer implementation:
|
| + virtual void OnTokenChanged();
|
| + virtual void OnCredentialsChanged();
|
| +
|
| + private:
|
| + // Indicates the current state the provider is in.
|
| + enum ClientState {
|
| + // The provider is initializing, policy information not yet available.
|
| + STATE_TOKEN_UNAVAILABLE,
|
| + // The token is valid, but policy is yet to be fetched.
|
| + STATE_TOKEN_VALID,
|
| + // Policy information is available and valid.
|
| + STATE_POLICY_VALID,
|
| + // The service returned an error when requesting policy, ask again later.
|
| + STATE_POLICY_ERROR,
|
| + };
|
| +
|
| + friend class CloudPolicyClientTest;
|
| +
|
| + // More configurable constructor for use by test cases.
|
| + CloudPolicyClient(CloudPolicyCache* cache,
|
| + DeviceManagementBackend* backend,
|
| + DeviceTokenFetcher* token_fetcher,
|
| + CloudPolicyController* controller,
|
| + int64 policy_refresh_rate_ms,
|
| + int policy_refresh_deviation_factor_percent,
|
| + int64 policy_refresh_deviation_max_ms,
|
| + int64 policy_refresh_error_delay_ms);
|
| +
|
| + // Called by constructors to perform shared initialization. Initialization
|
| + // requiring the IOThread must not be performed directly in this method,
|
| + // rather must be deferred until the IOThread is fully initialized. This is
|
| + // the case in InitializeAfterIOThreadExists.
|
| + void Initialize(CloudPolicyCache* cache,
|
| + DeviceManagementBackend* backend,
|
| + DeviceTokenFetcher* token_fetcher,
|
| + CloudPolicyController* controller,
|
| + int64 policy_refresh_rate_ms,
|
| + int policy_refresh_deviation_factor_percent,
|
| + int64 policy_refresh_deviation_max_ms,
|
| + int64 policy_refresh_error_delay_ms);
|
| +
|
| + // Asks the token fetcher to fetch a new token.
|
| + void FetchToken();
|
| +
|
| + // Sends a request to the device manager backend to fetch policy if one isn't
|
| + // already outstanding.
|
| + void SendPolicyRequest();
|
| +
|
| + // Called back from the delayed work task. Performs whatever action is
|
| + // required in the current state, e.g. refreshing policy.
|
| + void DoDelayedWork();
|
| +
|
| + // Cancels the delayed work task.
|
| + void CancelDelayedWork();
|
| +
|
| + // Switches to a new state and triggers any appropriate actions.
|
| + void SetState(ClientState new_state);
|
| +
|
| + // Computes the policy refresh delay to use.
|
| + int64 GetRefreshDelay();
|
| +
|
| + CloudPolicyCache* cache_;
|
| + scoped_ptr<DeviceManagementBackend> backend_;
|
| + CloudPolicyController* controller_;
|
| + DeviceTokenFetcher* token_fetcher_;
|
| + ClientState state_;
|
| + bool initial_fetch_done_;
|
| +
|
| + int64 policy_refresh_rate_ms_;
|
| + int policy_refresh_deviation_factor_percent_;
|
| + int64 policy_refresh_deviation_max_ms_;
|
| + int64 policy_refresh_error_delay_ms_;
|
| + int64 effective_policy_refresh_error_delay_ms_;
|
| +
|
| + CancelableTask* delayed_work_task_;
|
| + ScopedRunnableMethodFactory<CloudPolicyClient> method_factory_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(CloudPolicyClient);
|
| +};
|
| +
|
| +} // namespace policy
|
| +
|
| +#endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_CLIENT_H_
|
|
|