Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / policy / device_cloud_policy_store_chromeos.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_CHROMEOS_POLICY_DEVICE_CLOUD_POLICY_STORE_CHROMEOS_H_
6 #define CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_CLOUD_POLICY_STORE_CHROMEOS_H_
7
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "chrome/browser/chromeos/policy/device_cloud_policy_validator.h"
14 #include "chrome/browser/chromeos/settings/device_settings_service.h"
15 #include "components/policy/core/common/cloud/cloud_policy_store.h"
16
17 namespace base {
18 class SequencedTaskRunner;
19 }
20
21 namespace enterprise_management {
22 class PolicyFetchResponse;
23 }
24
25 namespace policy {
26
27 class EnterpriseInstallAttributes;
28
29 // CloudPolicyStore implementation for device policy on Chrome OS. Policy is
30 // stored/loaded via DBus to/from session_manager.
31 class DeviceCloudPolicyStoreChromeOS
32     : public CloudPolicyStore,
33       public chromeos::DeviceSettingsService::Observer {
34  public:
35   DeviceCloudPolicyStoreChromeOS(
36       chromeos::DeviceSettingsService* device_settings_service,
37       EnterpriseInstallAttributes* install_attributes,
38       scoped_refptr<base::SequencedTaskRunner> background_task_runner);
39   virtual ~DeviceCloudPolicyStoreChromeOS();
40
41   // CloudPolicyStore:
42   virtual void Store(
43       const enterprise_management::PolicyFetchResponse& policy) override;
44   virtual void Load() override;
45
46   // Installs initial policy. This is different from Store() in that it skips
47   // the signature validation step against already-installed policy. The checks
48   // against installation-time attributes are performed nevertheless. The result
49   // of the operation is reported through the OnStoreLoaded() or OnStoreError()
50   // observer callbacks.
51   void InstallInitialPolicy(
52       const enterprise_management::PolicyFetchResponse& policy);
53
54   // chromeos::DeviceSettingsService::Observer:
55   virtual void OwnershipStatusChanged() override;
56   virtual void DeviceSettingsUpdated() override;
57   virtual void OnDeviceSettingsServiceShutdown() override;
58
59  private:
60   // Create a validator for |policy| with basic device policy configuration and
61   // OnPolicyStored() as the completion callback.
62   scoped_ptr<DeviceCloudPolicyValidator> CreateValidator(
63       const enterprise_management::PolicyFetchResponse& policy);
64
65   // Called on completion on the policy validation prior to storing policy.
66   // Starts the actual store operation.
67   void OnPolicyToStoreValidated(DeviceCloudPolicyValidator* validator);
68
69   // Handles store completion operations updates status.
70   void OnPolicyStored();
71
72   // Re-syncs policy and status from |device_settings_service_|.
73   void UpdateFromService();
74
75   chromeos::DeviceSettingsService* device_settings_service_;
76   EnterpriseInstallAttributes* install_attributes_;
77
78   scoped_refptr<base::SequencedTaskRunner> background_task_runner_;
79
80   // Whether enterprise enrollment validation has yet been done.
81   bool enrollment_validation_done_;
82
83   base::WeakPtrFactory<DeviceCloudPolicyStoreChromeOS> weak_factory_;
84
85   DISALLOW_COPY_AND_ASSIGN(DeviceCloudPolicyStoreChromeOS);
86 };
87
88 }  // namespace policy
89
90 #endif  // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_CLOUD_POLICY_STORE_CHROMEOS_H_