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