| 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> |
| 11 | 11 |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
| 17 #include "base/scoped_observer.h" |
| 17 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
| 18 #include "base/synchronization/lock.h" | 19 #include "base/synchronization/lock.h" |
| 19 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 20 #include "chrome/browser/history/shortcuts_database.h" | 21 #include "chrome/browser/history/shortcuts_database.h" |
| 22 #include "components/history/core/browser/history_service_observer.h" |
| 21 #include "components/keyed_service/core/refcounted_keyed_service.h" | 23 #include "components/keyed_service/core/refcounted_keyed_service.h" |
| 22 #include "components/omnibox/autocomplete_match.h" | 24 #include "components/omnibox/autocomplete_match.h" |
| 23 #include "content/public/browser/notification_observer.h" | 25 #include "content/public/browser/notification_observer.h" |
| 24 #include "content/public/browser/notification_registrar.h" | 26 #include "content/public/browser/notification_registrar.h" |
| 25 #include "url/gurl.h" | 27 #include "url/gurl.h" |
| 26 | 28 |
| 27 class Profile; | 29 class Profile; |
| 28 | 30 |
| 29 namespace history { | 31 namespace history { |
| 30 class ShortcutsDatabase; | 32 class ShortcutsDatabase; |
| 31 }; // namespace history | 33 }; // namespace history |
| 32 | 34 |
| 33 // This class manages the shortcut provider backend - access to database on the | 35 // This class manages the shortcut provider backend - access to database on the |
| 34 // db thread, etc. | 36 // db thread, etc. |
| 35 class ShortcutsBackend : public RefcountedKeyedService, | 37 class ShortcutsBackend : public RefcountedKeyedService, |
| 36 public content::NotificationObserver { | 38 public content::NotificationObserver, |
| 39 public history::HistoryServiceObserver { |
| 37 public: | 40 public: |
| 38 typedef std::multimap<base::string16, | 41 typedef std::multimap<base::string16, |
| 39 const history::ShortcutsDatabase::Shortcut> ShortcutMap; | 42 const history::ShortcutsDatabase::Shortcut> ShortcutMap; |
| 40 | 43 |
| 41 // |profile| is necessary for profile notifications only and can be NULL in | 44 // |profile| is necessary for profile notifications only and can be NULL in |
| 42 // unit-tests. For unit testing, set |suppress_db| to true to prevent creation | 45 // unit-tests. For unit testing, set |suppress_db| to true to prevent creation |
| 43 // of the database, in which case all operations are performed in memory only. | 46 // of the database, in which case all operations are performed in memory only. |
| 44 ShortcutsBackend(Profile* profile, bool suppress_db); | 47 ShortcutsBackend(Profile* profile, bool suppress_db); |
| 45 | 48 |
| 46 // The interface is guaranteed to be called on the thread AddObserver() | 49 // The interface is guaranteed to be called on the thread AddObserver() |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 bool DeleteShortcutsWithIDs( | 124 bool DeleteShortcutsWithIDs( |
| 122 const history::ShortcutsDatabase::ShortcutIDs& shortcut_ids); | 125 const history::ShortcutsDatabase::ShortcutIDs& shortcut_ids); |
| 123 | 126 |
| 124 // Deletes all shortcuts whose URLs begin with |url|. If |exact_match| is | 127 // Deletes all shortcuts whose URLs begin with |url|. If |exact_match| is |
| 125 // true, only shortcuts from exactly |url| are deleted. | 128 // true, only shortcuts from exactly |url| are deleted. |
| 126 bool DeleteShortcutsWithURL(const GURL& url, bool exact_match); | 129 bool DeleteShortcutsWithURL(const GURL& url, bool exact_match); |
| 127 | 130 |
| 128 // Deletes all of the shortcuts. | 131 // Deletes all of the shortcuts. |
| 129 bool DeleteAllShortcuts(); | 132 bool DeleteAllShortcuts(); |
| 130 | 133 |
| 134 // history::HistoryServiceObserver: |
| 135 void OnURLsDeleted( |
| 136 HistoryService* history_service, |
| 137 const history::URLsDeletedDetails& deleted_details) override; |
| 138 |
| 131 Profile* profile_; | 139 Profile* profile_; |
| 132 CurrentState current_state_; | 140 CurrentState current_state_; |
| 133 ObserverList<ShortcutsBackendObserver> observer_list_; | 141 ObserverList<ShortcutsBackendObserver> observer_list_; |
| 134 scoped_refptr<history::ShortcutsDatabase> db_; | 142 scoped_refptr<history::ShortcutsDatabase> db_; |
| 135 | 143 |
| 136 // The |temp_shortcuts_map_| and |temp_guid_map_| used for temporary storage | 144 // The |temp_shortcuts_map_| and |temp_guid_map_| used for temporary storage |
| 137 // between InitInternal() and InitComplete() to avoid doing a potentially huge | 145 // between InitInternal() and InitComplete() to avoid doing a potentially huge |
| 138 // copy. | 146 // copy. |
| 139 scoped_ptr<ShortcutMap> temp_shortcuts_map_; | 147 scoped_ptr<ShortcutMap> temp_shortcuts_map_; |
| 140 scoped_ptr<GuidMap> temp_guid_map_; | 148 scoped_ptr<GuidMap> temp_guid_map_; |
| 141 | 149 |
| 142 ShortcutMap shortcuts_map_; | 150 ShortcutMap shortcuts_map_; |
| 143 // This is a helper map for quick access to a shortcut by guid. | 151 // This is a helper map for quick access to a shortcut by guid. |
| 144 GuidMap guid_map_; | 152 GuidMap guid_map_; |
| 145 | 153 |
| 146 content::NotificationRegistrar notification_registrar_; | 154 content::NotificationRegistrar notification_registrar_; |
| 147 | 155 |
| 148 // For some unit-test only. | 156 // For some unit-test only. |
| 149 bool no_db_access_; | 157 bool no_db_access_; |
| 150 | 158 |
| 159 ScopedObserver<HistoryService, HistoryServiceObserver> |
| 160 history_service_observer_; |
| 161 |
| 151 DISALLOW_COPY_AND_ASSIGN(ShortcutsBackend); | 162 DISALLOW_COPY_AND_ASSIGN(ShortcutsBackend); |
| 152 }; | 163 }; |
| 153 | 164 |
| 154 #endif // CHROME_BROWSER_AUTOCOMPLETE_SHORTCUTS_BACKEND_H_ | 165 #endif // CHROME_BROWSER_AUTOCOMPLETE_SHORTCUTS_BACKEND_H_ |
| OLD | NEW |