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_POLICY_SIGNIN_SERVICE_FACTORY_H_
6#define CHROME_BROWSER_POLICY_CLOUD_USER_POLICY_SIGNIN_SERVICE_FACTORY_H_
7
8#include "base/memory/singleton.h"
9#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
10
11class Profile;
12
13namespace user_prefs {
14class PrefRegistrySyncable;
15}
16
17namespace policy {
18
19class DeviceManagementService;
20class UserPolicySigninService;
21
22// Singleton that owns all UserPolicySigninServices and creates/deletes them as
23// new Profiles are created/shutdown.
24class UserPolicySigninServiceFactory
25    : public BrowserContextKeyedServiceFactory {
26 public:
27  // Returns an instance of the UserPolicySigninServiceFactory singleton.
28  static UserPolicySigninServiceFactory* GetInstance();
29
30  // Returns the instance of UserPolicySigninService for the passed |profile|.
31  // Used primarily for testing.
32  static UserPolicySigninService* GetForProfile(Profile* profile);
33
34  // Allows setting a mock DeviceManagementService for tests. Does not take
35  // ownership, and should be reset to NULL at the end of the test.
36  // Set this before an instance is built for a Profile.
37  static void SetDeviceManagementServiceForTesting(
38      DeviceManagementService* device_management_service);
39
40 protected:
41  // BrowserContextKeyedServiceFactory implementation.
42  virtual KeyedService* BuildServiceInstanceFor(
43      content::BrowserContext* profile) const OVERRIDE;
44
45  // Overridden to cause this object to be created when the profile is created.
46  virtual bool ServiceIsCreatedWithBrowserContext() const OVERRIDE;
47
48  // Register the preferences related to cloud-based user policy.
49  virtual void RegisterProfilePrefs(
50      user_prefs::PrefRegistrySyncable* registry) OVERRIDE;
51
52 private:
53  friend struct DefaultSingletonTraits<UserPolicySigninServiceFactory>;
54
55  UserPolicySigninServiceFactory();
56  virtual ~UserPolicySigninServiceFactory();
57
58  DISALLOW_COPY_AND_ASSIGN(UserPolicySigninServiceFactory);
59};
60
61}  // namespace policy
62
63#endif  // CHROME_BROWSER_POLICY_CLOUD_USER_POLICY_SIGNIN_SERVICE_FACTORY_H_
64