policy_cert_service_factory.h revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
1// Copyright 2013 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_POLICY_CERT_SERVICE_FACTORY_H_
6#define CHROME_BROWSER_CHROMEOS_POLICY_POLICY_CERT_SERVICE_FACTORY_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 "components/browser_context_keyed_service/browser_context_keyed_service_factory.h"
14
15template <typename T> struct DefaultSingletonTraits;
16
17class PrefRegistrySimple;
18class Profile;
19
20namespace policy {
21
22class PolicyCertService;
23class PolicyCertVerifier;
24
25// Factory to create PolicyCertServices.
26class PolicyCertServiceFactory : public BrowserContextKeyedServiceFactory {
27 public:
28  // Returns an existing PolicyCertService for |profile|. See
29  // CreateForProfile.
30  static PolicyCertService* GetForProfile(Profile* profile);
31
32  // Creates a new PolicyCertService and returns the associated
33  // PolicyCertVerifier. Returns NULL if this service isn't allowed for
34  // |profile|, i.e. if NetworkConfigurationUpdater doesn't exist.
35  // This service is created separately for the original profile and the
36  // incognito profile.
37  // Note: NetworkConfigurationUpdater is currently only created for the primary
38  // user's profile.
39  static scoped_ptr<PolicyCertVerifier> CreateForProfile(Profile* profile);
40
41  static PolicyCertServiceFactory* GetInstance();
42
43  // Used to mark or clear |user_id| as having used certificates pushed by
44  // policy before.
45  static void SetUsedPolicyCertificates(const std::string& user_id);
46  static void ClearUsedPolicyCertificates(const std::string& user_id);
47  static bool UsedPolicyCertificates(const std::string& user_id);
48
49  static void RegisterPrefs(PrefRegistrySimple* local_state);
50
51 private:
52  friend struct DefaultSingletonTraits<PolicyCertServiceFactory>;
53
54  PolicyCertServiceFactory();
55  virtual ~PolicyCertServiceFactory();
56
57  // BrowserContextKeyedServiceFactory:
58  virtual BrowserContextKeyedService* BuildServiceInstanceFor(
59      content::BrowserContext* context) const OVERRIDE;
60  virtual content::BrowserContext* GetBrowserContextToUse(
61      content::BrowserContext* context) const OVERRIDE;
62  virtual void RegisterProfilePrefs(
63      user_prefs::PrefRegistrySyncable* registry) OVERRIDE;
64  virtual bool ServiceIsNULLWhileTesting() const OVERRIDE;
65
66  DISALLOW_COPY_AND_ASSIGN(PolicyCertServiceFactory);
67};
68
69}  // namespace policy
70
71#endif  // CHROME_BROWSER_CHROMEOS_POLICY_POLICY_CERT_SERVICE_FACTORY_H_
72