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 TestShortcutInfo; | |
33 | |
34 void PopulateShortcutsBackendWithTestShortcutData( | |
35 scoped_refptr<ShortcutsBackend> backend, | |
36 TestShortcutInfo* 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 ShortcutsProviderExtensionTest; | 99 friend class ShortcutsProviderExtensionTest; |
93 friend class ShortcutsProviderTest; | 100 friend class ShortcutsProviderTest; |
94 friend class ShortcutsBackendTest; | 101 friend class ShortcutsBackendTest; |
102 friend void PopulateShortcutsBackendWithTestShortcutData( | |
103 scoped_refptr<ShortcutsBackend> backend, | |
104 TestShortcutInfo* db, | |
105 size_t db_size); | |
Peter Kasting
2016/02/03 00:31:47
Does this let us unfriend any of the test classes?
rohitrao (ping after 24h)
2016/02/03 14:58:08
Yup, dropped what I could.
| |
95 FRIEND_TEST_ALL_PREFIXES(ShortcutsBackendTest, EntitySuggestionTest); | 106 FRIEND_TEST_ALL_PREFIXES(ShortcutsBackendTest, EntitySuggestionTest); |
96 | 107 |
97 enum CurrentState { | 108 enum CurrentState { |
98 NOT_INITIALIZED, // Backend created but not initialized. | 109 NOT_INITIALIZED, // Backend created but not initialized. |
99 INITIALIZING, // Init() called, but not completed yet. | 110 INITIALIZING, // Init() called, but not completed yet. |
100 INITIALIZED, // Initialization completed, all accessors can be safely | 111 INITIALIZED, // Initialization completed, all accessors can be safely |
101 // called. | 112 // called. |
102 }; | 113 }; |
103 | 114 |
104 typedef std::map<std::string, ShortcutMap::iterator> GuidMap; | 115 typedef std::map<std::string, ShortcutMap::iterator> GuidMap; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 scoped_refptr<base::SequencedTaskRunner> main_runner_; | 178 scoped_refptr<base::SequencedTaskRunner> main_runner_; |
168 scoped_refptr<base::SequencedTaskRunner> db_runner_; | 179 scoped_refptr<base::SequencedTaskRunner> db_runner_; |
169 | 180 |
170 // For some unit-test only. | 181 // For some unit-test only. |
171 bool no_db_access_; | 182 bool no_db_access_; |
172 | 183 |
173 DISALLOW_COPY_AND_ASSIGN(ShortcutsBackend); | 184 DISALLOW_COPY_AND_ASSIGN(ShortcutsBackend); |
174 }; | 185 }; |
175 | 186 |
176 #endif // COMPONENTS_OMNIBOX_BROWSER_SHORTCUTS_BACKEND_H_ | 187 #endif // COMPONENTS_OMNIBOX_BROWSER_SHORTCUTS_BACKEND_H_ |
OLD | NEW |