Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(204)

Side by Side Diff: chrome/browser/history/shortcuts_database.h

Issue 9689085: Clean up ShortcutsProvider and related classes. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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 #ifndef CHROME_BROWSER_HISTORY_SHORTCUTS_DATABASE_H_ 5 #ifndef CHROME_BROWSER_HISTORY_SHORTCUTS_DATABASE_H_
6 #define CHROME_BROWSER_HISTORY_SHORTCUTS_DATABASE_H_ 6 #define CHROME_BROWSER_HISTORY_SHORTCUTS_DATABASE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/file_path.h" 13 #include "base/file_path.h"
14 #include "base/gtest_prod_util.h" 14 #include "base/gtest_prod_util.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/string16.h" 16 #include "base/string16.h"
17 #include "chrome/browser/autocomplete/shortcuts_provider_shortcut.h" 17 #include "chrome/browser/history/shortcuts_backend.h"
18 #include "googleurl/src/gurl.h" 18 #include "googleurl/src/gurl.h"
19 #include "sql/connection.h" 19 #include "sql/connection.h"
20 20
21 namespace history { 21 namespace history {
22 22
23 // This class manages the shortcut provider table within the SQLite database 23 // This class manages the shortcut provider table within the SQLite database
24 // passed to the constructor. It expects the following schema: 24 // passed to the constructor. It expects the following schema:
25 // 25 //
26 // Note: The database stores time in seconds, UTC. 26 // Note: The database stores time in seconds, UTC.
27 // 27 //
28 // omni_box_shortcuts 28 // omni_box_shortcuts
29 // id Unique id of the entry (needed for the sync). 29 // id Unique id of the entry (needed for the sync).
30 // search_text Text that shortcuts was searched with. 30 // search_text Text that shortcuts was searched with.
31 // url The url of the shortcut. 31 // url The url of the shortcut.
32 // contents Contents of the original omni-box entry. 32 // contents Contents of the original omni-box entry.
33 // contents_matches Comma separated matches of the |search_text| in 33 // contents_matches Comma separated matches of the |search_text| in
34 // |contents|, for example "0,0,5,3,9,0". 34 // |contents|, for example "0,0,5,3,9,0".
35 // description Description of the original omni-box entry. 35 // description Description of the original omni-box entry.
36 // description_matches Comma separated matches of the |search_text| in 36 // description_matches Comma separated matches of the |search_text| in
37 // |description|. 37 // |description|.
38 // last_access_time Time the entry was accessed last, stored in seconds, 38 // last_access_time Time the entry was accessed last, stored in seconds,
39 // UTC. 39 // UTC.
40 // number_of_hits Number of times that the entry has been selected. 40 // number_of_hits Number of times that the entry has been selected.
41 class ShortcutsDatabase : public base::RefCountedThreadSafe<ShortcutsDatabase> { 41 class ShortcutsDatabase : public base::RefCountedThreadSafe<ShortcutsDatabase> {
42 public: 42 public:
43 typedef std::map<std::string, ShortcutsBackend::Shortcut> GuidToShortcutMap;
44
43 explicit ShortcutsDatabase(const FilePath& folder_path); 45 explicit ShortcutsDatabase(const FilePath& folder_path);
44 virtual ~ShortcutsDatabase(); 46 virtual ~ShortcutsDatabase();
45 47
46 bool Init(); 48 bool Init();
47 49
48 // Adds the ShortcutsProvider::Shortcut to the database. 50 // Adds the ShortcutsProvider::Shortcut to the database.
49 bool AddShortcut(const shortcuts_provider::Shortcut& shortcut); 51 bool AddShortcut(const ShortcutsBackend::Shortcut& shortcut);
50 52
51 // Updates timing and selection count for the ShortcutsProvider::Shortcut. 53 // Updates timing and selection count for the ShortcutsProvider::Shortcut.
52 bool UpdateShortcut(const shortcuts_provider::Shortcut& shortcut); 54 bool UpdateShortcut(const ShortcutsBackend::Shortcut& shortcut);
53 55
54 // Deletes the ShortcutsProvider::Shortcuts with the id. 56 // Deletes the ShortcutsProvider::Shortcuts with the id.
55 bool DeleteShortcutsWithIds(const std::vector<std::string>& shortcut_ids); 57 bool DeleteShortcutsWithIds(const std::vector<std::string>& shortcut_ids);
56 58
57 // Deletes the ShortcutsProvider::Shortcuts with the url. 59 // Deletes the ShortcutsProvider::Shortcuts with the url.
58 bool DeleteShortcutsWithUrl(const std::string& shortcut_url_spec); 60 bool DeleteShortcutsWithUrl(const std::string& shortcut_url_spec);
59 61
60 // Deletes all of the ShortcutsProvider::Shortcuts. 62 // Deletes all of the ShortcutsProvider::Shortcuts.
61 bool DeleteAllShortcuts(); 63 bool DeleteAllShortcuts();
62 64
63 // Loads all of the shortcuts. 65 // Loads all of the shortcuts.
64 bool LoadShortcuts( 66 bool LoadShortcuts(GuidToShortcutMap* shortcuts);
65 std::map<std::string, shortcuts_provider::Shortcut>* shortcuts);
66 67
67 private: 68 private:
68 // Ensures that the table is present. 69 // Ensures that the table is present.
69 bool EnsureTable(); 70 bool EnsureTable();
70 71
71 friend class ShortcutsDatabaseTest; 72 friend class ShortcutsDatabaseTest;
72 FRIEND_TEST_ALL_PREFIXES(ShortcutsDatabaseTest, AddShortcut); 73 FRIEND_TEST_ALL_PREFIXES(ShortcutsDatabaseTest, AddShortcut);
73 FRIEND_TEST_ALL_PREFIXES(ShortcutsDatabaseTest, UpdateShortcut); 74 FRIEND_TEST_ALL_PREFIXES(ShortcutsDatabaseTest, UpdateShortcut);
74 FRIEND_TEST_ALL_PREFIXES(ShortcutsDatabaseTest, DeleteShortcutsWithIds); 75 FRIEND_TEST_ALL_PREFIXES(ShortcutsDatabaseTest, DeleteShortcutsWithIds);
75 FRIEND_TEST_ALL_PREFIXES(ShortcutsDatabaseTest, DeleteShortcutsWithUrl); 76 FRIEND_TEST_ALL_PREFIXES(ShortcutsDatabaseTest, DeleteShortcutsWithUrl);
76 FRIEND_TEST_ALL_PREFIXES(ShortcutsDatabaseTest, LoadShortcuts); 77 FRIEND_TEST_ALL_PREFIXES(ShortcutsDatabaseTest, LoadShortcuts);
77 78
78 // The sql database. Not valid until Init is called. 79 // The sql database. Not valid until Init is called.
79 sql::Connection db_; 80 sql::Connection db_;
80 FilePath database_path_; 81 FilePath database_path_;
81 82
82 static const FilePath::CharType kShortcutsDatabaseName[]; 83 static const FilePath::CharType kShortcutsDatabaseName[];
83 84
84 DISALLOW_COPY_AND_ASSIGN(ShortcutsDatabase); 85 DISALLOW_COPY_AND_ASSIGN(ShortcutsDatabase);
85 }; 86 };
86 87
87 } // namespace history 88 } // namespace history
88 89
89 #endif // CHROME_BROWSER_HISTORY_SHORTCUTS_DATABASE_H_ 90 #endif // CHROME_BROWSER_HISTORY_SHORTCUTS_DATABASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698