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