| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // Chromium settings and storage represent user-selected preferences and | 5 #ifndef CHROME_BROWSER_WEBDATA_KEYWORD_WEB_DATA_SERVICE_H__ |
| 6 // information and MUST not be extracted, overwritten or modified except | 6 #define CHROME_BROWSER_WEBDATA_KEYWORD_WEB_DATA_SERVICE_H__ |
| 7 // through Chromium defined APIs. | |
| 8 | 7 |
| 9 #ifndef CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__ | |
| 10 #define CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__ | |
| 11 | |
| 12 #include <map> | |
| 13 #include <string> | |
| 14 #include <vector> | |
| 15 | |
| 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" | 8 #include "base/memory/ref_counted.h" |
| 20 #include "base/sequenced_task_runner_helpers.h" | |
| 21 #include "chrome/browser/webdata/keyword_table.h" | 9 #include "chrome/browser/webdata/keyword_table.h" |
| 22 #include "components/search_engines/template_url.h" | |
| 23 #include "components/search_engines/template_url_id.h" | 10 #include "components/search_engines/template_url_id.h" |
| 24 #include "components/webdata/common/web_data_results.h" | |
| 25 #include "components/webdata/common/web_data_service_base.h" | 11 #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" | 12 #include "components/webdata/common/web_database.h" |
| 28 | 13 |
| 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; | |
| 37 | |
| 38 namespace base { | 14 namespace base { |
| 39 class Thread; | 15 class MessageLoopProxy; |
| 40 } | 16 } |
| 41 | 17 |
| 42 namespace content { | 18 class WDTypedResult; |
| 43 class BrowserContext; | 19 class WebDatabaseService; |
| 44 } | 20 struct TemplateURLData; |
| 45 | |
| 46 namespace webkit_glue { | |
| 47 struct WebIntentServiceData; | |
| 48 } | |
| 49 | |
| 50 //////////////////////////////////////////////////////////////////////////////// | |
| 51 // | |
| 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. | |
| 54 // | |
| 55 // All requests return a handle. The handle can be used to cancel the request. | |
| 56 // | |
| 57 //////////////////////////////////////////////////////////////////////////////// | |
| 58 | |
| 59 | |
| 60 //////////////////////////////////////////////////////////////////////////////// | |
| 61 // | |
| 62 // WebDataService results | |
| 63 // | |
| 64 //////////////////////////////////////////////////////////////////////////////// | |
| 65 | |
| 66 typedef base::Callback<scoped_ptr<WDTypedResult>(void)> ResultTask; | |
| 67 | |
| 68 // Result from GetWebAppImages. | |
| 69 struct WDAppImagesResult { | |
| 70 WDAppImagesResult(); | |
| 71 ~WDAppImagesResult(); | |
| 72 | |
| 73 // True if SetWebAppHasAllImages(true) was invoked. | |
| 74 bool has_all_images; | |
| 75 | |
| 76 // The images, may be empty. | |
| 77 std::vector<SkBitmap> images; | |
| 78 }; | |
| 79 | 21 |
| 80 struct WDKeywordsResult { | 22 struct WDKeywordsResult { |
| 81 WDKeywordsResult(); | 23 WDKeywordsResult(); |
| 82 ~WDKeywordsResult(); | 24 ~WDKeywordsResult(); |
| 83 | 25 |
| 84 KeywordTable::Keywords keywords; | 26 KeywordTable::Keywords keywords; |
| 85 // Identifies the ID of the TemplateURL that is the default search. A value of | 27 // Identifies the ID of the TemplateURL that is the default search. A value of |
| 86 // 0 indicates there is no default search provider. | 28 // 0 indicates there is no default search provider. |
| 87 int64 default_search_provider_id; | 29 int64 default_search_provider_id; |
| 88 // Version of the built-in keywords. A value of 0 indicates a first run. | 30 // Version of the built-in keywords. A value of 0 indicates a first run. |
| 89 int builtin_keyword_version; | 31 int builtin_keyword_version; |
| 90 }; | 32 }; |
| 91 | 33 |
| 92 class WebDataServiceConsumer; | 34 class WebDataServiceConsumer; |
| 93 | 35 |
| 94 class WebDataService : public WebDataServiceBase { | 36 class KeywordWebDataService : public WebDataServiceBase { |
| 95 public: | 37 public: |
| 96 // Instantiate this to turn on keyword batch mode on the provided |service| | 38 // 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 | 39 // 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 | 40 // three keyword table modification functions below will result in locally |
| 99 // queueing the operation; on setting this back to false, all the | 41 // queueing the operation; on setting this back to false, all the |
| 100 // modifications will be performed at once. This is a performance | 42 // modifications will be performed at once. This is a performance |
| 101 // optimization; see comments on KeywordTable::PerformOperations(). | 43 // optimization; see comments on KeywordTable::PerformOperations(). |
| 102 // | 44 // |
| 103 // If multiple scopers are in-scope simultaneously, batch mode will only be | 45 // 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 | 46 // exited when all are destroyed. If |service| is NULL, the object will do |
| 105 // nothing. | 47 // nothing. |
| 106 class KeywordBatchModeScoper { | 48 class KeywordBatchModeScoper { |
| 107 public: | 49 public: |
| 108 explicit KeywordBatchModeScoper(WebDataService* service); | 50 explicit KeywordBatchModeScoper(KeywordWebDataService* service); |
| 109 ~KeywordBatchModeScoper(); | 51 ~KeywordBatchModeScoper(); |
| 110 | 52 |
| 111 private: | 53 private: |
| 112 WebDataService* service_; | 54 KeywordWebDataService* service_; |
| 113 | 55 |
| 114 DISALLOW_COPY_AND_ASSIGN(KeywordBatchModeScoper); | 56 DISALLOW_COPY_AND_ASSIGN(KeywordBatchModeScoper); |
| 115 }; | 57 }; |
| 116 | 58 |
| 117 // Retrieve a WebDataService for the given context. | 59 KeywordWebDataService(scoped_refptr<WebDatabaseService> wdbs, |
| 118 static scoped_refptr<WebDataService> FromBrowserContext( | 60 scoped_refptr<base::MessageLoopProxy> ui_thread, |
| 119 content::BrowserContext* context); | 61 const ProfileErrorCallback& callback); |
| 120 | |
| 121 WebDataService(scoped_refptr<WebDatabaseService> wdbs, | |
| 122 const ProfileErrorCallback& callback); | |
| 123 | |
| 124 ////////////////////////////////////////////////////////////////////////////// | |
| 125 // | |
| 126 // Keywords | |
| 127 // | |
| 128 ////////////////////////////////////////////////////////////////////////////// | |
| 129 | 62 |
| 130 // As the database processes requests at a later date, all deletion is | 63 // As the database processes requests at a later date, all deletion is |
| 131 // done on the background thread. | 64 // done on the background thread. |
| 132 // | 65 // |
| 133 // Many of the keyword related methods do not return a handle. This is because | 66 // 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 | 67 // the caller (TemplateURLService) does not need to know when the request is |
| 135 // done. | 68 // done. |
| 136 | 69 |
| 137 void AddKeyword(const TemplateURLData& data); | 70 void AddKeyword(const TemplateURLData& data); |
| 138 void RemoveKeyword(TemplateURLID id); | 71 void RemoveKeyword(TemplateURLID id); |
| 139 void UpdateKeyword(const TemplateURLData& data); | 72 void UpdateKeyword(const TemplateURLData& data); |
| 140 | 73 |
| 141 // Fetches the keywords. | 74 // Fetches the keywords. |
| 142 // On success, consumer is notified with WDResult<KeywordTable::Keywords>. | 75 // On success, consumer is notified with WDResult<KeywordTable::Keywords>. |
| 143 Handle GetKeywords(WebDataServiceConsumer* consumer); | 76 Handle GetKeywords(WebDataServiceConsumer* consumer); |
| 144 | 77 |
| 145 // Sets the ID of the default search provider. | 78 // Sets the ID of the default search provider. |
| 146 void SetDefaultSearchProviderID(TemplateURLID id); | 79 void SetDefaultSearchProviderID(TemplateURLID id); |
| 147 | 80 |
| 148 // Sets the version of the builtin keywords. | 81 // Sets the version of the builtin keywords. |
| 149 void SetBuiltinKeywordVersion(int version); | 82 void SetBuiltinKeywordVersion(int version); |
| 150 | 83 |
| 151 ////////////////////////////////////////////////////////////////////////////// | |
| 152 // | |
| 153 // Web Apps | |
| 154 // | |
| 155 ////////////////////////////////////////////////////////////////////////////// | |
| 156 | |
| 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); | |
| 161 | |
| 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); | |
| 164 | |
| 165 // Removes all images for the specified web app. | |
| 166 void RemoveWebApp(const GURL& app_url); | |
| 167 | |
| 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); | |
| 171 | |
| 172 #if defined(OS_WIN) | |
| 173 ////////////////////////////////////////////////////////////////////////////// | |
| 174 // | |
| 175 // IE7/8 Password Access (used by PasswordStoreWin - do not use elsewhere) | |
| 176 // | |
| 177 ////////////////////////////////////////////////////////////////////////////// | |
| 178 | |
| 179 // Adds |info| to the list of imported passwords from ie7/ie8. | |
| 180 void AddIE7Login(const IE7PasswordInfo& info); | |
| 181 | |
| 182 // Removes |info| from the list of imported passwords from ie7/ie8. | |
| 183 void RemoveIE7Login(const IE7PasswordInfo& info); | |
| 184 | |
| 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) | |
| 192 | |
| 193 protected: | 84 protected: |
| 194 // For unit tests, passes a null callback. | 85 virtual ~KeywordWebDataService(); |
| 195 WebDataService(); | |
| 196 | |
| 197 virtual ~WebDataService(); | |
| 198 | 86 |
| 199 private: | 87 private: |
| 200 // Called by the KeywordBatchModeScoper (see comments there). | 88 // Called by the KeywordBatchModeScoper (see comments there). |
| 201 void AdjustKeywordBatchModeLevel(bool entering_batch_mode); | 89 void AdjustKeywordBatchModeLevel(bool entering_batch_mode); |
| 202 | 90 |
| 203 ////////////////////////////////////////////////////////////////////////////// | 91 ////////////////////////////////////////////////////////////////////////////// |
| 204 // | 92 // |
| 205 // The following methods are only invoked on the DB thread. | 93 // The following methods are only invoked on the DB thread. |
| 206 // | 94 // |
| 207 ////////////////////////////////////////////////////////////////////////////// | 95 ////////////////////////////////////////////////////////////////////////////// |
| 208 | |
| 209 ////////////////////////////////////////////////////////////////////////////// | |
| 210 // | |
| 211 // Keywords. | |
| 212 // | |
| 213 ////////////////////////////////////////////////////////////////////////////// | |
| 214 WebDatabase::State PerformKeywordOperationsImpl( | 96 WebDatabase::State PerformKeywordOperationsImpl( |
| 215 const KeywordTable::Operations& operations, | 97 const KeywordTable::Operations& operations, |
| 216 WebDatabase* db); | 98 WebDatabase* db); |
| 217 scoped_ptr<WDTypedResult> GetKeywordsImpl(WebDatabase* db); | 99 scoped_ptr<WDTypedResult> GetKeywordsImpl(WebDatabase* db); |
| 218 WebDatabase::State SetDefaultSearchProviderIDImpl(TemplateURLID id, | 100 WebDatabase::State SetDefaultSearchProviderIDImpl(TemplateURLID id, |
| 219 WebDatabase* db); | 101 WebDatabase* db); |
| 220 WebDatabase::State SetBuiltinKeywordVersionImpl(int version, WebDatabase* db); | 102 WebDatabase::State SetBuiltinKeywordVersionImpl(int version, WebDatabase* db); |
| 221 | 103 |
| 222 ////////////////////////////////////////////////////////////////////////////// | |
| 223 // | |
| 224 // Web Apps. | |
| 225 // | |
| 226 ////////////////////////////////////////////////////////////////////////////// | |
| 227 | |
| 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); | |
| 235 | |
| 236 #if defined(ENABLE_WEB_INTENTS) | |
| 237 ////////////////////////////////////////////////////////////////////////////// | |
| 238 // | |
| 239 // Web Intents. | |
| 240 // | |
| 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 | |
| 261 | |
| 262 #if defined(OS_WIN) | |
| 263 ////////////////////////////////////////////////////////////////////////////// | |
| 264 // | |
| 265 // Password manager. | |
| 266 // | |
| 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) | |
| 275 | |
| 276 size_t keyword_batch_mode_level_; | 104 size_t keyword_batch_mode_level_; |
| 277 KeywordTable::Operations queued_keyword_operations_; | 105 KeywordTable::Operations queued_keyword_operations_; |
| 278 | 106 |
| 279 DISALLOW_COPY_AND_ASSIGN(WebDataService); | 107 DISALLOW_COPY_AND_ASSIGN(KeywordWebDataService); |
| 280 }; | 108 }; |
| 281 | 109 |
| 282 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__ | 110 #endif // CHROME_BROWSER_WEBDATA_KEYWORD_WEB_DATA_SERVICE_H__ |
| OLD | NEW |