Upstream version 8.37.180.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / policy / profile_policy_connector_factory.h
1 // Copyright (c) 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_POLICY_PROFILE_POLICY_CONNECTOR_FACTORY_H_
6 #define CHROME_BROWSER_POLICY_PROFILE_POLICY_CONNECTOR_FACTORY_H_
7
8 #include <map>
9
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "components/keyed_service/content/browser_context_keyed_base_factory.h"
13
14 template <typename T>
15 struct DefaultSingletonTraits;
16
17 class Profile;
18
19 namespace base {
20 class SequencedTaskRunner;
21 }
22
23 namespace content {
24 class BrowserContext;
25 }
26
27 namespace policy {
28
29 class ProfilePolicyConnector;
30
31 // Creates ProfilePolicyConnectors for Profiles, which manage the common
32 // policy providers and other policy components.
33 // TODO(joaodasilva): convert this class to a proper PKS once the PrefService,
34 // which depends on this class, becomes a PKS too.
35 class ProfilePolicyConnectorFactory : public BrowserContextKeyedBaseFactory {
36  public:
37   // Returns the ProfilePolicyConnectorFactory singleton.
38   static ProfilePolicyConnectorFactory* GetInstance();
39
40   // Returns the ProfilePolicyConnector associated with |profile|. This is only
41   // valid before |profile| is shut down.
42   static ProfilePolicyConnector* GetForProfile(Profile* profile);
43
44   // Creates a new ProfilePolicyConnector for |profile|, which must be managed
45   // by the caller. Subsequent calls to GetForProfile() will return the instance
46   // created, as long as it lives.
47   // If |force_immediate_load| is true then policy is loaded synchronously on
48   // startup.
49   static scoped_ptr<ProfilePolicyConnector> CreateForProfile(
50       Profile* profile,
51       bool force_immediate_load);
52
53   // Overrides the |connector| for the given |profile|; use only in tests.
54   // Once this class becomes a proper PKS then it can reuse the testing
55   // methods of BrowserContextKeyedServiceFactory.
56   void SetServiceForTesting(Profile* profile,
57                             ProfilePolicyConnector* connector);
58
59  private:
60   friend struct DefaultSingletonTraits<ProfilePolicyConnectorFactory>;
61
62   ProfilePolicyConnectorFactory();
63   virtual ~ProfilePolicyConnectorFactory();
64
65   ProfilePolicyConnector* GetForProfileInternal(Profile* profile);
66
67   scoped_ptr<ProfilePolicyConnector> CreateForProfileInternal(
68       Profile* profile,
69       bool force_immediate_load);
70
71   // BrowserContextKeyedBaseFactory:
72   virtual void BrowserContextShutdown(
73       content::BrowserContext* context) OVERRIDE;
74   virtual void BrowserContextDestroyed(
75       content::BrowserContext* context) OVERRIDE;
76   virtual void SetEmptyTestingFactory(
77       content::BrowserContext* context) OVERRIDE;
78   virtual bool HasTestingFactory(content::BrowserContext* context) OVERRIDE;
79   virtual void CreateServiceNow(content::BrowserContext* context) OVERRIDE;
80
81   typedef std::map<Profile*, ProfilePolicyConnector*> ConnectorMap;
82   ConnectorMap connectors_;
83
84   DISALLOW_COPY_AND_ASSIGN(ProfilePolicyConnectorFactory);
85 };
86
87 }  // namespace policy
88
89 #endif  // CHROME_BROWSER_POLICY_PROFILE_POLICY_CONNECTOR_FACTORY_H_