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