Index: chrome/browser/history/shortcuts_backend.h |
=================================================================== |
--- chrome/browser/history/shortcuts_backend.h (revision 125990) |
+++ chrome/browser/history/shortcuts_backend.h (working copy) |
@@ -17,8 +17,8 @@ |
#include "base/observer_list.h" |
#include "base/string16.h" |
#include "base/synchronization/lock.h" |
-#include "chrome/browser/autocomplete/shortcuts_provider_shortcut.h" |
-#include "chrome/browser/history/shortcuts_database.h" |
+#include "base/time.h" |
+#include "chrome/browser/autocomplete/autocomplete_match.h" |
#include "content/public/browser/notification_observer.h" |
#include "content/public/browser/notification_registrar.h" |
#include "googleurl/src/gurl.h" |
@@ -27,11 +27,48 @@ |
namespace history { |
+class ShortcutsDatabase; |
+ |
// This class manages the shortcut provider backend - access to database on the |
// db thread, etc. |
class ShortcutsBackend : public base::RefCountedThreadSafe<ShortcutsBackend>, |
public content::NotificationObserver { |
public: |
+ // The following struct encapsulates one previously selected omnibox shortcut. |
+ struct Shortcut { |
+ Shortcut(const std::string& id, |
+ const string16& text, |
+ const GURL& url, |
+ const string16& contents, |
+ const ACMatchClassifications& contents_class, |
+ const string16& description, |
+ const ACMatchClassifications& description_class, |
+ const base::Time& last_access_time, |
+ int number_of_hits); |
+ // Required for STL, we don't use this directly. |
+ Shortcut(); |
+ ~Shortcut(); |
+ |
+ std::string id; // Unique guid for the shortcut. |
+ string16 text; // The user's original input string. |
+ GURL url; // The corresponding destination URL. |
brettw
2012/03/13 22:47:23
Either use 2-spaces or align them all the same.
|
+ |
+ // Contents and description from the original match, along with their |
+ // corresponding markup. We need these in order to correctly mark which |
+ // parts are URLs, dim, etc. However, we strip all MATCH classifications |
+ // from these since we'll mark the matching portions ourselves as we match |
+ // the user's current typing against these Shortcuts. |
+ string16 contents; |
+ ACMatchClassifications contents_class; |
+ string16 description; |
+ ACMatchClassifications description_class; |
+ |
+ base::Time last_access_time; // Last time shortcut was selected. |
+ int number_of_hits; // How many times shortcut was selected. |
+ }; |
+ |
+ typedef std::multimap<string16, ShortcutsBackend::Shortcut> ShortcutMap; |
+ |
// |profile| is necessary for profile notifications only and can be NULL in |
// unit-tests. |db_folder_path| could be an empty path only in unit-tests as |
// well. It means there is no database created, all things are done in memory. |
@@ -59,10 +96,10 @@ |
// All of the public functions *must* be called on UI thread only! |
// Adds the Shortcut to the database. |
- bool AddShortcut(const shortcuts_provider::Shortcut& shortcut); |
+ bool AddShortcut(const ShortcutsBackend::Shortcut& shortcut); |
// Updates timing and selection count for the Shortcut. |
- bool UpdateShortcut(const shortcuts_provider::Shortcut& shortcut); |
+ bool UpdateShortcut(const ShortcutsBackend::Shortcut& shortcut); |
// Deletes the Shortcuts with the id. |
bool DeleteShortcutsWithIds(const std::vector<std::string>& shortcut_ids); |
@@ -73,14 +110,10 @@ |
// Deletes all of the shortcuts. |
bool DeleteAllShortcuts(); |
- const shortcuts_provider::ShortcutMap& shortcuts_map() const { |
+ const ShortcutMap& shortcuts_map() const { |
return shortcuts_map_; |
} |
- const shortcuts_provider::GuidToShortcutsIteratorMap& guid_map() const { |
- return guid_map_; |
- } |
- |
void AddObserver(ShortcutsBackendObserver* obs) { |
observer_list_.AddObserver(obs); |
} |
@@ -90,6 +123,9 @@ |
} |
private: |
+ typedef std::map<std::string, ShortcutMap::iterator> |
+ GuidToShortcutsIteratorMap; |
+ |
// Internal initialization of the back-end. Posted by Init() to the DB thread. |
// On completion posts InitCompleted() back to UI thread. |
void InitInternal(); |
@@ -115,12 +151,12 @@ |
// The |temp_shortcuts_map_| and |temp_guid_map_| used for temporary storage |
// between InitInternal() and InitComplete() to avoid doing a potentially huge |
// copy. |
- scoped_ptr<shortcuts_provider::ShortcutMap> temp_shortcuts_map_; |
- scoped_ptr<shortcuts_provider::GuidToShortcutsIteratorMap> temp_guid_map_; |
+ scoped_ptr<ShortcutMap> temp_shortcuts_map_; |
+ scoped_ptr<GuidToShortcutsIteratorMap> temp_guid_map_; |
- shortcuts_provider::ShortcutMap shortcuts_map_; |
+ ShortcutMap shortcuts_map_; |
// This is a helper map for quick access to a shortcut by guid. |
- shortcuts_provider::GuidToShortcutsIteratorMap guid_map_; |
+ GuidToShortcutsIteratorMap guid_map_; |
content::NotificationRegistrar notification_registrar_; |