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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_FACTORY_H__
6 #define CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_FACTORY_H__
8 #include "base/basictypes.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/singleton.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "components/keyed_service/content/browser_context_keyed_service_factory.h"
13 #include "components/keyed_service/core/keyed_service.h"
14 #include "components/webdata/common/web_database_service.h"
16 class KeywordWebDataService
;
20 class PasswordWebDataService
;
24 class AutofillWebDataService
;
25 } // namespace autofill
27 // A wrapper of WebDataService so that we can use it as a profile keyed service.
28 class WebDataServiceWrapper
: public KeyedService
{
30 explicit WebDataServiceWrapper(Profile
* profile
);
33 WebDataServiceWrapper();
35 virtual ~WebDataServiceWrapper();
38 virtual void Shutdown() OVERRIDE
;
40 virtual scoped_refptr
<autofill::AutofillWebDataService
> GetAutofillWebData();
42 virtual scoped_refptr
<KeywordWebDataService
> GetKeywordWebData();
44 virtual scoped_refptr
<TokenWebData
> GetTokenWebData();
47 virtual scoped_refptr
<PasswordWebDataService
> GetPasswordWebData();
51 scoped_refptr
<WebDatabaseService
> web_database_
;
53 scoped_refptr
<autofill::AutofillWebDataService
> autofill_web_data_
;
54 scoped_refptr
<KeywordWebDataService
> keyword_web_data_
;
55 scoped_refptr
<TokenWebData
> token_web_data_
;
58 scoped_refptr
<PasswordWebDataService
> password_web_data_
;
61 DISALLOW_COPY_AND_ASSIGN(WebDataServiceWrapper
);
64 // Singleton that owns all WebDataServiceWrappers and associates them with
66 class WebDataServiceFactory
: public BrowserContextKeyedServiceFactory
{
68 // Returns the WebDataServiceWrapper associated with the |profile|.
69 static WebDataServiceWrapper
* GetForProfile(
71 Profile::ServiceAccessType access_type
);
73 static WebDataServiceWrapper
* GetForProfileIfExists(
75 Profile::ServiceAccessType access_type
);
77 // Returns the AutofillWebDataService associated with the |profile|.
78 static scoped_refptr
<autofill::AutofillWebDataService
>
79 GetAutofillWebDataForProfile(Profile
* profile
,
80 Profile::ServiceAccessType access_type
);
82 // Returns the KeywordWebDataService associated with the |profile|.
83 static scoped_refptr
<KeywordWebDataService
> GetKeywordWebDataForProfile(
85 Profile::ServiceAccessType access_type
);
87 // Returns the TokenWebData associated with the |profile|.
88 static scoped_refptr
<TokenWebData
> GetTokenWebDataForProfile(
90 Profile::ServiceAccessType access_type
);
93 // Returns the PasswordWebDataService associated with the |profile|.
94 static scoped_refptr
<PasswordWebDataService
> GetPasswordWebDataForProfile(
96 Profile::ServiceAccessType access_type
);
99 static WebDataServiceFactory
* GetInstance();
102 friend struct DefaultSingletonTraits
<WebDataServiceFactory
>;
104 WebDataServiceFactory();
105 virtual ~WebDataServiceFactory();
107 // |BrowserContextKeyedBaseFactory| methods:
108 virtual content::BrowserContext
* GetBrowserContextToUse(
109 content::BrowserContext
* context
) const OVERRIDE
;
110 virtual KeyedService
* BuildServiceInstanceFor(
111 content::BrowserContext
* profile
) const OVERRIDE
;
112 virtual bool ServiceIsNULLWhileTesting() const OVERRIDE
;
114 DISALLOW_COPY_AND_ASSIGN(WebDataServiceFactory
);
117 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_FACTORY_H__