| 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_HISTORY_SHORTCUTS_BACKEND_H_ | 5 #ifndef CHROME_BROWSER_HISTORY_SHORTCUTS_BACKEND_H_ |
| 6 #define CHROME_BROWSER_HISTORY_SHORTCUTS_BACKEND_H_ | 6 #define CHROME_BROWSER_HISTORY_SHORTCUTS_BACKEND_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 base::Time last_access_time; // Last time shortcut was selected. | 66 base::Time last_access_time; // Last time shortcut was selected. |
| 67 int number_of_hits; // How many times shortcut was selected. | 67 int number_of_hits; // How many times shortcut was selected. |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 typedef std::multimap<string16, ShortcutsBackend::Shortcut> ShortcutMap; | 70 typedef std::multimap<string16, ShortcutsBackend::Shortcut> ShortcutMap; |
| 71 | 71 |
| 72 // |profile| is necessary for profile notifications only and can be NULL in | 72 // |profile| is necessary for profile notifications only and can be NULL in |
| 73 // unit-tests. |db_folder_path| could be an empty path only in unit-tests as | 73 // unit-tests. |db_folder_path| could be an empty path only in unit-tests as |
| 74 // well. It means there is no database created, all things are done in memory. | 74 // well. It means there is no database created, all things are done in memory. |
| 75 ShortcutsBackend(const FilePath& db_folder_path, Profile* profile); | 75 ShortcutsBackend(const FilePath& db_folder_path, Profile* profile); |
| 76 virtual ~ShortcutsBackend(); | |
| 77 | 76 |
| 78 // The interface is guaranteed to be called on the thread AddObserver() | 77 // The interface is guaranteed to be called on the thread AddObserver() |
| 79 // was called. | 78 // was called. |
| 80 class ShortcutsBackendObserver { | 79 class ShortcutsBackendObserver { |
| 81 public: | 80 public: |
| 82 // Called after the database is loaded and Init() completed. | 81 // Called after the database is loaded and Init() completed. |
| 83 virtual void OnShortcutsLoaded() = 0; | 82 virtual void OnShortcutsLoaded() = 0; |
| 84 // Called when shortcuts changed (added/updated/removed) in the database. | 83 // Called when shortcuts changed (added/updated/removed) in the database. |
| 85 virtual void OnShortcutsChanged() {} | 84 virtual void OnShortcutsChanged() {} |
| 85 |
| 86 protected: | 86 protected: |
| 87 virtual ~ShortcutsBackendObserver() {} | 87 virtual ~ShortcutsBackendObserver() {} |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 // Asynchronously initializes the ShortcutsBackend, it is safe to call | 90 // Asynchronously initializes the ShortcutsBackend, it is safe to call |
| 91 // multiple times - only the first call will be processed. | 91 // multiple times - only the first call will be processed. |
| 92 bool Init(); | 92 bool Init(); |
| 93 | 93 |
| 94 bool initialized() const { return current_state_ == INITIALIZED; } | 94 bool initialized() const { return current_state_ == INITIALIZED; } |
| 95 | 95 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 116 | 116 |
| 117 void AddObserver(ShortcutsBackendObserver* obs) { | 117 void AddObserver(ShortcutsBackendObserver* obs) { |
| 118 observer_list_.AddObserver(obs); | 118 observer_list_.AddObserver(obs); |
| 119 } | 119 } |
| 120 | 120 |
| 121 void RemoveObserver(ShortcutsBackendObserver* obs) { | 121 void RemoveObserver(ShortcutsBackendObserver* obs) { |
| 122 observer_list_.RemoveObserver(obs); | 122 observer_list_.RemoveObserver(obs); |
| 123 } | 123 } |
| 124 | 124 |
| 125 private: | 125 private: |
| 126 friend class base::RefCountedThreadSafe<ShortcutsBackend>; |
| 127 |
| 126 typedef std::map<std::string, ShortcutMap::iterator> | 128 typedef std::map<std::string, ShortcutMap::iterator> |
| 127 GuidToShortcutsIteratorMap; | 129 GuidToShortcutsIteratorMap; |
| 128 | 130 |
| 131 virtual ~ShortcutsBackend(); |
| 132 |
| 129 // Internal initialization of the back-end. Posted by Init() to the DB thread. | 133 // Internal initialization of the back-end. Posted by Init() to the DB thread. |
| 130 // On completion posts InitCompleted() back to UI thread. | 134 // On completion posts InitCompleted() back to UI thread. |
| 131 void InitInternal(); | 135 void InitInternal(); |
| 132 | 136 |
| 133 // Finishes initialization on UI thread, notifies all observers. | 137 // Finishes initialization on UI thread, notifies all observers. |
| 134 void InitCompleted(); | 138 void InitCompleted(); |
| 135 | 139 |
| 136 // content::NotificationObserver: | 140 // content::NotificationObserver: |
| 137 virtual void Observe(int type, | 141 virtual void Observe(int type, |
| 138 const content::NotificationSource& source, | 142 const content::NotificationSource& source, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 162 | 166 |
| 163 // For some unit-test only. | 167 // For some unit-test only. |
| 164 bool no_db_access_; | 168 bool no_db_access_; |
| 165 | 169 |
| 166 DISALLOW_COPY_AND_ASSIGN(ShortcutsBackend); | 170 DISALLOW_COPY_AND_ASSIGN(ShortcutsBackend); |
| 167 }; | 171 }; |
| 168 | 172 |
| 169 } // namespace history | 173 } // namespace history |
| 170 | 174 |
| 171 #endif // CHROME_BROWSER_HISTORY_SHORTCUTS_BACKEND_H_ | 175 #endif // CHROME_BROWSER_HISTORY_SHORTCUTS_BACKEND_H_ |
| OLD | NEW |