145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org// Copyright (c) 2013 The Chromium Authors. All rights reserved. 245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org// Use of this source code is governed by a BSD-style license that can be 345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org// found in the LICENSE file. 445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#ifndef CHROME_BROWSER_POLICY_PROFILE_POLICY_CONNECTOR_FACTORY_H_ 645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define CHROME_BROWSER_POLICY_PROFILE_POLICY_CONNECTOR_FACTORY_H_ 745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include <list> 945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include <map> 1045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 1145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include "base/basictypes.h" 1245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include "base/memory/scoped_ptr.h" 1345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include "components/keyed_service/content/browser_context_keyed_base_factory.h" 1445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 1545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtemplate <typename T> 1645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstruct DefaultSingletonTraits; 1745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 1845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgclass Profile; 1945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 2045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgnamespace base { 2145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgclass SequencedTaskRunner; 2245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} 2345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 2445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgnamespace content { 2545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgclass BrowserContext; 2645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} 2745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 2845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgnamespace policy { 2945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 3045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgclass ConfigurationPolicyProvider; 3145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgclass ProfilePolicyConnector; 3245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 3345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org// Creates ProfilePolicyConnectors for Profiles, which manage the common 3445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org// policy providers and other policy components. 3545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org// TODO(joaodasilva): convert this class to a proper PKS once the PrefService, 3645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org// which depends on this class, becomes a PKS too. 3745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgclass ProfilePolicyConnectorFactory : public BrowserContextKeyedBaseFactory { 3845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org public: 3945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // Returns the ProfilePolicyConnectorFactory singleton. 4045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org static ProfilePolicyConnectorFactory* GetInstance(); 4145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 4245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // Returns the ProfilePolicyConnector associated with |profile|. This is only 4345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // valid before |profile| is shut down. 4445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org static ProfilePolicyConnector* GetForProfile(Profile* profile); 4545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 4645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // Creates a new ProfilePolicyConnector for |profile|, which must be managed 4745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // by the caller. Subsequent calls to GetForProfile() will return the instance 4845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // created, as long as it lives. 4945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // If |force_immediate_load| is true then policy is loaded synchronously on 5045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // startup. 5145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org static scoped_ptr<ProfilePolicyConnector> CreateForProfile( 5245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org Profile* profile, 5345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org bool force_immediate_load); 5445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 5545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // Overrides the |connector| for the given |profile|; use only in tests. 5645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // Once this class becomes a proper PKS then it can reuse the testing 5745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // methods of BrowserContextKeyedServiceFactory. 5845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org void SetServiceForTesting(Profile* profile, 5945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ProfilePolicyConnector* connector); 6045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 6145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // The next Profile to call CreateForProfile() will get a PolicyService 6245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // with |provider| as its sole policy provider. This can be called multiple 6345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // times to override the policy providers for more than 1 Profile. 6445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org void PushProviderForTesting(ConfigurationPolicyProvider* provider); 6545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 6645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org private: 6745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org friend struct DefaultSingletonTraits<ProfilePolicyConnectorFactory>; 6845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 6945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ProfilePolicyConnectorFactory(); 7045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org virtual ~ProfilePolicyConnectorFactory(); 7145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 72d65182f1818d1c19e6f3866ab6e68a262fad5185hbono@chromium.org ProfilePolicyConnector* GetForProfileInternal(Profile* profile); 73d65182f1818d1c19e6f3866ab6e68a262fad5185hbono@chromium.org 7445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org scoped_ptr<ProfilePolicyConnector> CreateForProfileInternal( 7545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org Profile* profile, 7645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org bool force_immediate_load); 7745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 7845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org // BrowserContextKeyedBaseFactory: 7945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org virtual void BrowserContextShutdown( 8045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org content::BrowserContext* context) OVERRIDE; 8145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org virtual void BrowserContextDestroyed( 8245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org content::BrowserContext* context) OVERRIDE; 8345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org virtual void SetEmptyTestingFactory( 8445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org content::BrowserContext* context) OVERRIDE; 8545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org virtual bool HasTestingFactory(content::BrowserContext* context) OVERRIDE; 8645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org virtual void CreateServiceNow(content::BrowserContext* context) OVERRIDE; 8745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 8845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org typedef std::map<Profile*, ProfilePolicyConnector*> ConnectorMap; 8945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ConnectorMap connectors_; 9045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org std::list<ConfigurationPolicyProvider*> test_providers_; 9145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 9245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org DISALLOW_COPY_AND_ASSIGN(ProfilePolicyConnectorFactory); 9345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org}; 9445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 9545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} // namespace policy 9645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 9745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#endif // CHROME_BROWSER_POLICY_PROFILE_POLICY_CONNECTOR_FACTORY_H_ 9845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org