| 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 "chrome/browser/profiles/profile_keyed_service.h" | 12 #include "chrome/browser/profiles/profile_keyed_service.h" |
| 13 #include "chrome/browser/profiles/profile_keyed_service_factory.h" | 13 #include "chrome/browser/profiles/profile_keyed_service_factory.h" |
| 14 #include "chrome/browser/webdata/web_data_service.h" | 14 #include "chrome/browser/webdata/web_database_service.h" |
| 15 |
| 16 class AutofillWebDataService; |
| 17 class WebDataService; |
| 15 | 18 |
| 16 // A wrapper of WebDataService so that we can use it as a profile keyed service. | 19 // A wrapper of WebDataService so that we can use it as a profile keyed service. |
| 17 class WebDataServiceWrapper : public ProfileKeyedService { | 20 class WebDataServiceWrapper : public ProfileKeyedService { |
| 18 public: | 21 public: |
| 19 explicit WebDataServiceWrapper(Profile* profile); | 22 explicit WebDataServiceWrapper(Profile* profile); |
| 20 | 23 |
| 21 // For testing. | 24 // For testing. |
| 22 WebDataServiceWrapper(); | 25 WebDataServiceWrapper(); |
| 23 | 26 |
| 24 virtual ~WebDataServiceWrapper(); | 27 virtual ~WebDataServiceWrapper(); |
| 25 | 28 |
| 26 // ProfileKeyedService: | 29 // ProfileKeyedService: |
| 27 virtual void Shutdown() OVERRIDE; | 30 virtual void Shutdown() OVERRIDE; |
| 28 | 31 |
| 32 virtual scoped_refptr<AutofillWebDataService> GetAutofillWebData(); |
| 33 |
| 29 virtual scoped_refptr<WebDataService> GetWebData(); | 34 virtual scoped_refptr<WebDataService> GetWebData(); |
| 30 | 35 |
| 31 private: | 36 private: |
| 32 scoped_refptr<WebDataService> web_data_service_; | 37 scoped_refptr<WebDatabaseService> web_database_; |
| 38 |
| 39 scoped_refptr<AutofillWebDataService> autofill_web_data_; |
| 40 scoped_refptr<WebDataService> web_data_; |
| 33 | 41 |
| 34 DISALLOW_COPY_AND_ASSIGN(WebDataServiceWrapper); | 42 DISALLOW_COPY_AND_ASSIGN(WebDataServiceWrapper); |
| 35 }; | 43 }; |
| 36 | 44 |
| 37 // Singleton that owns all WebDataServiceWrappers and associates them with | 45 // Singleton that owns all WebDataServiceWrappers and associates them with |
| 38 // Profiles. | 46 // Profiles. |
| 39 class WebDataServiceFactory : public ProfileKeyedServiceFactory { | 47 class WebDataServiceFactory : public ProfileKeyedServiceFactory { |
| 40 public: | 48 public: |
| 41 // Returns the |WebDataService| associated with the |profile|. | 49 // Returns the |WebDataServiceWrapper| associated with the |profile|. |
| 42 // |access_type| is either EXPLICIT_ACCESS or IMPLICIT_ACCESS | 50 // |access_type| is either EXPLICIT_ACCESS or IMPLICIT_ACCESS |
| 43 // (see its definition). | 51 // (see its definition). |
| 44 static scoped_refptr<WebDataService> GetForProfile( | 52 static WebDataServiceWrapper* GetForProfile( |
| 45 Profile* profile, Profile::ServiceAccessType access_type); | 53 Profile* profile, Profile::ServiceAccessType access_type); |
| 46 | 54 |
| 47 static scoped_refptr<WebDataService> GetForProfileIfExists( | 55 static WebDataServiceWrapper* GetForProfileIfExists( |
| 48 Profile* profile, Profile::ServiceAccessType access_type); | 56 Profile* profile, Profile::ServiceAccessType access_type); |
| 49 | 57 |
| 50 static WebDataServiceFactory* GetInstance(); | 58 static WebDataServiceFactory* GetInstance(); |
| 51 | 59 |
| 52 private: | 60 private: |
| 53 friend struct DefaultSingletonTraits<WebDataServiceFactory>; | 61 friend struct DefaultSingletonTraits<WebDataServiceFactory>; |
| 54 | 62 |
| 55 WebDataServiceFactory(); | 63 WebDataServiceFactory(); |
| 56 virtual ~WebDataServiceFactory(); | 64 virtual ~WebDataServiceFactory(); |
| 57 | 65 |
| 58 // |ProfileKeyedBaseFactory| methods: | 66 // |ProfileKeyedBaseFactory| methods: |
| 59 virtual bool ServiceRedirectedInIncognito() const OVERRIDE; | 67 virtual bool ServiceRedirectedInIncognito() const OVERRIDE; |
| 60 virtual ProfileKeyedService* BuildServiceInstanceFor( | 68 virtual ProfileKeyedService* BuildServiceInstanceFor( |
| 61 Profile* profile) const OVERRIDE; | 69 Profile* profile) const OVERRIDE; |
| 62 virtual bool ServiceIsNULLWhileTesting() const OVERRIDE; | 70 virtual bool ServiceIsNULLWhileTesting() const OVERRIDE; |
| 63 | 71 |
| 64 DISALLOW_COPY_AND_ASSIGN(WebDataServiceFactory); | 72 DISALLOW_COPY_AND_ASSIGN(WebDataServiceFactory); |
| 65 }; | 73 }; |
| 66 | 74 |
| 67 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_FACTORY_H__ | 75 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_FACTORY_H__ |
| OLD | NEW |