| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 // Chromium settings and storage represent user-selected preferences and |
| 6 // information and MUST not be extracted, overwritten or modified except | 6 // information and MUST not be extracted, overwritten or modified except |
| 7 // through Chromium defined APIs. | 7 // through Chromium defined APIs. |
| 8 | 8 |
| 9 #ifndef CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__ | 9 #ifndef CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__ |
| 10 #define CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__ | 10 #define CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__ |
| 11 | 11 |
| 12 #include <map> | |
| 13 #include <string> | |
| 14 #include <vector> | 12 #include <vector> |
| 15 | 13 |
| 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" | 14 #include "base/memory/ref_counted.h" |
| 20 #include "base/sequenced_task_runner_helpers.h" | 15 #include "base/sequenced_task_runner_helpers.h" |
| 21 #include "chrome/browser/webdata/keyword_table.h" | |
| 22 #include "components/search_engines/template_url.h" | |
| 23 #include "components/search_engines/template_url_id.h" | |
| 24 #include "components/webdata/common/web_data_results.h" | 16 #include "components/webdata/common/web_data_results.h" |
| 25 #include "components/webdata/common/web_data_service_base.h" | 17 #include "components/webdata/common/web_data_service_base.h" |
| 26 #include "components/webdata/common/web_data_service_consumer.h" | 18 #include "components/webdata/common/web_data_service_consumer.h" |
| 27 #include "components/webdata/common/web_database.h" | 19 #include "components/webdata/common/web_database.h" |
| 28 | 20 |
| 29 struct DefaultWebIntentService; | 21 struct DefaultWebIntentService; |
| 30 class GURL; | 22 class GURL; |
| 31 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
| 32 struct IE7PasswordInfo; | 24 struct IE7PasswordInfo; |
| 33 #endif | 25 #endif |
| (...skipping 22 matching lines...) Expand all Loading... |
| 56 // | 48 // |
| 57 //////////////////////////////////////////////////////////////////////////////// | 49 //////////////////////////////////////////////////////////////////////////////// |
| 58 | 50 |
| 59 | 51 |
| 60 //////////////////////////////////////////////////////////////////////////////// | 52 //////////////////////////////////////////////////////////////////////////////// |
| 61 // | 53 // |
| 62 // WebDataService results | 54 // WebDataService results |
| 63 // | 55 // |
| 64 //////////////////////////////////////////////////////////////////////////////// | 56 //////////////////////////////////////////////////////////////////////////////// |
| 65 | 57 |
| 66 typedef base::Callback<scoped_ptr<WDTypedResult>(void)> ResultTask; | |
| 67 | |
| 68 // Result from GetWebAppImages. | 58 // Result from GetWebAppImages. |
| 69 struct WDAppImagesResult { | 59 struct WDAppImagesResult { |
| 70 WDAppImagesResult(); | 60 WDAppImagesResult(); |
| 71 ~WDAppImagesResult(); | 61 ~WDAppImagesResult(); |
| 72 | 62 |
| 73 // True if SetWebAppHasAllImages(true) was invoked. | 63 // True if SetWebAppHasAllImages(true) was invoked. |
| 74 bool has_all_images; | 64 bool has_all_images; |
| 75 | 65 |
| 76 // The images, may be empty. | 66 // The images, may be empty. |
| 77 std::vector<SkBitmap> images; | 67 std::vector<SkBitmap> images; |
| 78 }; | 68 }; |
| 79 | 69 |
| 80 struct WDKeywordsResult { | |
| 81 WDKeywordsResult(); | |
| 82 ~WDKeywordsResult(); | |
| 83 | |
| 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; | |
| 90 }; | |
| 91 | |
| 92 class WebDataServiceConsumer; | 70 class WebDataServiceConsumer; |
| 93 | 71 |
| 94 class WebDataService : public WebDataServiceBase { | 72 class WebDataService : public WebDataServiceBase { |
| 95 public: | 73 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(). | |
| 102 // | |
| 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(); | |
| 110 | |
| 111 private: | |
| 112 WebDataService* service_; | |
| 113 | |
| 114 DISALLOW_COPY_AND_ASSIGN(KeywordBatchModeScoper); | |
| 115 }; | |
| 116 | |
| 117 // Retrieve a WebDataService for the given context. | 74 // Retrieve a WebDataService for the given context. |
| 118 static scoped_refptr<WebDataService> FromBrowserContext( | 75 static scoped_refptr<WebDataService> FromBrowserContext( |
| 119 content::BrowserContext* context); | 76 content::BrowserContext* context); |
| 120 | 77 |
| 121 WebDataService(scoped_refptr<WebDatabaseService> wdbs, | 78 WebDataService(scoped_refptr<WebDatabaseService> wdbs, |
| 122 const ProfileErrorCallback& callback); | 79 const ProfileErrorCallback& callback); |
| 123 | 80 |
| 124 ////////////////////////////////////////////////////////////////////////////// | 81 ////////////////////////////////////////////////////////////////////////////// |
| 125 // | 82 // |
| 126 // Keywords | |
| 127 // | |
| 128 ////////////////////////////////////////////////////////////////////////////// | |
| 129 | |
| 130 // As the database processes requests at a later date, all deletion is | |
| 131 // done on the background thread. | |
| 132 // | |
| 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. | |
| 136 | |
| 137 void AddKeyword(const TemplateURLData& data); | |
| 138 void RemoveKeyword(TemplateURLID id); | |
| 139 void UpdateKeyword(const TemplateURLData& data); | |
| 140 | |
| 141 // Fetches the keywords. | |
| 142 // On success, consumer is notified with WDResult<KeywordTable::Keywords>. | |
| 143 Handle GetKeywords(WebDataServiceConsumer* consumer); | |
| 144 | |
| 145 // Sets the ID of the default search provider. | |
| 146 void SetDefaultSearchProviderID(TemplateURLID id); | |
| 147 | |
| 148 // Sets the version of the builtin keywords. | |
| 149 void SetBuiltinKeywordVersion(int version); | |
| 150 | |
| 151 ////////////////////////////////////////////////////////////////////////////// | |
| 152 // | |
| 153 // Web Apps | 83 // Web Apps |
| 154 // | 84 // |
| 155 ////////////////////////////////////////////////////////////////////////////// | 85 ////////////////////////////////////////////////////////////////////////////// |
| 156 | 86 |
| 157 // Sets the image for the specified web app. A web app can have any number of | 87 // 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 | 88 // 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. | 89 // web app at the size of the given image it is replaced. |
| 160 void SetWebAppImage(const GURL& app_url, const SkBitmap& image); | 90 void SetWebAppImage(const GURL& app_url, const SkBitmap& image); |
| 161 | 91 |
| 162 // Sets whether all the images have been downloaded for the specified web app. | 92 // Sets whether all the images have been downloaded for the specified web app. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 190 WebDataServiceConsumer* consumer); | 120 WebDataServiceConsumer* consumer); |
| 191 #endif // defined(OS_WIN) | 121 #endif // defined(OS_WIN) |
| 192 | 122 |
| 193 protected: | 123 protected: |
| 194 // For unit tests, passes a null callback. | 124 // For unit tests, passes a null callback. |
| 195 WebDataService(); | 125 WebDataService(); |
| 196 | 126 |
| 197 virtual ~WebDataService(); | 127 virtual ~WebDataService(); |
| 198 | 128 |
| 199 private: | 129 private: |
| 200 // Called by the KeywordBatchModeScoper (see comments there). | |
| 201 void AdjustKeywordBatchModeLevel(bool entering_batch_mode); | |
| 202 | |
| 203 ////////////////////////////////////////////////////////////////////////////// | 130 ////////////////////////////////////////////////////////////////////////////// |
| 204 // | 131 // |
| 205 // The following methods are only invoked on the DB thread. | 132 // The following methods are only invoked on the DB thread. |
| 206 // | 133 // |
| 207 ////////////////////////////////////////////////////////////////////////////// | 134 ////////////////////////////////////////////////////////////////////////////// |
| 208 | 135 |
| 209 ////////////////////////////////////////////////////////////////////////////// | 136 ////////////////////////////////////////////////////////////////////////////// |
| 210 // | 137 // |
| 211 // Keywords. | |
| 212 // | |
| 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); | |
| 221 | |
| 222 ////////////////////////////////////////////////////////////////////////////// | |
| 223 // | |
| 224 // Web Apps. | 138 // Web Apps. |
| 225 // | 139 // |
| 226 ////////////////////////////////////////////////////////////////////////////// | 140 ////////////////////////////////////////////////////////////////////////////// |
| 227 | 141 |
| 228 WebDatabase::State SetWebAppImageImpl(const GURL& app_url, | 142 WebDatabase::State SetWebAppImageImpl(const GURL& app_url, |
| 229 const SkBitmap& image, WebDatabase* db); | 143 const SkBitmap& image, WebDatabase* db); |
| 230 WebDatabase::State SetWebAppHasAllImagesImpl(const GURL& app_url, | 144 WebDatabase::State SetWebAppHasAllImagesImpl(const GURL& app_url, |
| 231 bool has_all_images, WebDatabase* db); | 145 bool has_all_images, WebDatabase* db); |
| 232 WebDatabase::State RemoveWebAppImpl(const GURL& app_url, WebDatabase* db); | 146 WebDatabase::State RemoveWebAppImpl(const GURL& app_url, WebDatabase* db); |
| 233 scoped_ptr<WDTypedResult> GetWebAppImagesImpl( | 147 scoped_ptr<WDTypedResult> GetWebAppImagesImpl( |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 // | 180 // |
| 267 ////////////////////////////////////////////////////////////////////////////// | 181 ////////////////////////////////////////////////////////////////////////////// |
| 268 WebDatabase::State AddIE7LoginImpl( | 182 WebDatabase::State AddIE7LoginImpl( |
| 269 const IE7PasswordInfo& info, WebDatabase* db); | 183 const IE7PasswordInfo& info, WebDatabase* db); |
| 270 WebDatabase::State RemoveIE7LoginImpl( | 184 WebDatabase::State RemoveIE7LoginImpl( |
| 271 const IE7PasswordInfo& info, WebDatabase* db); | 185 const IE7PasswordInfo& info, WebDatabase* db); |
| 272 scoped_ptr<WDTypedResult> GetIE7LoginImpl( | 186 scoped_ptr<WDTypedResult> GetIE7LoginImpl( |
| 273 const IE7PasswordInfo& info, WebDatabase* db); | 187 const IE7PasswordInfo& info, WebDatabase* db); |
| 274 #endif // defined(OS_WIN) | 188 #endif // defined(OS_WIN) |
| 275 | 189 |
| 276 size_t keyword_batch_mode_level_; | |
| 277 KeywordTable::Operations queued_keyword_operations_; | |
| 278 | |
| 279 DISALLOW_COPY_AND_ASSIGN(WebDataService); | 190 DISALLOW_COPY_AND_ASSIGN(WebDataService); |
| 280 }; | 191 }; |
| 281 | 192 |
| 282 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__ | 193 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__ |
| OLD | NEW |