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_USER_CLOUD_POLICY_MANAGER_H_ 6 #define CHROME_BROWSER_POLICY_CLOUD_USER_CLOUD_POLICY_MANAGER_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 "chrome/browser/policy/cloud/cloud_policy_manager.h" 14 #include "components/browser_context_keyed_service/browser_context_keyed_service.h" 15 16 class PrefService; 17 class Profile; 18 19 namespace policy { 20 21 class DeviceManagementService; 22 class UserCloudPolicyStore; 23 24 // UserCloudPolicyManager handles initialization of user policy for Chrome 25 // Profiles on the desktop platforms. 26 class UserCloudPolicyManager : public CloudPolicyManager, 27 public BrowserContextKeyedService { 28 public: 29 UserCloudPolicyManager(Profile* profile, 30 scoped_ptr<UserCloudPolicyStore> store); 31 virtual ~UserCloudPolicyManager(); 32 33 // Initializes the cloud connection. |local_state| and 34 // |device_management_service| must stay valid until this object is deleted or 35 // DisconnectAndRemovePolicy() gets called. Virtual for mocking. 36 virtual void Connect(PrefService* local_state, 37 scoped_ptr<CloudPolicyClient> client); 38 39 // Shuts down the UserCloudPolicyManager (removes and stops refreshing the 40 // cached cloud policy). This is typically called when a profile is being 41 // disassociated from a given user (e.g. during signout). No policy will be 42 // provided by this object until the next time Initialize() is invoked. 43 void DisconnectAndRemovePolicy(); 44 45 // Returns true if the underlying CloudPolicyClient is already registered. 46 // Virtual for mocking. 47 virtual bool IsClientRegistered() const; 48 49 // Creates a CloudPolicyClient for this client. Used in situations where 50 // callers want to create a DMToken without actually initializing the 51 // profile's policy infrastructure. 52 static scoped_ptr<CloudPolicyClient> CreateCloudPolicyClient( 53 DeviceManagementService* device_management_service); 54 55 private: 56 // The profile this instance belongs to. 57 Profile* profile_; 58 59 // Typed pointer to the store owned by UserCloudPolicyManager. Note that 60 // CloudPolicyManager only keeps a plain CloudPolicyStore pointer. 61 scoped_ptr<UserCloudPolicyStore> store_; 62 63 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManager); 64 }; 65 66 } // namespace policy 67 68 #endif // CHROME_BROWSER_POLICY_CLOUD_USER_CLOUD_POLICY_MANAGER_H_ 69