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 // Chromium settings and storage represent user-selected preferences and
6 // information and MUST not be extracted, overwritten or modified except
7 // through Chromium defined APIs.
9 #ifndef CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__
10 #define CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__
16 #include "base/callback_forward.h"
17 #include "base/files/file_path.h"
18 #include "base/location.h"
19 #include "base/memory/ref_counted.h"
20 #include "base/sequenced_task_runner_helpers.h"
21 #include "chrome/browser/search_engines/template_url.h"
22 #include "chrome/browser/search_engines/template_url_id.h"
23 #include "chrome/browser/webdata/keyword_table.h"
24 #include "components/webdata/common/web_data_results.h"
25 #include "components/webdata/common/web_data_service_base.h"
26 #include "components/webdata/common/web_data_service_consumer.h"
27 #include "components/webdata/common/web_database.h"
29 struct DefaultWebIntentService
;
32 struct IE7PasswordInfo
;
36 class WebDatabaseService
;
46 namespace webkit_glue
{
47 struct WebIntentServiceData
;
50 ////////////////////////////////////////////////////////////////////////////////
52 // WebDataService is a generic data repository for meta data associated with
53 // web pages. All data is retrieved and archived in an asynchronous way.
55 // All requests return a handle. The handle can be used to cancel the request.
57 ////////////////////////////////////////////////////////////////////////////////
60 ////////////////////////////////////////////////////////////////////////////////
62 // WebDataService results
64 ////////////////////////////////////////////////////////////////////////////////
66 typedef base::Callback
<scoped_ptr
<WDTypedResult
>(void)> ResultTask
;
68 // Result from GetWebAppImages.
69 struct WDAppImagesResult
{
73 // True if SetWebAppHasAllImages(true) was invoked.
76 // The images, may be empty.
77 std::vector
<SkBitmap
> images
;
80 struct WDKeywordsResult
{
84 KeywordTable::Keywords keywords
;
85 // Identifies the ID of the TemplateURL that is the default search. A value of
86 // 0 indicates there is no default search provider.
87 int64 default_search_provider_id
;
88 // Version of the built-in keywords. A value of 0 indicates a first run.
89 int builtin_keyword_version
;
92 class WebDataServiceConsumer
;
94 class WebDataService
: public WebDataServiceBase
{
96 // Retrieve a WebDataService for the given context.
97 static scoped_refptr
<WebDataService
> FromBrowserContext(
98 content::BrowserContext
* context
);
100 WebDataService(scoped_refptr
<WebDatabaseService
> wdbs
,
101 const ProfileErrorCallback
& callback
);
103 //////////////////////////////////////////////////////////////////////////////
107 //////////////////////////////////////////////////////////////////////////////
109 // As the database processes requests at a later date, all deletion is
110 // done on the background thread.
112 // Many of the keyword related methods do not return a handle. This is because
113 // the caller (TemplateURLService) does not need to know when the request is
116 void AddKeyword(const TemplateURLData
& data
);
117 void RemoveKeyword(TemplateURLID id
);
118 void UpdateKeyword(const TemplateURLData
& data
);
120 // Fetches the keywords.
121 // On success, consumer is notified with WDResult<KeywordTable::Keywords>.
122 Handle
GetKeywords(WebDataServiceConsumer
* consumer
);
124 // Sets the keywords used for the default search provider.
125 void SetDefaultSearchProvider(const TemplateURL
* url
);
127 // Sets the version of the builtin keywords.
128 void SetBuiltinKeywordVersion(int version
);
130 //////////////////////////////////////////////////////////////////////////////
134 //////////////////////////////////////////////////////////////////////////////
136 // Sets the image for the specified web app. A web app can have any number of
137 // images, but only one at a particular size. If there was an image for the
138 // web app at the size of the given image it is replaced.
139 void SetWebAppImage(const GURL
& app_url
, const SkBitmap
& image
);
141 // Sets whether all the images have been downloaded for the specified web app.
142 void SetWebAppHasAllImages(const GURL
& app_url
, bool has_all_images
);
144 // Removes all images for the specified web app.
145 void RemoveWebApp(const GURL
& app_url
);
147 // Fetches the images and whether all images have been downloaded for the
148 // specified web app.
149 Handle
GetWebAppImages(const GURL
& app_url
, WebDataServiceConsumer
* consumer
);
152 //////////////////////////////////////////////////////////////////////////////
154 // IE7/8 Password Access (used by PasswordStoreWin - do not use elsewhere)
156 //////////////////////////////////////////////////////////////////////////////
158 // Adds |info| to the list of imported passwords from ie7/ie8.
159 void AddIE7Login(const IE7PasswordInfo
& info
);
161 // Removes |info| from the list of imported passwords from ie7/ie8.
162 void RemoveIE7Login(const IE7PasswordInfo
& info
);
164 // Get the login matching the information in |info|. |consumer| will be
165 // notified when the request is done. The result is of type
166 // WDResult<IE7PasswordInfo>.
167 // If there is no match, the fields of the IE7PasswordInfo will be empty.
168 Handle
GetIE7Login(const IE7PasswordInfo
& info
,
169 WebDataServiceConsumer
* consumer
);
170 #endif // defined(OS_WIN)
173 // For unit tests, passes a null callback.
176 virtual ~WebDataService();
179 //////////////////////////////////////////////////////////////////////////////
181 // The following methods are only invoked on the DB thread.
183 //////////////////////////////////////////////////////////////////////////////
185 //////////////////////////////////////////////////////////////////////////////
189 //////////////////////////////////////////////////////////////////////////////
190 WebDatabase::State
AddKeywordImpl(
191 const TemplateURLData
& data
, WebDatabase
* db
);
192 WebDatabase::State
RemoveKeywordImpl(
193 TemplateURLID id
, WebDatabase
* db
);
194 WebDatabase::State
UpdateKeywordImpl(
195 const TemplateURLData
& data
, WebDatabase
* db
);
196 scoped_ptr
<WDTypedResult
> GetKeywordsImpl(WebDatabase
* db
);
197 WebDatabase::State
SetDefaultSearchProviderImpl(
198 TemplateURLID r
, WebDatabase
* db
);
199 WebDatabase::State
SetBuiltinKeywordVersionImpl(int version
, WebDatabase
* db
);
201 //////////////////////////////////////////////////////////////////////////////
205 //////////////////////////////////////////////////////////////////////////////
207 WebDatabase::State
SetWebAppImageImpl(const GURL
& app_url
,
208 const SkBitmap
& image
, WebDatabase
* db
);
209 WebDatabase::State
SetWebAppHasAllImagesImpl(const GURL
& app_url
,
210 bool has_all_images
, WebDatabase
* db
);
211 WebDatabase::State
RemoveWebAppImpl(const GURL
& app_url
, WebDatabase
* db
);
212 scoped_ptr
<WDTypedResult
> GetWebAppImagesImpl(
213 const GURL
& app_url
, WebDatabase
* db
);
215 #if defined(ENABLE_WEB_INTENTS)
216 //////////////////////////////////////////////////////////////////////////////
220 //////////////////////////////////////////////////////////////////////////////
221 WebDatabase::State
AddWebIntentServiceImpl(
222 const webkit_glue::WebIntentServiceData
& service
);
223 WebDatabase::State
RemoveWebIntentServiceImpl(
224 const webkit_glue::WebIntentServiceData
& service
);
225 scoped_ptr
<WDTypedResult
> GetWebIntentServicesImpl(
226 const base::string16
& action
);
227 scoped_ptr
<WDTypedResult
> GetWebIntentServicesForURLImpl(
228 const base::string16
& service_url
);
229 scoped_ptr
<WDTypedResult
> GetAllWebIntentServicesImpl();
230 WebDatabase::State
AddDefaultWebIntentServiceImpl(
231 const DefaultWebIntentService
& service
);
232 WebDatabase::State
RemoveDefaultWebIntentServiceImpl(
233 const DefaultWebIntentService
& service
);
234 WebDatabase::State
RemoveWebIntentServiceDefaultsImpl(
235 const GURL
& service_url
);
236 scoped_ptr
<WDTypedResult
> GetDefaultWebIntentServicesForActionImpl(
237 const base::string16
& action
);
238 scoped_ptr
<WDTypedResult
> GetAllDefaultWebIntentServicesImpl();
242 //////////////////////////////////////////////////////////////////////////////
246 //////////////////////////////////////////////////////////////////////////////
247 WebDatabase::State
AddIE7LoginImpl(
248 const IE7PasswordInfo
& info
, WebDatabase
* db
);
249 WebDatabase::State
RemoveIE7LoginImpl(
250 const IE7PasswordInfo
& info
, WebDatabase
* db
);
251 scoped_ptr
<WDTypedResult
> GetIE7LoginImpl(
252 const IE7PasswordInfo
& info
, WebDatabase
* db
);
253 #endif // defined(OS_WIN)
255 DISALLOW_COPY_AND_ASSIGN(WebDataService
);
258 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__