| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_BOOKMARKS_BOOKMARK_STORAGE_H_ | 5 #ifndef CHROME_BROWSER_BOOKMARKS_BOOKMARK_STORAGE_H_ |
| 6 #define CHROME_BROWSER_BOOKMARKS_BOOKMARK_STORAGE_H_ | 6 #define CHROME_BROWSER_BOOKMARKS_BOOKMARK_STORAGE_H_ |
| 7 | 7 |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/ref_counted.h" | 9 #include "base/ref_counted.h" |
| 10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
| 11 #include "chrome/browser/bookmarks/bookmark_index.h" | 11 #include "chrome/browser/bookmarks/bookmark_index.h" |
| 12 #include "chrome/common/important_file_writer.h" | 12 #include "chrome/common/important_file_writer.h" |
| 13 #include "chrome/common/notification_observer.h" | 13 #include "chrome/common/notification_observer.h" |
| 14 #include "chrome/common/notification_registrar.h" | 14 #include "chrome/common/notification_registrar.h" |
| 15 | 15 |
| 16 class BookmarkModel; | 16 class BookmarkModel; |
| 17 class BookmarkNode; | 17 class BookmarkNode; |
| 18 class Profile; | 18 class Profile; |
| 19 class Task; | 19 class Task; |
| 20 class Value; | 20 class Value; |
| 21 | 21 |
| 22 namespace base { | |
| 23 class Thread; | |
| 24 } | |
| 25 | |
| 26 // BookmarkStorage handles reading/write the bookmark bar model. The | 22 // BookmarkStorage handles reading/write the bookmark bar model. The |
| 27 // BookmarkModel uses the BookmarkStorage to load bookmarks from disk, as well | 23 // BookmarkModel uses the BookmarkStorage to load bookmarks from disk, as well |
| 28 // as notifying the BookmarkStorage every time the model changes. | 24 // as notifying the BookmarkStorage every time the model changes. |
| 29 // | 25 // |
| 30 // Internally BookmarkStorage uses BookmarkCodec to do the actual read/write. | 26 // Internally BookmarkStorage uses BookmarkCodec to do the actual read/write. |
| 31 class BookmarkStorage : public NotificationObserver, | 27 class BookmarkStorage : public NotificationObserver, |
| 32 public ImportantFileWriter::DataSerializer, | 28 public ImportantFileWriter::DataSerializer, |
| 33 public base::RefCountedThreadSafe<BookmarkStorage> { | 29 public base::RefCountedThreadSafe<BookmarkStorage> { |
| 34 public: | 30 public: |
| 35 // LoadDetails is used by BookmarkStorage when loading bookmarks. | 31 // LoadDetails is used by BookmarkStorage when loading bookmarks. |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 void FinishHistoryMigration(); | 132 void FinishHistoryMigration(); |
| 137 | 133 |
| 138 // NotificationObserver | 134 // NotificationObserver |
| 139 void Observe(NotificationType type, const NotificationSource& source, | 135 void Observe(NotificationType type, const NotificationSource& source, |
| 140 const NotificationDetails& details); | 136 const NotificationDetails& details); |
| 141 | 137 |
| 142 // Serializes the data and schedules save using ImportantFileWriter. | 138 // Serializes the data and schedules save using ImportantFileWriter. |
| 143 // Returns true on successful serialization. | 139 // Returns true on successful serialization. |
| 144 bool SaveNow(); | 140 bool SaveNow(); |
| 145 | 141 |
| 146 // Runs task on backend thread (or on current thread if backend thread | |
| 147 // is NULL). Takes ownership of |task|. | |
| 148 void RunTaskOnBackendThread(Task* task) const; | |
| 149 | |
| 150 // Returns the thread the backend is run on. | |
| 151 const base::Thread* backend_thread() const { return backend_thread_; } | |
| 152 | |
| 153 // Keep the pointer to profile, we may need it for migration from history. | 142 // Keep the pointer to profile, we may need it for migration from history. |
| 154 Profile* profile_; | 143 Profile* profile_; |
| 155 | 144 |
| 156 // The model. The model is NULL once BookmarkModelDeleted has been invoked. | 145 // The model. The model is NULL once BookmarkModelDeleted has been invoked. |
| 157 BookmarkModel* model_; | 146 BookmarkModel* model_; |
| 158 | 147 |
| 159 // Thread read/writing is run on. This comes from the profile, and is null | |
| 160 // during testing. | |
| 161 const base::Thread* backend_thread_; | |
| 162 | |
| 163 // Helper to write bookmark data safely. | 148 // Helper to write bookmark data safely. |
| 164 ImportantFileWriter writer_; | 149 ImportantFileWriter writer_; |
| 165 | 150 |
| 166 // Helper to ensure that we unregister from notifications on destruction. | 151 // Helper to ensure that we unregister from notifications on destruction. |
| 167 NotificationRegistrar notification_registrar_; | 152 NotificationRegistrar notification_registrar_; |
| 168 | 153 |
| 169 // Path to temporary file created during migrating bookmarks from history. | 154 // Path to temporary file created during migrating bookmarks from history. |
| 170 const FilePath tmp_history_path_; | 155 const FilePath tmp_history_path_; |
| 171 | 156 |
| 172 // See class description of LoadDetails for details on this. | 157 // See class description of LoadDetails for details on this. |
| 173 scoped_ptr<LoadDetails> details_; | 158 scoped_ptr<LoadDetails> details_; |
| 174 | 159 |
| 175 DISALLOW_COPY_AND_ASSIGN(BookmarkStorage); | 160 DISALLOW_COPY_AND_ASSIGN(BookmarkStorage); |
| 176 }; | 161 }; |
| 177 | 162 |
| 178 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_STORAGE_H_ | 163 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_STORAGE_H_ |
| OLD | NEW |