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_LOCAL_ACCOUNT_POLICY_STORE_H_ 6 #define CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_POLICY_STORE_H_ 7 8 #include <string> 9 10 #include "base/basictypes.h" 11 #include "base/compiler_specific.h" 12 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/weak_ptr.h" 14 #include "chrome/browser/chromeos/settings/device_settings_service.h" 15 #include "chrome/browser/policy/cloud/cloud_policy_validator.h" 16 #include "chrome/browser/policy/cloud/user_cloud_policy_store_base.h" 17 18 namespace chromeos { 19 class DeviceSettingsService; 20 class SessionManagerClient; 21 } 22 23 namespace enterprise_management { 24 class PolicyFetchResponse; 25 } 26 27 namespace policy { 28 29 class DeviceLocalAccountPolicyBroker; 30 31 // CloudPolicyStore implementation for device-local account policy. Stores/loads 32 // policy to/from session_manager. 33 class DeviceLocalAccountPolicyStore 34 : public UserCloudPolicyStoreBase { 35 public: 36 DeviceLocalAccountPolicyStore( 37 const std::string& account_id, 38 chromeos::SessionManagerClient* client, 39 chromeos::DeviceSettingsService* device_settings_service); 40 virtual ~DeviceLocalAccountPolicyStore(); 41 42 const std::string& account_id() const { return account_id_; } 43 44 // CloudPolicyStore: 45 virtual void Store( 46 const enterprise_management::PolicyFetchResponse& policy) OVERRIDE; 47 virtual void Load() OVERRIDE; 48 49 private: 50 // Called back by |session_manager_client_| after policy retrieval. Checks for 51 // success and triggers policy validation. 52 void ValidateLoadedPolicyBlob(const std::string& policy_blob); 53 54 // Updates state after validation and notifies observers. 55 void UpdatePolicy(UserCloudPolicyValidator* validator); 56 57 // Sends the policy blob to session_manager for storing after validation. 58 void StoreValidatedPolicy(UserCloudPolicyValidator* validator); 59 60 // Called back when a store operation completes, updates state and reloads the 61 // policy if applicable. 62 void HandleStoreResult(bool result); 63 64 // Gets the owner key and triggers policy validation. 65 void CheckKeyAndValidate( 66 scoped_ptr<enterprise_management::PolicyFetchResponse> policy, 67 const UserCloudPolicyValidator::CompletionCallback& callback); 68 69 // Triggers policy validation. 70 void Validate( 71 scoped_ptr<enterprise_management::PolicyFetchResponse> policy, 72 const UserCloudPolicyValidator::CompletionCallback& callback, 73 chromeos::DeviceSettingsService::OwnershipStatus ownership_status, 74 bool is_owner); 75 76 const std::string account_id_; 77 chromeos::SessionManagerClient* session_manager_client_; 78 chromeos::DeviceSettingsService* device_settings_service_; 79 80 base::WeakPtrFactory<DeviceLocalAccountPolicyStore> weak_factory_; 81 82 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyStore); 83 }; 84 85 } // namespace policy 86 87 #endif // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_POLICY_STORE_H_ 88