Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / webdata / web_data_service_factory.h
bloba8d848ec2254b357a8ccbc8f3fe8bbac0fc88024
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/browser_context_keyed_service/browser_context_keyed_service.h"
13 #include "components/browser_context_keyed_service/browser_context_keyed_service_factory.h"
14 #include "components/webdata/common/web_database_service.h"
16 class TokenWebData;
17 class WebDataService;
19 namespace autofill {
20 class AutofillWebDataService;
21 } // namespace autofill
23 // A wrapper of WebDataService so that we can use it as a profile keyed service.
24 class WebDataServiceWrapper : public BrowserContextKeyedService {
25 public:
26 explicit WebDataServiceWrapper(Profile* profile);
28 // For testing.
29 WebDataServiceWrapper();
31 virtual ~WebDataServiceWrapper();
33 // BrowserContextKeyedService:
34 virtual void Shutdown() OVERRIDE;
36 virtual scoped_refptr<autofill::AutofillWebDataService> GetAutofillWebData();
38 virtual scoped_refptr<WebDataService> GetWebData();
40 virtual scoped_refptr<TokenWebData> GetTokenWebData();
42 private:
43 scoped_refptr<WebDatabaseService> web_database_;
45 scoped_refptr<autofill::AutofillWebDataService> autofill_web_data_;
46 scoped_refptr<TokenWebData> token_web_data_;
47 scoped_refptr<WebDataService> web_data_;
49 DISALLOW_COPY_AND_ASSIGN(WebDataServiceWrapper);
52 // Singleton that owns all WebDataServiceWrappers and associates them with
53 // Profiles.
54 class WebDataServiceFactory : public BrowserContextKeyedServiceFactory {
55 public:
56 // Returns the WebDataServiceWrapper associated with the |profile|.
57 static WebDataServiceWrapper* GetForProfile(
58 Profile* profile,
59 Profile::ServiceAccessType access_type);
61 static WebDataServiceWrapper* GetForProfileIfExists(
62 Profile* profile,
63 Profile::ServiceAccessType access_type);
65 // Returns the AutofillWebDataService associated with the |profile|.
66 static scoped_refptr<autofill::AutofillWebDataService>
67 GetAutofillWebDataForProfile(Profile* profile,
68 Profile::ServiceAccessType access_type);
70 // Returns the TokenWebData associated with the |profile|.
71 static scoped_refptr<TokenWebData> GetTokenWebDataForProfile(Profile* profile,
72 Profile::ServiceAccessType access_type);
74 static WebDataServiceFactory* GetInstance();
76 private:
77 friend struct DefaultSingletonTraits<WebDataServiceFactory>;
79 WebDataServiceFactory();
80 virtual ~WebDataServiceFactory();
82 // |BrowserContextKeyedBaseFactory| methods:
83 virtual content::BrowserContext* GetBrowserContextToUse(
84 content::BrowserContext* context) const OVERRIDE;
85 virtual BrowserContextKeyedService* BuildServiceInstanceFor(
86 content::BrowserContext* profile) const OVERRIDE;
87 virtual bool ServiceIsNULLWhileTesting() const OVERRIDE;
89 DISALLOW_COPY_AND_ASSIGN(WebDataServiceFactory);
92 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_FACTORY_H__