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