| 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 COMPONENTS_OMNIBOX_BROWSER_SHORTCUTS_BACKEND_H_ | 5 #ifndef COMPONENTS_OMNIBOX_BROWSER_SHORTCUTS_BACKEND_H_ |
| 6 #define COMPONENTS_OMNIBOX_BROWSER_SHORTCUTS_BACKEND_H_ | 6 #define COMPONENTS_OMNIBOX_BROWSER_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/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
| 18 #include "base/scoped_observer.h" | 18 #include "base/scoped_observer.h" |
| 19 #include "base/sequenced_task_runner.h" | 19 #include "base/sequenced_task_runner.h" |
| 20 #include "base/strings/string16.h" | 20 #include "base/strings/string16.h" |
| 21 #include "base/synchronization/lock.h" | 21 #include "base/synchronization/lock.h" |
| 22 #include "base/time/time.h" | 22 #include "base/time/time.h" |
| 23 #include "components/history/core/browser/history_service_observer.h" | 23 #include "components/history/core/browser/history_service_observer.h" |
| 24 #include "components/keyed_service/core/refcounted_keyed_service.h" | 24 #include "components/keyed_service/core/refcounted_keyed_service.h" |
| 25 #include "components/omnibox/browser/autocomplete_match.h" | 25 #include "components/omnibox/browser/autocomplete_match.h" |
| 26 #include "components/omnibox/browser/shortcuts_database.h" | 26 #include "components/omnibox/browser/shortcuts_database.h" |
| 27 #include "components/search_engines/search_terms_data.h" | 27 #include "components/search_engines/search_terms_data.h" |
| 28 #include "url/gurl.h" | 28 #include "url/gurl.h" |
| 29 | 29 |
| 30 class ShortcutsBackend; |
| 30 class TemplateURLService; | 31 class TemplateURLService; |
| 32 struct TestShortcutData; |
| 33 |
| 34 void PopulateShortcutsBackendWithTestData( |
| 35 scoped_refptr<ShortcutsBackend> backend, |
| 36 TestShortcutData* db, |
| 37 size_t db_size); |
| 31 | 38 |
| 32 namespace history { | 39 namespace history { |
| 33 class HistoryService; | 40 class HistoryService; |
| 34 class ShortcutsDatabase; | 41 class ShortcutsDatabase; |
| 35 }; // namespace history | 42 }; // namespace history |
| 36 | 43 |
| 37 // This class manages the shortcut provider backend - access to database on the | 44 // This class manages the shortcut provider backend - access to database on the |
| 38 // db thread, etc. | 45 // db thread, etc. |
| 39 class ShortcutsBackend : public RefcountedKeyedService, | 46 class ShortcutsBackend : public RefcountedKeyedService, |
| 40 public history::HistoryServiceObserver { | 47 public history::HistoryServiceObserver { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 void AddObserver(ShortcutsBackendObserver* obs); | 89 void AddObserver(ShortcutsBackendObserver* obs); |
| 83 void RemoveObserver(ShortcutsBackendObserver* obs); | 90 void RemoveObserver(ShortcutsBackendObserver* obs); |
| 84 | 91 |
| 85 // Looks for an existing shortcut to match.destination_url that starts with | 92 // Looks for an existing shortcut to match.destination_url that starts with |
| 86 // |text|. Updates that shortcut if found, otherwise adds a new shortcut. | 93 // |text|. Updates that shortcut if found, otherwise adds a new shortcut. |
| 87 void AddOrUpdateShortcut(const base::string16& text, | 94 void AddOrUpdateShortcut(const base::string16& text, |
| 88 const AutocompleteMatch& match); | 95 const AutocompleteMatch& match); |
| 89 | 96 |
| 90 private: | 97 private: |
| 91 friend class base::RefCountedThreadSafe<ShortcutsBackend>; | 98 friend class base::RefCountedThreadSafe<ShortcutsBackend>; |
| 92 friend class ShortcutsProviderTest; | |
| 93 friend class ShortcutsBackendTest; | 99 friend class ShortcutsBackendTest; |
| 100 friend void PopulateShortcutsBackendWithTestData( |
| 101 scoped_refptr<ShortcutsBackend> backend, |
| 102 TestShortcutData* db, |
| 103 size_t db_size); |
| 94 FRIEND_TEST_ALL_PREFIXES(ShortcutsBackendTest, EntitySuggestionTest); | 104 FRIEND_TEST_ALL_PREFIXES(ShortcutsBackendTest, EntitySuggestionTest); |
| 95 | 105 |
| 96 enum CurrentState { | 106 enum CurrentState { |
| 97 NOT_INITIALIZED, // Backend created but not initialized. | 107 NOT_INITIALIZED, // Backend created but not initialized. |
| 98 INITIALIZING, // Init() called, but not completed yet. | 108 INITIALIZING, // Init() called, but not completed yet. |
| 99 INITIALIZED, // Initialization completed, all accessors can be safely | 109 INITIALIZED, // Initialization completed, all accessors can be safely |
| 100 // called. | 110 // called. |
| 101 }; | 111 }; |
| 102 | 112 |
| 103 typedef std::map<std::string, ShortcutMap::iterator> GuidMap; | 113 typedef std::map<std::string, ShortcutMap::iterator> GuidMap; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 scoped_refptr<base::SequencedTaskRunner> main_runner_; | 176 scoped_refptr<base::SequencedTaskRunner> main_runner_; |
| 167 scoped_refptr<base::SequencedTaskRunner> db_runner_; | 177 scoped_refptr<base::SequencedTaskRunner> db_runner_; |
| 168 | 178 |
| 169 // For some unit-test only. | 179 // For some unit-test only. |
| 170 bool no_db_access_; | 180 bool no_db_access_; |
| 171 | 181 |
| 172 DISALLOW_COPY_AND_ASSIGN(ShortcutsBackend); | 182 DISALLOW_COPY_AND_ASSIGN(ShortcutsBackend); |
| 173 }; | 183 }; |
| 174 | 184 |
| 175 #endif // COMPONENTS_OMNIBOX_BROWSER_SHORTCUTS_BACKEND_H_ | 185 #endif // COMPONENTS_OMNIBOX_BROWSER_SHORTCUTS_BACKEND_H_ |
| OLD | NEW |