Add abhijeet.k@samsung.com to AUTHORS list.
[chromium-blink-merge.git] / components / search_engines / keyword_web_data_service.h
blob44d3fe8366757652fd5b9e579c33c0c02399f4e4
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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_SEARCH_ENGINES_KEYWORD_WEB_DATA_SERVICE_H__
6 #define COMPONENTS_SEARCH_ENGINES_KEYWORD_WEB_DATA_SERVICE_H__
8 #include "base/memory/ref_counted.h"
9 #include "components/search_engines/keyword_table.h"
10 #include "components/search_engines/template_url_id.h"
11 #include "components/webdata/common/web_data_service_base.h"
12 #include "components/webdata/common/web_database.h"
14 namespace base {
15 class MessageLoopProxy;
18 class WDTypedResult;
19 class WebDatabaseService;
20 struct TemplateURLData;
22 struct WDKeywordsResult {
23 WDKeywordsResult();
24 ~WDKeywordsResult();
26 KeywordTable::Keywords keywords;
27 // Identifies the ID of the TemplateURL that is the default search. A value of
28 // 0 indicates there is no default search provider.
29 int64 default_search_provider_id;
30 // Version of the built-in keywords. A value of 0 indicates a first run.
31 int builtin_keyword_version;
34 class WebDataServiceConsumer;
36 class KeywordWebDataService : public WebDataServiceBase {
37 public:
38 // Instantiate this to turn on batch mode on the provided |service|
39 // until the scoper is destroyed. When batch mode is on, calls to any of the
40 // three keyword table modification functions below will result in locally
41 // queueing the operation; on setting this back to false, all the
42 // modifications will be performed at once. This is a performance
43 // optimization; see comments on KeywordTable::PerformOperations().
45 // If multiple scopers are in-scope simultaneously, batch mode will only be
46 // exited when all are destroyed. If |service| is NULL, the object will do
47 // nothing.
48 class BatchModeScoper {
49 public:
50 explicit BatchModeScoper(KeywordWebDataService* service);
51 ~BatchModeScoper();
53 private:
54 KeywordWebDataService* service_;
56 DISALLOW_COPY_AND_ASSIGN(BatchModeScoper);
59 KeywordWebDataService(scoped_refptr<WebDatabaseService> wdbs,
60 scoped_refptr<base::MessageLoopProxy> ui_thread,
61 const ProfileErrorCallback& callback);
63 // As the database processes requests at a later date, all deletion is
64 // done on the background thread.
66 // Many of the keyword related methods do not return a handle. This is because
67 // the caller (TemplateURLService) does not need to know when the request is
68 // done.
70 void AddKeyword(const TemplateURLData& data);
71 void RemoveKeyword(TemplateURLID id);
72 void UpdateKeyword(const TemplateURLData& data);
74 // Fetches the keywords.
75 // On success, consumer is notified with WDResult<KeywordTable::Keywords>.
76 Handle GetKeywords(WebDataServiceConsumer* consumer);
78 // Sets the ID of the default search provider.
79 void SetDefaultSearchProviderID(TemplateURLID id);
81 // Sets the version of the builtin keywords.
82 void SetBuiltinKeywordVersion(int version);
84 protected:
85 ~KeywordWebDataService() override;
87 private:
88 // Called by the BatchModeScoper (see comments there).
89 void AdjustBatchModeLevel(bool entering_batch_mode);
91 //////////////////////////////////////////////////////////////////////////////
93 // The following methods are only invoked on the DB thread.
95 //////////////////////////////////////////////////////////////////////////////
96 WebDatabase::State PerformKeywordOperationsImpl(
97 const KeywordTable::Operations& operations,
98 WebDatabase* db);
99 scoped_ptr<WDTypedResult> GetKeywordsImpl(WebDatabase* db);
100 WebDatabase::State SetDefaultSearchProviderIDImpl(TemplateURLID id,
101 WebDatabase* db);
102 WebDatabase::State SetBuiltinKeywordVersionImpl(int version, WebDatabase* db);
104 size_t batch_mode_level_;
105 KeywordTable::Operations queued_keyword_operations_;
107 DISALLOW_COPY_AND_ASSIGN(KeywordWebDataService);
110 #endif // COMPONENTS_SEARCH_ENGINES_KEYWORD_WEB_DATA_SERVICE_H__