Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / browser / policy / profile_policy_connector_factory.h
blob22569f4c3ec9e01d070457f1cf3a3c9cd60a1e96
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.
5 #ifndef CHROME_BROWSER_POLICY_PROFILE_POLICY_CONNECTOR_FACTORY_H_
6 #define CHROME_BROWSER_POLICY_PROFILE_POLICY_CONNECTOR_FACTORY_H_
8 #include <list>
9 #include <map>
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "components/keyed_service/content/browser_context_keyed_base_factory.h"
15 template <typename T>
16 struct DefaultSingletonTraits;
18 class Profile;
20 namespace base {
21 class SequencedTaskRunner;
24 namespace content {
25 class BrowserContext;
28 namespace policy {
30 class ConfigurationPolicyProvider;
31 class ProfilePolicyConnector;
33 // Creates ProfilePolicyConnectors for Profiles, which manage the common
34 // policy providers and other policy components.
35 // TODO(joaodasilva): convert this class to a proper PKS once the PrefService,
36 // which depends on this class, becomes a PKS too.
37 class ProfilePolicyConnectorFactory : public BrowserContextKeyedBaseFactory {
38 public:
39 // Returns the ProfilePolicyConnectorFactory singleton.
40 static ProfilePolicyConnectorFactory* GetInstance();
42 // Returns the ProfilePolicyConnector associated with |profile|. This is only
43 // valid before |profile| is shut down.
44 static ProfilePolicyConnector* GetForProfile(Profile* profile);
46 // Creates a new ProfilePolicyConnector for |profile|, which must be managed
47 // by the caller. Subsequent calls to GetForProfile() will return the instance
48 // created, as long as it lives.
49 // If |force_immediate_load| is true then policy is loaded synchronously on
50 // startup.
51 static scoped_ptr<ProfilePolicyConnector> CreateForProfile(
52 Profile* profile,
53 bool force_immediate_load);
55 // Overrides the |connector| for the given |profile|; use only in tests.
56 // Once this class becomes a proper PKS then it can reuse the testing
57 // methods of BrowserContextKeyedServiceFactory.
58 void SetServiceForTesting(Profile* profile,
59 ProfilePolicyConnector* connector);
61 // The next Profile to call CreateForProfile() will get a PolicyService
62 // with |provider| as its sole policy provider. This can be called multiple
63 // times to override the policy providers for more than 1 Profile.
64 void PushProviderForTesting(ConfigurationPolicyProvider* provider);
66 private:
67 friend struct DefaultSingletonTraits<ProfilePolicyConnectorFactory>;
69 ProfilePolicyConnectorFactory();
70 virtual ~ProfilePolicyConnectorFactory();
72 ProfilePolicyConnector* GetForProfileInternal(Profile* profile);
74 scoped_ptr<ProfilePolicyConnector> CreateForProfileInternal(
75 Profile* profile,
76 bool force_immediate_load);
78 // BrowserContextKeyedBaseFactory:
79 virtual void BrowserContextShutdown(
80 content::BrowserContext* context) override;
81 virtual void BrowserContextDestroyed(
82 content::BrowserContext* context) override;
83 virtual void SetEmptyTestingFactory(
84 content::BrowserContext* context) override;
85 virtual bool HasTestingFactory(content::BrowserContext* context) override;
86 virtual void CreateServiceNow(content::BrowserContext* context) override;
88 typedef std::map<Profile*, ProfilePolicyConnector*> ConnectorMap;
89 ConnectorMap connectors_;
90 std::list<ConfigurationPolicyProvider*> test_providers_;
92 DISALLOW_COPY_AND_ASSIGN(ProfilePolicyConnectorFactory);
95 } // namespace policy
97 #endif // CHROME_BROWSER_POLICY_PROFILE_POLICY_CONNECTOR_FACTORY_H_