- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / policy / cloud / cloud_policy_manager.h
1 // Copyright (c) 2012 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_CLOUD_CLOUD_POLICY_MANAGER_H_
6 #define CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_MANAGER_H_
7
8 #include <string>
9
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/prefs/pref_member.h"
14 #include "chrome/browser/policy/cloud/cloud_policy_constants.h"
15 #include "chrome/browser/policy/cloud/cloud_policy_core.h"
16 #include "chrome/browser/policy/cloud/cloud_policy_store.h"
17 #include "chrome/browser/policy/configuration_policy_provider.h"
18
19 namespace base {
20 class SequencedTaskRunner;
21 }
22
23 namespace policy {
24
25 class PolicyBundle;
26
27 // CloudPolicyManager is the main switching central between cloud policy and the
28 // upper layers of the policy stack. It wires up a CloudPolicyCore to the
29 // ConfigurationPolicyProvider interface.
30 //
31 // This class contains the base functionality, there are subclasses that add
32 // functionality specific to user-level and device-level cloud policy, such as
33 // blocking on initial user policy fetch or device enrollment.
34 class CloudPolicyManager : public ConfigurationPolicyProvider,
35                            public CloudPolicyStore::Observer {
36  public:
37   // |task_runner| is the runner for policy refresh tasks.
38   CloudPolicyManager(
39       const PolicyNamespaceKey& policy_ns_key,
40       CloudPolicyStore* cloud_policy_store,
41       const scoped_refptr<base::SequencedTaskRunner>& task_runner);
42   virtual ~CloudPolicyManager();
43
44   CloudPolicyCore* core() { return &core_; }
45   const CloudPolicyCore* core() const { return &core_; }
46
47   // ConfigurationPolicyProvider:
48   virtual void Shutdown() OVERRIDE;
49   virtual bool IsInitializationComplete(PolicyDomain domain) const OVERRIDE;
50   virtual void RefreshPolicies() OVERRIDE;
51
52   // CloudPolicyStore::Observer:
53   virtual void OnStoreLoaded(CloudPolicyStore* cloud_policy_store) OVERRIDE;
54   virtual void OnStoreError(CloudPolicyStore* cloud_policy_store) OVERRIDE;
55
56  protected:
57   // Check whether fully initialized and if so, publish policy by calling
58   // ConfigurationPolicyStore::UpdatePolicy().
59   void CheckAndPublishPolicy();
60
61   // Called by CheckAndPublishPolicy() to create a bundle with the current
62   // policies.
63   virtual scoped_ptr<PolicyBundle> CreatePolicyBundle();
64
65   // Convenience accessors to core() components.
66   CloudPolicyClient* client() { return core_.client(); }
67   const CloudPolicyClient* client() const { return core_.client(); }
68   CloudPolicyStore* store() { return core_.store(); }
69   const CloudPolicyStore* store() const { return core_.store(); }
70   CloudPolicyService* service() { return core_.service(); }
71   const CloudPolicyService* service() const { return core_.service(); }
72
73  private:
74   // Completion handler for policy refresh operations.
75   void OnRefreshComplete(bool success);
76
77   CloudPolicyCore core_;
78
79   // Whether there's a policy refresh operation pending, in which case all
80   // policy update notifications are deferred until after it completes.
81   bool waiting_for_policy_refresh_;
82
83   DISALLOW_COPY_AND_ASSIGN(CloudPolicyManager);
84 };
85
86 }  // namespace policy
87
88 #endif  // CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_MANAGER_H_