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 // Singleton that owns all WebDataServiceWrappers and associates them with |
| 37 // Profiles. |
| 38 class WebDataServiceFactory : public ProfileKeyedServiceFactory { |
16 public: | 39 public: |
17 // Returns the |WebDataService| associated with the |profile|. | 40 // Returns the |WebDataService| associated with the |profile|. |
18 // |access_type| is either EXPLICIT_ACCESS or IMPLICIT_ACCESS | 41 // |access_type| is either EXPLICIT_ACCESS or IMPLICIT_ACCESS |
19 // (see its definition). | 42 // (see its definition). |
20 static scoped_refptr<WebDataService> GetForProfile( | 43 static scoped_refptr<WebDataService> GetForProfile( |
21 Profile* profile, Profile::ServiceAccessType access_type); | 44 Profile* profile, Profile::ServiceAccessType access_type); |
22 | 45 |
23 static scoped_refptr<WebDataService> GetForProfileIfExists( | 46 static scoped_refptr<WebDataService> GetForProfileIfExists( |
24 Profile* profile, Profile::ServiceAccessType access_type); | 47 Profile* profile, Profile::ServiceAccessType access_type); |
25 | 48 |
26 static WebDataServiceFactory* GetInstance(); | 49 static WebDataServiceFactory* GetInstance(); |
27 | 50 |
28 private: | 51 private: |
29 friend struct DefaultSingletonTraits<WebDataServiceFactory>; | 52 friend struct DefaultSingletonTraits<WebDataServiceFactory>; |
30 | 53 |
31 WebDataServiceFactory(); | 54 WebDataServiceFactory(); |
32 virtual ~WebDataServiceFactory(); | 55 virtual ~WebDataServiceFactory(); |
33 | 56 |
34 // |ProfileKeyedBaseFactory| methods: | 57 // |ProfileKeyedBaseFactory| methods: |
35 virtual bool ServiceRedirectedInIncognito() const OVERRIDE; | 58 virtual bool ServiceRedirectedInIncognito() const OVERRIDE; |
36 virtual scoped_refptr<RefcountedProfileKeyedService> BuildServiceInstanceFor( | 59 virtual ProfileKeyedService* BuildServiceInstanceFor( |
37 Profile* profile) const OVERRIDE; | 60 Profile* profile) const OVERRIDE; |
38 virtual bool ServiceIsNULLWhileTesting() const OVERRIDE; | 61 virtual bool ServiceIsNULLWhileTesting() const OVERRIDE; |
| 62 |
| 63 DISALLOW_COPY_AND_ASSIGN(WebDataServiceFactory); |
39 }; | 64 }; |
40 | 65 |
41 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_FACTORY_H__ | 66 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_FACTORY_H__ |
OLD | NEW |