1 // Copyright (c) 2011 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. 4 5 #ifndef CHROME_BROWSER_WEBDATA_KEYWORD_TABLE_H_ 6 #define CHROME_BROWSER_WEBDATA_KEYWORD_TABLE_H_ 7 #pragma once 8 9 #include <vector> 10 11 #include "chrome/browser/webdata/web_database_table.h" 12 #include "chrome/browser/search_engines/template_url_id.h" 13 14 class GURL; 15 class TemplateURL; 16 17 namespace base { 18 class Time; 19 } 20 21 // This class manages the |keywords| MetaTable within the SQLite database 22 // passed to the constructor. It expects the following schema: 23 // 24 // Note: The database stores time in seconds, UTC. 25 // 26 // keywords Most of the columns mirror that of a field in 27 // TemplateURL. See TemplateURL for more details. 28 // id 29 // short_name 30 // keyword 31 // favicon_url 32 // url 33 // show_in_default_list 34 // safe_for_autoreplace 35 // originating_url 36 // date_created This column was added after we allowed keywords. 37 // Keywords created before we started tracking 38 // creation date have a value of 0 for this. 39 // usage_count 40 // input_encodings Semicolon separated list of supported input 41 // encodings, may be empty. 42 // suggest_url 43 // prepopulate_id See TemplateURL::prepopulate_id. 44 // autogenerate_keyword 45 // logo_id See TemplateURL::logo_id 46 // created_by_policy See TemplateURL::created_by_policy. This was added 47 // in version 26. 48 // instant_url See TemplateURL::instant_url. This was added 49 // in version 29. 50 // 51 class KeywordTable : public WebDatabaseTable { 52 public: KeywordTable(sql::Connection * db,sql::MetaTable * meta_table)53 KeywordTable(sql::Connection* db, sql::MetaTable* meta_table) 54 : WebDatabaseTable(db, meta_table) {} 55 virtual ~KeywordTable(); 56 virtual bool Init(); 57 virtual bool IsSyncable(); 58 59 // Adds a new keyword, updating the id field on success. 60 // Returns true if successful. 61 bool AddKeyword(const TemplateURL& url); 62 63 // Removes the specified keyword. 64 // Returns true if successful. 65 bool RemoveKeyword(TemplateURLID id); 66 67 // Loads the keywords into the specified vector. It's up to the caller to 68 // delete the returned objects. 69 // Returns true on success. 70 bool GetKeywords(std::vector<TemplateURL*>* urls); 71 72 // Updates the database values for the specified url. 73 // Returns true on success. 74 bool UpdateKeyword(const TemplateURL& url); 75 76 // ID (TemplateURL->id) of the default search provider. 77 bool SetDefaultSearchProviderID(int64 id); 78 int64 GetDefaulSearchProviderID(); 79 80 // Version of the built-in keywords. 81 bool SetBuitinKeywordVersion(int version); 82 int GetBuitinKeywordVersion(); 83 84 // Table migration functions. 85 bool MigrateToVersion21AutoGenerateKeywordColumn(); 86 bool MigrateToVersion25AddLogoIDColumn(); 87 bool MigrateToVersion26AddCreatedByPolicyColumn(); 88 bool MigrateToVersion28SupportsInstantColumn(); 89 bool MigrateToVersion29InstantUrlToSupportsInstant(); 90 91 private: 92 DISALLOW_COPY_AND_ASSIGN(KeywordTable); 93 }; 94 95 #endif // CHROME_BROWSER_WEBDATA_KEYWORD_TABLE_H_ 96