| 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 #ifndef CHROME_BROWSER_AUTOCOMPLETE_SHORTCUTS_BACKEND_H_ | 5 #ifndef CHROME_BROWSER_AUTOCOMPLETE_SHORTCUTS_BACKEND_H_ |
| 6 #define CHROME_BROWSER_AUTOCOMPLETE_SHORTCUTS_BACKEND_H_ | 6 #define CHROME_BROWSER_AUTOCOMPLETE_SHORTCUTS_BACKEND_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 | 73 |
| 74 // Looks for an existing shortcut to match.destination_url that starts with | 74 // Looks for an existing shortcut to match.destination_url that starts with |
| 75 // |text|. Updates that shortcut if found, otherwise adds a new shortcut. | 75 // |text|. Updates that shortcut if found, otherwise adds a new shortcut. |
| 76 void AddOrUpdateShortcut(const base::string16& text, | 76 void AddOrUpdateShortcut(const base::string16& text, |
| 77 const AutocompleteMatch& match); | 77 const AutocompleteMatch& match); |
| 78 | 78 |
| 79 private: | 79 private: |
| 80 friend class base::RefCountedThreadSafe<ShortcutsBackend>; | 80 friend class base::RefCountedThreadSafe<ShortcutsBackend>; |
| 81 friend class ShortcutsProviderTest; | 81 friend class ShortcutsProviderTest; |
| 82 friend class ShortcutsBackendTest; | 82 friend class ShortcutsBackendTest; |
| 83 FRIEND_TEST_ALL_PREFIXES(ShortcutsBackendTest, EntitySuggestionTest); | |
| 84 | 83 |
| 85 enum CurrentState { | 84 enum CurrentState { |
| 86 NOT_INITIALIZED, // Backend created but not initialized. | 85 NOT_INITIALIZED, // Backend created but not initialized. |
| 87 INITIALIZING, // Init() called, but not completed yet. | 86 INITIALIZING, // Init() called, but not completed yet. |
| 88 INITIALIZED, // Initialization completed, all accessors can be safely | 87 INITIALIZED, // Initialization completed, all accessors can be safely |
| 89 // called. | 88 // called. |
| 90 }; | 89 }; |
| 91 | 90 |
| 92 typedef std::map<std::string, ShortcutMap::iterator> GuidMap; | 91 typedef std::map<std::string, ShortcutMap::iterator> GuidMap; |
| 93 | 92 |
| 94 virtual ~ShortcutsBackend(); | 93 virtual ~ShortcutsBackend(); |
| 95 | 94 |
| 96 static history::ShortcutsDatabase::Shortcut::MatchCore MatchToMatchCore( | 95 static history::ShortcutsDatabase::Shortcut::MatchCore MatchToMatchCore( |
| 97 const AutocompleteMatch& match, Profile* profile); | 96 const AutocompleteMatch& match); |
| 98 | 97 |
| 99 // RefcountedBrowserContextKeyedService: | 98 // RefcountedBrowserContextKeyedService: |
| 100 virtual void ShutdownOnUIThread() OVERRIDE; | 99 virtual void ShutdownOnUIThread() OVERRIDE; |
| 101 | 100 |
| 102 // content::NotificationObserver: | 101 // content::NotificationObserver: |
| 103 virtual void Observe(int type, | 102 virtual void Observe(int type, |
| 104 const content::NotificationSource& source, | 103 const content::NotificationSource& source, |
| 105 const content::NotificationDetails& details) OVERRIDE; | 104 const content::NotificationDetails& details) OVERRIDE; |
| 106 | 105 |
| 107 // Internal initialization of the back-end. Posted by Init() to the DB thread. | 106 // Internal initialization of the back-end. Posted by Init() to the DB thread. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 121 bool DeleteShortcutsWithIDs( | 120 bool DeleteShortcutsWithIDs( |
| 122 const history::ShortcutsDatabase::ShortcutIDs& shortcut_ids); | 121 const history::ShortcutsDatabase::ShortcutIDs& shortcut_ids); |
| 123 | 122 |
| 124 // Deletes all shortcuts whose URLs begin with |url|. If |exact_match| is | 123 // Deletes all shortcuts whose URLs begin with |url|. If |exact_match| is |
| 125 // true, only shortcuts from exactly |url| are deleted. | 124 // true, only shortcuts from exactly |url| are deleted. |
| 126 bool DeleteShortcutsWithURL(const GURL& url, bool exact_match); | 125 bool DeleteShortcutsWithURL(const GURL& url, bool exact_match); |
| 127 | 126 |
| 128 // Deletes all of the shortcuts. | 127 // Deletes all of the shortcuts. |
| 129 bool DeleteAllShortcuts(); | 128 bool DeleteAllShortcuts(); |
| 130 | 129 |
| 131 Profile* profile_; | |
| 132 CurrentState current_state_; | 130 CurrentState current_state_; |
| 133 ObserverList<ShortcutsBackendObserver> observer_list_; | 131 ObserverList<ShortcutsBackendObserver> observer_list_; |
| 134 scoped_refptr<history::ShortcutsDatabase> db_; | 132 scoped_refptr<history::ShortcutsDatabase> db_; |
| 135 | 133 |
| 136 // The |temp_shortcuts_map_| and |temp_guid_map_| used for temporary storage | 134 // The |temp_shortcuts_map_| and |temp_guid_map_| used for temporary storage |
| 137 // between InitInternal() and InitComplete() to avoid doing a potentially huge | 135 // between InitInternal() and InitComplete() to avoid doing a potentially huge |
| 138 // copy. | 136 // copy. |
| 139 scoped_ptr<ShortcutMap> temp_shortcuts_map_; | 137 scoped_ptr<ShortcutMap> temp_shortcuts_map_; |
| 140 scoped_ptr<GuidMap> temp_guid_map_; | 138 scoped_ptr<GuidMap> temp_guid_map_; |
| 141 | 139 |
| 142 ShortcutMap shortcuts_map_; | 140 ShortcutMap shortcuts_map_; |
| 143 // This is a helper map for quick access to a shortcut by guid. | 141 // This is a helper map for quick access to a shortcut by guid. |
| 144 GuidMap guid_map_; | 142 GuidMap guid_map_; |
| 145 | 143 |
| 146 content::NotificationRegistrar notification_registrar_; | 144 content::NotificationRegistrar notification_registrar_; |
| 147 | 145 |
| 148 // For some unit-test only. | 146 // For some unit-test only. |
| 149 bool no_db_access_; | 147 bool no_db_access_; |
| 150 | 148 |
| 151 DISALLOW_COPY_AND_ASSIGN(ShortcutsBackend); | 149 DISALLOW_COPY_AND_ASSIGN(ShortcutsBackend); |
| 152 }; | 150 }; |
| 153 | 151 |
| 154 #endif // CHROME_BROWSER_AUTOCOMPLETE_SHORTCUTS_BACKEND_H_ | 152 #endif // CHROME_BROWSER_AUTOCOMPLETE_SHORTCUTS_BACKEND_H_ |
| OLD | NEW |