| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/files/file_path.h" |
| 8 #include "base/files/important_file_writer.h" | 9 #include "base/files/important_file_writer.h" |
| 9 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 11 #include "chrome/browser/bookmarks/bookmark_model.h" | 12 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 12 | 13 |
| 13 class BookmarkIndex; | 14 class BookmarkIndex; |
| 14 class BookmarkModel; | 15 class BookmarkModel; |
| 15 class BookmarkPermanentNode; | 16 class BookmarkPermanentNode; |
| 16 | 17 |
| 17 namespace base { | 18 namespace base { |
| 18 class SequencedTaskRunner; | 19 class SequencedTaskRunner; |
| 19 } | 20 } |
| 20 | 21 |
| 21 namespace content { | |
| 22 class BrowserContext; | |
| 23 } | |
| 24 | |
| 25 // BookmarkLoadDetails is used by BookmarkStorage when loading bookmarks. | 22 // BookmarkLoadDetails is used by BookmarkStorage when loading bookmarks. |
| 26 // BookmarkModel creates a BookmarkLoadDetails and passes it (including | 23 // BookmarkModel creates a BookmarkLoadDetails and passes it (including |
| 27 // ownership) to BookmarkStorage. BookmarkStorage loads the bookmarks (and | 24 // ownership) to BookmarkStorage. BookmarkStorage loads the bookmarks (and |
| 28 // index) in the background thread, then calls back to the BookmarkModel (on | 25 // index) in the background thread, then calls back to the BookmarkModel (on |
| 29 // the main thread) when loading is done, passing ownership back to the | 26 // the main thread) when loading is done, passing ownership back to the |
| 30 // BookmarkModel. While loading BookmarkModel does not maintain references to | 27 // BookmarkModel. While loading BookmarkModel does not maintain references to |
| 31 // the contents of the BookmarkLoadDetails, this ensures we don't have any | 28 // the contents of the BookmarkLoadDetails, this ensures we don't have any |
| 32 // threading problems. | 29 // threading problems. |
| 33 class BookmarkLoadDetails { | 30 class BookmarkLoadDetails { |
| 34 public: | 31 public: |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 107 |
| 111 // BookmarkStorage handles reading/write the bookmark bar model. The | 108 // BookmarkStorage handles reading/write the bookmark bar model. The |
| 112 // BookmarkModel uses the BookmarkStorage to load bookmarks from disk, as well | 109 // BookmarkModel uses the BookmarkStorage to load bookmarks from disk, as well |
| 113 // as notifying the BookmarkStorage every time the model changes. | 110 // as notifying the BookmarkStorage every time the model changes. |
| 114 // | 111 // |
| 115 // Internally BookmarkStorage uses BookmarkCodec to do the actual read/write. | 112 // Internally BookmarkStorage uses BookmarkCodec to do the actual read/write. |
| 116 class BookmarkStorage : public base::ImportantFileWriter::DataSerializer, | 113 class BookmarkStorage : public base::ImportantFileWriter::DataSerializer, |
| 117 public base::RefCountedThreadSafe<BookmarkStorage> { | 114 public base::RefCountedThreadSafe<BookmarkStorage> { |
| 118 public: | 115 public: |
| 119 // Creates a BookmarkStorage for the specified model | 116 // Creates a BookmarkStorage for the specified model |
| 120 BookmarkStorage(content::BrowserContext* context, | 117 BookmarkStorage(BookmarkModel* model, |
| 121 BookmarkModel* model, | 118 const base::FilePath& profile_path, |
| 122 base::SequencedTaskRunner* sequenced_task_runner); | 119 base::SequencedTaskRunner* sequenced_task_runner); |
| 123 | 120 |
| 124 // Loads the bookmarks into the model, notifying the model when done. This | 121 // Loads the bookmarks into the model, notifying the model when done. This |
| 125 // takes ownership of |details|. See BookmarkLoadDetails for details. | 122 // takes ownership of |details|. See BookmarkLoadDetails for details. |
| 126 void LoadBookmarks(BookmarkLoadDetails* details); | 123 void LoadBookmarks(BookmarkClient* client, BookmarkLoadDetails* details); |
| 127 | 124 |
| 128 // Schedules saving the bookmark bar model to disk. | 125 // Schedules saving the bookmark bar model to disk. |
| 129 void ScheduleSave(); | 126 void ScheduleSave(); |
| 130 | 127 |
| 131 // Notification the bookmark bar model is going to be deleted. If there is | 128 // Notification the bookmark bar model is going to be deleted. If there is |
| 132 // a pending save, it is saved immediately. | 129 // a pending save, it is saved immediately. |
| 133 void BookmarkModelDeleted(); | 130 void BookmarkModelDeleted(); |
| 134 | 131 |
| 135 // Callback from backend after loading the bookmark file. | 132 // Callback from backend after loading the bookmark file. |
| 136 void OnLoadFinished(); | 133 void OnLoadFinished(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 156 // See class description of BookmarkLoadDetails for details on this. | 153 // See class description of BookmarkLoadDetails for details on this. |
| 157 scoped_ptr<BookmarkLoadDetails> details_; | 154 scoped_ptr<BookmarkLoadDetails> details_; |
| 158 | 155 |
| 159 // Sequenced task runner where file I/O operations will be performed at. | 156 // Sequenced task runner where file I/O operations will be performed at. |
| 160 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_; | 157 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_; |
| 161 | 158 |
| 162 DISALLOW_COPY_AND_ASSIGN(BookmarkStorage); | 159 DISALLOW_COPY_AND_ASSIGN(BookmarkStorage); |
| 163 }; | 160 }; |
| 164 | 161 |
| 165 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_STORAGE_H_ | 162 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_STORAGE_H_ |
| OLD | NEW |