asynchronous_policy_provider.h revision 3f50c38dc070f4bb515c1b64450dae14f316474e
1// Copyright (c) 2010 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_PROVIDER_H_
6#define CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_PROVIDER_H_
7#pragma once
8
9#include "base/ref_counted.h"
10#include "base/threading/non_thread_safe.h"
11#include "base/weak_ptr.h"
12#include "chrome/browser/policy/configuration_policy_provider.h"
13
14namespace policy {
15
16class AsynchronousPolicyLoader;
17
18// Policy provider that loads policy asynchronously. Providers should subclass
19// from this class if loading the policy requires disk access or must for some
20// other reason be performed on the file thread. The actual logic for loading
21// policy is handled by a delegate passed at construction time.
22class AsynchronousPolicyProvider
23    : public ConfigurationPolicyProvider,
24      public base::NonThreadSafe {
25 public:
26  // Must be implemented by subclasses of the asynchronous policy provider to
27  // provide the implementation details of how policy is loaded.
28  class Delegate {
29   public:
30    virtual ~Delegate() {}
31
32    virtual DictionaryValue* Load() = 0;
33  };
34
35  // Assumes ownership of |loader|.
36  AsynchronousPolicyProvider(
37      const PolicyDefinitionList* policy_list,
38      scoped_refptr<AsynchronousPolicyLoader> loader);
39  virtual ~AsynchronousPolicyProvider();
40
41  // ConfigurationPolicyProvider implementation.
42  virtual bool Provide(ConfigurationPolicyStoreInterface* store);
43
44  // For tests to trigger reloads.
45  scoped_refptr<AsynchronousPolicyLoader> loader();
46
47 protected:
48  // The loader object used internally.
49  scoped_refptr<AsynchronousPolicyLoader> loader_;
50
51 private:
52  // ConfigurationPolicyProvider overrides:
53  virtual void AddObserver(ConfigurationPolicyProvider::Observer* observer);
54  virtual void RemoveObserver(ConfigurationPolicyProvider::Observer* observer);
55
56  DISALLOW_COPY_AND_ASSIGN(AsynchronousPolicyProvider);
57};
58
59}  // namespace policy
60
61#endif  // CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_PROVIDER_H_
62