Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / webdata / web_data_service.h
blobc19e22e65a96d97dd3e5020c2d38f4f1430f6200
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__
12 #include <map>
13 #include <string>
14 #include <vector>
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;
30 class GURL;
31 #if defined(OS_WIN)
32 struct IE7PasswordInfo;
33 #endif
34 class Profile;
35 class SkBitmap;
36 class WebDatabaseService;
38 namespace base {
39 class Thread;
42 namespace content {
43 class BrowserContext;
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 {
70 WDAppImagesResult();
71 ~WDAppImagesResult();
73 // True if SetWebAppHasAllImages(true) was invoked.
74 bool has_all_images;
76 // The images, may be empty.
77 std::vector<SkBitmap> images;
80 struct WDKeywordsResult {
81 WDKeywordsResult();
82 ~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 {
95 public:
96 // Instantiate this to turn on keyword batch mode on the provided |service|
97 // until the scoper is destroyed. When batch mode is on, calls to any of the
98 // three keyword table modification functions below will result in locally
99 // queueing the operation; on setting this back to false, all the
100 // modifications will be performed at once. This is a performance
101 // optimization; see comments on KeywordTable::PerformOperations().
103 // If multiple scopers are in-scope simultaneously, batch mode will only be
104 // exited when all are destroyed. If |service| is NULL, the object will do
105 // nothing.
106 class KeywordBatchModeScoper {
107 public:
108 explicit KeywordBatchModeScoper(WebDataService* service);
109 ~KeywordBatchModeScoper();
111 private:
112 WebDataService* service_;
114 DISALLOW_COPY_AND_ASSIGN(KeywordBatchModeScoper);
117 // Retrieve a WebDataService for the given context.
118 static scoped_refptr<WebDataService> FromBrowserContext(
119 content::BrowserContext* context);
121 WebDataService(scoped_refptr<WebDatabaseService> wdbs,
122 const ProfileErrorCallback& callback);
124 //////////////////////////////////////////////////////////////////////////////
126 // Keywords
128 //////////////////////////////////////////////////////////////////////////////
130 // As the database processes requests at a later date, all deletion is
131 // done on the background thread.
133 // Many of the keyword related methods do not return a handle. This is because
134 // the caller (TemplateURLService) does not need to know when the request is
135 // done.
137 void AddKeyword(const TemplateURLData& data);
138 void RemoveKeyword(TemplateURLID id);
139 void UpdateKeyword(const TemplateURLData& data);
141 // Fetches the keywords.
142 // On success, consumer is notified with WDResult<KeywordTable::Keywords>.
143 Handle GetKeywords(WebDataServiceConsumer* consumer);
145 // Sets the ID of the default search provider.
146 void SetDefaultSearchProviderID(TemplateURLID id);
148 // Sets the version of the builtin keywords.
149 void SetBuiltinKeywordVersion(int version);
151 //////////////////////////////////////////////////////////////////////////////
153 // Web Apps
155 //////////////////////////////////////////////////////////////////////////////
157 // Sets the image for the specified web app. A web app can have any number of
158 // images, but only one at a particular size. If there was an image for the
159 // web app at the size of the given image it is replaced.
160 void SetWebAppImage(const GURL& app_url, const SkBitmap& image);
162 // Sets whether all the images have been downloaded for the specified web app.
163 void SetWebAppHasAllImages(const GURL& app_url, bool has_all_images);
165 // Removes all images for the specified web app.
166 void RemoveWebApp(const GURL& app_url);
168 // Fetches the images and whether all images have been downloaded for the
169 // specified web app.
170 Handle GetWebAppImages(const GURL& app_url, WebDataServiceConsumer* consumer);
172 #if defined(OS_WIN)
173 //////////////////////////////////////////////////////////////////////////////
175 // IE7/8 Password Access (used by PasswordStoreWin - do not use elsewhere)
177 //////////////////////////////////////////////////////////////////////////////
179 // Adds |info| to the list of imported passwords from ie7/ie8.
180 void AddIE7Login(const IE7PasswordInfo& info);
182 // Removes |info| from the list of imported passwords from ie7/ie8.
183 void RemoveIE7Login(const IE7PasswordInfo& info);
185 // Get the login matching the information in |info|. |consumer| will be
186 // notified when the request is done. The result is of type
187 // WDResult<IE7PasswordInfo>.
188 // If there is no match, the fields of the IE7PasswordInfo will be empty.
189 Handle GetIE7Login(const IE7PasswordInfo& info,
190 WebDataServiceConsumer* consumer);
191 #endif // defined(OS_WIN)
193 protected:
194 // For unit tests, passes a null callback.
195 WebDataService();
197 virtual ~WebDataService();
199 private:
200 // Called by the KeywordBatchModeScoper (see comments there).
201 void AdjustKeywordBatchModeLevel(bool entering_batch_mode);
203 //////////////////////////////////////////////////////////////////////////////
205 // The following methods are only invoked on the DB thread.
207 //////////////////////////////////////////////////////////////////////////////
209 //////////////////////////////////////////////////////////////////////////////
211 // Keywords.
213 //////////////////////////////////////////////////////////////////////////////
214 WebDatabase::State PerformKeywordOperationsImpl(
215 const KeywordTable::Operations& operations,
216 WebDatabase* db);
217 scoped_ptr<WDTypedResult> GetKeywordsImpl(WebDatabase* db);
218 WebDatabase::State SetDefaultSearchProviderIDImpl(TemplateURLID id,
219 WebDatabase* db);
220 WebDatabase::State SetBuiltinKeywordVersionImpl(int version, WebDatabase* db);
222 //////////////////////////////////////////////////////////////////////////////
224 // Web Apps.
226 //////////////////////////////////////////////////////////////////////////////
228 WebDatabase::State SetWebAppImageImpl(const GURL& app_url,
229 const SkBitmap& image, WebDatabase* db);
230 WebDatabase::State SetWebAppHasAllImagesImpl(const GURL& app_url,
231 bool has_all_images, WebDatabase* db);
232 WebDatabase::State RemoveWebAppImpl(const GURL& app_url, WebDatabase* db);
233 scoped_ptr<WDTypedResult> GetWebAppImagesImpl(
234 const GURL& app_url, WebDatabase* db);
236 #if defined(ENABLE_WEB_INTENTS)
237 //////////////////////////////////////////////////////////////////////////////
239 // Web Intents.
241 //////////////////////////////////////////////////////////////////////////////
242 WebDatabase::State AddWebIntentServiceImpl(
243 const webkit_glue::WebIntentServiceData& service);
244 WebDatabase::State RemoveWebIntentServiceImpl(
245 const webkit_glue::WebIntentServiceData& service);
246 scoped_ptr<WDTypedResult> GetWebIntentServicesImpl(
247 const base::string16& action);
248 scoped_ptr<WDTypedResult> GetWebIntentServicesForURLImpl(
249 const base::string16& service_url);
250 scoped_ptr<WDTypedResult> GetAllWebIntentServicesImpl();
251 WebDatabase::State AddDefaultWebIntentServiceImpl(
252 const DefaultWebIntentService& service);
253 WebDatabase::State RemoveDefaultWebIntentServiceImpl(
254 const DefaultWebIntentService& service);
255 WebDatabase::State RemoveWebIntentServiceDefaultsImpl(
256 const GURL& service_url);
257 scoped_ptr<WDTypedResult> GetDefaultWebIntentServicesForActionImpl(
258 const base::string16& action);
259 scoped_ptr<WDTypedResult> GetAllDefaultWebIntentServicesImpl();
260 #endif
262 #if defined(OS_WIN)
263 //////////////////////////////////////////////////////////////////////////////
265 // Password manager.
267 //////////////////////////////////////////////////////////////////////////////
268 WebDatabase::State AddIE7LoginImpl(
269 const IE7PasswordInfo& info, WebDatabase* db);
270 WebDatabase::State RemoveIE7LoginImpl(
271 const IE7PasswordInfo& info, WebDatabase* db);
272 scoped_ptr<WDTypedResult> GetIE7LoginImpl(
273 const IE7PasswordInfo& info, WebDatabase* db);
274 #endif // defined(OS_WIN)
276 size_t keyword_batch_mode_level_;
277 KeywordTable::Operations queued_keyword_operations_;
279 DISALLOW_COPY_AND_ASSIGN(WebDataService);
282 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__