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_WEBDATA_WEB_DATA_SERVICE_FACTORY_H__ 6 #define CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_FACTORY_H__ 7 8 #include "base/basictypes.h" 9 #include "base/memory/ref_counted.h" 10 #include "base/memory/singleton.h" 11 #include "chrome/browser/profiles/profile.h" 12 #include "components/keyed_service/content/browser_context_keyed_service_factory.h" 13 #include "components/keyed_service/core/keyed_service.h" 14 #include "components/webdata/common/web_database_service.h" 15 16 class KeywordWebDataService; 17 class TokenWebData; 18 19 #if defined(OS_WIN) 20 class PasswordWebDataService; 21 #endif 22 23 namespace autofill { 24 class AutofillWebDataService; 25 } // namespace autofill 26 27 // A wrapper of WebDataService so that we can use it as a profile keyed service. 28 class WebDataServiceWrapper : public KeyedService { 29 public: 30 explicit WebDataServiceWrapper(Profile* profile); 31 32 // For testing. 33 WebDataServiceWrapper(); 34 35 virtual ~WebDataServiceWrapper(); 36 37 // KeyedService: 38 virtual void Shutdown() OVERRIDE; 39 40 virtual scoped_refptr<autofill::AutofillWebDataService> GetAutofillWebData(); 41 42 virtual scoped_refptr<KeywordWebDataService> GetKeywordWebData(); 43 44 virtual scoped_refptr<TokenWebData> GetTokenWebData(); 45 46 #if defined(OS_WIN) 47 virtual scoped_refptr<PasswordWebDataService> GetPasswordWebData(); 48 #endif 49 50 private: 51 scoped_refptr<WebDatabaseService> web_database_; 52 53 scoped_refptr<autofill::AutofillWebDataService> autofill_web_data_; 54 scoped_refptr<KeywordWebDataService> keyword_web_data_; 55 scoped_refptr<TokenWebData> token_web_data_; 56 57 #if defined(OS_WIN) 58 scoped_refptr<PasswordWebDataService> password_web_data_; 59 #endif 60 61 DISALLOW_COPY_AND_ASSIGN(WebDataServiceWrapper); 62 }; 63 64 // Singleton that owns all WebDataServiceWrappers and associates them with 65 // Profiles. 66 class WebDataServiceFactory : public BrowserContextKeyedServiceFactory { 67 public: 68 // Returns the WebDataServiceWrapper associated with the |profile|. 69 static WebDataServiceWrapper* GetForProfile( 70 Profile* profile, 71 Profile::ServiceAccessType access_type); 72 73 static WebDataServiceWrapper* GetForProfileIfExists( 74 Profile* profile, 75 Profile::ServiceAccessType access_type); 76 77 // Returns the AutofillWebDataService associated with the |profile|. 78 static scoped_refptr<autofill::AutofillWebDataService> 79 GetAutofillWebDataForProfile(Profile* profile, 80 Profile::ServiceAccessType access_type); 81 82 // Returns the KeywordWebDataService associated with the |profile|. 83 static scoped_refptr<KeywordWebDataService> GetKeywordWebDataForProfile( 84 Profile* profile, 85 Profile::ServiceAccessType access_type); 86 87 // Returns the TokenWebData associated with the |profile|. 88 static scoped_refptr<TokenWebData> GetTokenWebDataForProfile( 89 Profile* profile, 90 Profile::ServiceAccessType access_type); 91 92 #if defined(OS_WIN) 93 // Returns the PasswordWebDataService associated with the |profile|. 94 static scoped_refptr<PasswordWebDataService> GetPasswordWebDataForProfile( 95 Profile* profile, 96 Profile::ServiceAccessType access_type); 97 #endif 98 99 static WebDataServiceFactory* GetInstance(); 100 101 private: 102 friend struct DefaultSingletonTraits<WebDataServiceFactory>; 103 104 WebDataServiceFactory(); 105 virtual ~WebDataServiceFactory(); 106 107 // |BrowserContextKeyedBaseFactory| methods: 108 virtual content::BrowserContext* GetBrowserContextToUse( 109 content::BrowserContext* context) const OVERRIDE; 110 virtual KeyedService* BuildServiceInstanceFor( 111 content::BrowserContext* profile) const OVERRIDE; 112 virtual bool ServiceIsNULLWhileTesting() const OVERRIDE; 113 114 DISALLOW_COPY_AND_ASSIGN(WebDataServiceFactory); 115 }; 116 117 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_FACTORY_H__ 118