| 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/ref_counted.h" | 8 #include "base/ref_counted.h" |
| 9 #include "base/task.h" | 9 #include "base/task.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 11 | 11 |
| 12 class BookmarkBarModel; | 12 class BookmarkModel; |
| 13 class Profile; | 13 class Profile; |
| 14 class Value; | 14 class Value; |
| 15 | 15 |
| 16 // BookmarkStorage handles reading/write the bookmark bar model. The | 16 // BookmarkStorage handles reading/write the bookmark bar model. The |
| 17 // BookmarkBarModel uses the BookmarkStorage to load bookmarks from | 17 // BookmarkModel uses the BookmarkStorage to load bookmarks from disk, as well |
| 18 // disk, as well as notifying the BookmarkStorage every time the model | 18 // as notifying the BookmarkStorage every time the model changes. |
| 19 // changes. | |
| 20 // | 19 // |
| 21 // Internally BookmarkStorage uses BookmarkCodec to do the actual read/write. | 20 // Internally BookmarkStorage uses BookmarkCodec to do the actual read/write. |
| 22 | 21 |
| 23 class BookmarkStorage : public base::RefCountedThreadSafe<BookmarkStorage> { | 22 class BookmarkStorage : public base::RefCountedThreadSafe<BookmarkStorage> { |
| 24 friend class BookmarkStorageBackend; | 23 friend class BookmarkStorageBackend; |
| 25 | 24 |
| 26 public: | 25 public: |
| 27 // Creates a BookmarkStorage for the specified model | 26 // Creates a BookmarkStorage for the specified model |
| 28 BookmarkStorage(Profile* profile, BookmarkBarModel* model); | 27 BookmarkStorage(Profile* profile, BookmarkModel* model); |
| 29 | 28 |
| 30 // Loads the bookmarks into the model, notifying the model when done. If | 29 // Loads the bookmarks into the model, notifying the model when done. If |
| 31 // load_from_history is true, the bookmarks are loaded from the file written | 30 // load_from_history is true, the bookmarks are loaded from the file written |
| 32 // by history (StarredURLDatabase). | 31 // by history (StarredURLDatabase). |
| 33 void LoadBookmarks(bool load_from_history); | 32 void LoadBookmarks(bool load_from_history); |
| 34 | 33 |
| 35 // Schedules saving the bookmark bar model to disk. | 34 // Schedules saving the bookmark bar model to disk. |
| 36 void ScheduleSave(); | 35 void ScheduleSave(); |
| 37 | 36 |
| 38 // Notification the bookmark bar model is going to be deleted. If there is | 37 // Notification the bookmark bar model is going to be deleted. If there is |
| 39 // a pending save, it is saved immediately. | 38 // a pending save, it is saved immediately. |
| 40 void BookmarkModelDeleted(); | 39 void BookmarkModelDeleted(); |
| 41 | 40 |
| 42 private: | 41 private: |
| 43 // Callback from backend with the results of the bookmark file. | 42 // Callback from backend with the results of the bookmark file. |
| 44 void LoadedBookmarks(Value* root_value, | 43 void LoadedBookmarks(Value* root_value, |
| 45 bool bookmark_file_exists, | 44 bool bookmark_file_exists, |
| 46 bool loaded_from_history); | 45 bool loaded_from_history); |
| 47 | 46 |
| 48 // Schedules a save on the backend thread. | 47 // Schedules a save on the backend thread. |
| 49 void SaveNow(); | 48 void SaveNow(); |
| 50 | 49 |
| 51 // Returns the thread the backend is run on. | 50 // Returns the thread the backend is run on. |
| 52 base::Thread* backend_thread() const { return backend_thread_; } | 51 base::Thread* backend_thread() const { return backend_thread_; } |
| 53 | 52 |
| 54 // The model. The model is NULL once BookmarkModelDeleted has been invoked. | 53 // The model. The model is NULL once BookmarkModelDeleted has been invoked. |
| 55 BookmarkBarModel* model_; | 54 BookmarkModel* model_; |
| 56 | 55 |
| 57 // Used to delay saves. | 56 // Used to delay saves. |
| 58 ScopedRunnableMethodFactory<BookmarkStorage> save_factory_; | 57 ScopedRunnableMethodFactory<BookmarkStorage> save_factory_; |
| 59 | 58 |
| 60 // The backend handles actual reading/writing to disk. | 59 // The backend handles actual reading/writing to disk. |
| 61 scoped_refptr<BookmarkStorageBackend> backend_; | 60 scoped_refptr<BookmarkStorageBackend> backend_; |
| 62 | 61 |
| 63 // Thread read/writing is run on. This comes from the profile, and is null | 62 // Thread read/writing is run on. This comes from the profile, and is null |
| 64 // during testing. | 63 // during testing. |
| 65 base::Thread* backend_thread_; | 64 base::Thread* backend_thread_; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 88 // Path we read/write to. | 87 // Path we read/write to. |
| 89 const std::wstring path_; | 88 const std::wstring path_; |
| 90 | 89 |
| 91 // Path bookmarks are read from if asked to load from history file. | 90 // Path bookmarks are read from if asked to load from history file. |
| 92 const std::wstring tmp_history_path_; | 91 const std::wstring tmp_history_path_; |
| 93 | 92 |
| 94 DISALLOW_COPY_AND_ASSIGN(BookmarkStorageBackend); | 93 DISALLOW_COPY_AND_ASSIGN(BookmarkStorageBackend); |
| 95 }; | 94 }; |
| 96 | 95 |
| 97 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_STORAGE_H_ | 96 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_STORAGE_H_ |
| OLD | NEW |