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/important_file_writer.h" | 8 #include "base/files/important_file_writer.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "chrome/browser/bookmarks/bookmark_index.h" | 11 #include "chrome/browser/bookmarks/bookmark_index.h" |
12 | 12 |
13 class BookmarkModel; | 13 class BookmarkModel; |
14 class BookmarkPermanentNode; | 14 class BookmarkPermanentNode; |
15 | 15 |
| 16 namespace base { |
| 17 class SequencedTaskRunner; |
| 18 } |
| 19 |
16 namespace content { | 20 namespace content { |
17 class BrowserContext; | 21 class BrowserContext; |
18 } | 22 } |
19 | 23 |
20 // BookmarkLoadDetails is used by BookmarkStorage when loading bookmarks. | 24 // BookmarkLoadDetails is used by BookmarkStorage when loading bookmarks. |
21 // BookmarkModel creates a BookmarkLoadDetails and passes it (including | 25 // BookmarkModel creates a BookmarkLoadDetails and passes it (including |
22 // ownership) to BookmarkStorage. BookmarkStorage loads the bookmarks (and | 26 // ownership) to BookmarkStorage. BookmarkStorage loads the bookmarks (and |
23 // index) in the background thread, then calls back to the BookmarkModel (on | 27 // index) in the background thread, then calls back to the BookmarkModel (on |
24 // the main thread) when loading is done, passing ownership back to the | 28 // the main thread) when loading is done, passing ownership back to the |
25 // BookmarkModel. While loading BookmarkModel does not maintain references to | 29 // BookmarkModel. While loading BookmarkModel does not maintain references to |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 99 |
96 // BookmarkStorage handles reading/write the bookmark bar model. The | 100 // BookmarkStorage handles reading/write the bookmark bar model. The |
97 // BookmarkModel uses the BookmarkStorage to load bookmarks from disk, as well | 101 // BookmarkModel uses the BookmarkStorage to load bookmarks from disk, as well |
98 // as notifying the BookmarkStorage every time the model changes. | 102 // as notifying the BookmarkStorage every time the model changes. |
99 // | 103 // |
100 // Internally BookmarkStorage uses BookmarkCodec to do the actual read/write. | 104 // Internally BookmarkStorage uses BookmarkCodec to do the actual read/write. |
101 class BookmarkStorage : public base::ImportantFileWriter::DataSerializer, | 105 class BookmarkStorage : public base::ImportantFileWriter::DataSerializer, |
102 public base::RefCountedThreadSafe<BookmarkStorage> { | 106 public base::RefCountedThreadSafe<BookmarkStorage> { |
103 public: | 107 public: |
104 // Creates a BookmarkStorage for the specified model | 108 // Creates a BookmarkStorage for the specified model |
105 BookmarkStorage(content::BrowserContext* context, BookmarkModel* model); | 109 BookmarkStorage(content::BrowserContext* context, |
| 110 BookmarkModel* model, |
| 111 base::SequencedTaskRunner* sequenced_task_runner); |
106 | 112 |
107 // Loads the bookmarks into the model, notifying the model when done. This | 113 // Loads the bookmarks into the model, notifying the model when done. This |
108 // takes ownership of |details|. See BookmarkLoadDetails for details. | 114 // takes ownership of |details|. See BookmarkLoadDetails for details. |
109 void LoadBookmarks(BookmarkLoadDetails* details); | 115 void LoadBookmarks(BookmarkLoadDetails* details); |
110 | 116 |
111 // Schedules saving the bookmark bar model to disk. | 117 // Schedules saving the bookmark bar model to disk. |
112 void ScheduleSave(); | 118 void ScheduleSave(); |
113 | 119 |
114 // Notification the bookmark bar model is going to be deleted. If there is | 120 // Notification the bookmark bar model is going to be deleted. If there is |
115 // a pending save, it is saved immediately. | 121 // a pending save, it is saved immediately. |
(...skipping 16 matching lines...) Expand all Loading... |
132 | 138 |
133 // The model. The model is NULL once BookmarkModelDeleted has been invoked. | 139 // The model. The model is NULL once BookmarkModelDeleted has been invoked. |
134 BookmarkModel* model_; | 140 BookmarkModel* model_; |
135 | 141 |
136 // Helper to write bookmark data safely. | 142 // Helper to write bookmark data safely. |
137 base::ImportantFileWriter writer_; | 143 base::ImportantFileWriter writer_; |
138 | 144 |
139 // See class description of BookmarkLoadDetails for details on this. | 145 // See class description of BookmarkLoadDetails for details on this. |
140 scoped_ptr<BookmarkLoadDetails> details_; | 146 scoped_ptr<BookmarkLoadDetails> details_; |
141 | 147 |
| 148 // Sequenced task runner where file I/O operations will be performed at. |
| 149 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_; |
| 150 |
142 DISALLOW_COPY_AND_ASSIGN(BookmarkStorage); | 151 DISALLOW_COPY_AND_ASSIGN(BookmarkStorage); |
143 }; | 152 }; |
144 | 153 |
145 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_STORAGE_H_ | 154 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_STORAGE_H_ |
OLD | NEW |