Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / chromeos / policy / device_local_account_policy_provider.h
blob3ff0f56a8317b49ce28a9637e4c0249cf7f87160
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.
5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_POLICY_PROVIDER_H_
6 #define CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_POLICY_PROVIDER_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "chrome/browser/chromeos/policy/device_local_account_external_data_manager.h"
16 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h"
17 #include "components/policy/core/common/configuration_policy_provider.h"
19 namespace policy {
21 class PolicyMap;
23 // Policy provider for a device-local account. Pulls policy from
24 // DeviceLocalAccountPolicyService. Note that this implementation keeps
25 // functioning when the device-local account disappears from
26 // DeviceLocalAccountPolicyService. The current policy will be kept in that case
27 // and RefreshPolicies becomes a no-op. Policies for any installed extensions
28 // will be kept as well in that case.
29 class DeviceLocalAccountPolicyProvider
30 : public ConfigurationPolicyProvider,
31 public DeviceLocalAccountPolicyService::Observer {
32 public:
33 DeviceLocalAccountPolicyProvider(
34 const std::string& user_id,
35 DeviceLocalAccountPolicyService* service,
36 scoped_ptr<PolicyMap> chrome_policy_overrides);
37 ~DeviceLocalAccountPolicyProvider() override;
39 // Factory function to create and initialize a provider for |user_id|. Returns
40 // NULL if |user_id| is not a device-local account or user policy isn't
41 // applicable for user_id's user type.
42 static scoped_ptr<DeviceLocalAccountPolicyProvider> Create(
43 const std::string& user_id,
44 DeviceLocalAccountPolicyService* service);
46 // ConfigurationPolicyProvider:
47 bool IsInitializationComplete(PolicyDomain domain) const override;
48 void RefreshPolicies() override;
50 // DeviceLocalAccountPolicyService::Observer:
51 void OnPolicyUpdated(const std::string& user_id) override;
52 void OnDeviceLocalAccountsChanged() override;
54 private:
55 // Returns the broker for |user_id_| or NULL if not available.
56 DeviceLocalAccountPolicyBroker* GetBroker() const;
58 // Handles completion of policy refreshes and triggers the update callback.
59 // |success| is true if the policy refresh was successful.
60 void ReportPolicyRefresh(bool success);
62 // Unless |waiting_for_policy_refresh_|, calls UpdatePolicy(), using the
63 // policy from the broker if available or keeping the current policy.
64 void UpdateFromBroker();
66 const std::string user_id_;
67 scoped_refptr<DeviceLocalAccountExternalDataManager> external_data_manager_;
69 DeviceLocalAccountPolicyService* service_;
71 // A policy map providing overrides to apply on top of the Chrome policy
72 // received from |service_|. This is used to fix certain policies for public
73 // sessions regardless of what's actually specified in policy.
74 scoped_ptr<PolicyMap> chrome_policy_overrides_;
76 bool store_initialized_;
77 bool waiting_for_policy_refresh_;
79 base::WeakPtrFactory<DeviceLocalAccountPolicyProvider> weak_factory_;
81 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyProvider);
84 } // namespace policy
86 #endif // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_POLICY_PROVIDER_H_