Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: chrome/browser/bookmarks/bookmark_storage.cc

Issue 11027070: Moved JsonPrefStore to use SequencedWorkerPool (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "chrome/browser/bookmarks/bookmark_storage.h" 5 #include "chrome/browser/bookmarks/bookmark_storage.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 index_(index), 100 index_(index),
101 max_id_(max_id), 101 max_id_(max_id),
102 ids_reassigned_(false) { 102 ids_reassigned_(false) {
103 } 103 }
104 104
105 BookmarkLoadDetails::~BookmarkLoadDetails() { 105 BookmarkLoadDetails::~BookmarkLoadDetails() {
106 } 106 }
107 107
108 // BookmarkStorage ------------------------------------------------------------- 108 // BookmarkStorage -------------------------------------------------------------
109 109
110 BookmarkStorage::BookmarkStorage(content::BrowserContext* context, 110 BookmarkStorage::BookmarkStorage(
111 BookmarkModel* model) 111 content::BrowserContext* context,
112 BookmarkModel* model,
113 base::SequencedTaskRunner* sequenced_task_runner)
112 : model_(model), 114 : model_(model),
113 writer_(context->GetPath().Append(chrome::kBookmarksFileName), 115 writer_(context->GetPath().Append(chrome::kBookmarksFileName),
114 BrowserThread::GetMessageLoopProxyForThread( 116 sequenced_task_runner) {
115 BrowserThread::FILE)) { 117 sequenced_task_runner_ = sequenced_task_runner;
116 writer_.set_commit_interval(base::TimeDelta::FromMilliseconds(kSaveDelayMS)); 118 writer_.set_commit_interval(base::TimeDelta::FromMilliseconds(kSaveDelayMS));
117 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 119 sequenced_task_runner_->PostTask(FROM_HERE,
118 base::Bind(&BackupCallback, writer_.path())); 120 base::Bind(&BackupCallback, writer_.path()));
119 } 121 }
120 122
121 BookmarkStorage::~BookmarkStorage() { 123 BookmarkStorage::~BookmarkStorage() {
122 if (writer_.HasPendingWrite()) 124 if (writer_.HasPendingWrite())
123 writer_.DoScheduledWrite(); 125 writer_.DoScheduledWrite();
124 } 126 }
125 127
126 void BookmarkStorage::LoadBookmarks(BookmarkLoadDetails* details) { 128 void BookmarkStorage::LoadBookmarks(BookmarkLoadDetails* details) {
127 DCHECK(!details_.get()); 129 DCHECK(!details_.get());
128 DCHECK(details); 130 DCHECK(details);
129 details_.reset(details); 131 details_.reset(details);
130 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, base::Bind( 132 sequenced_task_runner_->PostTask(
131 &LoadCallback, writer_.path(), make_scoped_refptr(this), details_.get())); 133 FROM_HERE,
134 base::Bind(&LoadCallback, writer_.path(), make_scoped_refptr(this),
135 details_.get()));
132 } 136 }
133 137
134 void BookmarkStorage::ScheduleSave() { 138 void BookmarkStorage::ScheduleSave() {
135 writer_.ScheduleWrite(this); 139 writer_.ScheduleWrite(this);
136 } 140 }
137 141
138 void BookmarkStorage::BookmarkModelDeleted() { 142 void BookmarkStorage::BookmarkModelDeleted() {
139 // We need to save now as otherwise by the time SaveNow is invoked 143 // We need to save now as otherwise by the time SaveNow is invoked
140 // the model is gone. 144 // the model is gone.
141 if (writer_.HasPendingWrite()) 145 if (writer_.HasPendingWrite())
(...skipping 23 matching lines...) Expand all
165 NOTREACHED(); 169 NOTREACHED();
166 return false; 170 return false;
167 } 171 }
168 172
169 std::string data; 173 std::string data;
170 if (!SerializeData(&data)) 174 if (!SerializeData(&data))
171 return false; 175 return false;
172 writer_.WriteNow(data); 176 writer_.WriteNow(data);
173 return true; 177 return true;
174 } 178 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698