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

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

Issue 113882: Add a preference to enable/disable ID persistence in bookmark model and... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 months 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
« no previous file with comments | « chrome/browser/bookmarks/bookmark_model.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "chrome/browser/bookmarks/bookmark_storage.h" 5 #include "chrome/browser/bookmarks/bookmark_storage.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/histogram.h" 9 #include "base/histogram.h"
10 #include "base/json_writer.h" 10 #include "base/json_writer.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 DISALLOW_COPY_AND_ASSIGN(FileDeleteTask); 61 DISALLOW_COPY_AND_ASSIGN(FileDeleteTask);
62 }; 62 };
63 63
64 } // namespace 64 } // namespace
65 65
66 class BookmarkStorage::LoadTask : public Task { 66 class BookmarkStorage::LoadTask : public Task {
67 public: 67 public:
68 LoadTask(const FilePath& path, 68 LoadTask(const FilePath& path,
69 MessageLoop* loop, 69 MessageLoop* loop,
70 BookmarkStorage* storage, 70 BookmarkStorage* storage,
71 LoadDetails* details) 71 LoadDetails* details,
72 bool persist_ids)
72 : path_(path), 73 : path_(path),
73 loop_(loop), 74 loop_(loop),
74 storage_(storage), 75 storage_(storage),
75 details_(details) { 76 details_(details),
77 persist_ids_(persist_ids) {
76 } 78 }
77 79
78 virtual void Run() { 80 virtual void Run() {
79 bool bookmark_file_exists = file_util::PathExists(path_); 81 bool bookmark_file_exists = file_util::PathExists(path_);
80 if (bookmark_file_exists) { 82 if (bookmark_file_exists) {
81 JSONFileValueSerializer serializer(path_); 83 JSONFileValueSerializer serializer(path_);
82 scoped_ptr<Value> root(serializer.Deserialize(NULL)); 84 scoped_ptr<Value> root(serializer.Deserialize(NULL));
83 85
84 if (root.get()) { 86 if (root.get()) {
85 // Building the index cane take a while, so we do it on the background 87 // Building the index cane take a while, so we do it on the background
86 // thread. 88 // thread.
87 int max_node_id = 0; 89 int max_node_id = 0;
88 BookmarkCodec codec; 90 BookmarkCodec codec(persist_ids_);
89 TimeTicks start_time = TimeTicks::Now(); 91 TimeTicks start_time = TimeTicks::Now();
90 codec.Decode(details_->bb_node(), details_->other_folder_node(), 92 codec.Decode(details_->bb_node(), details_->other_folder_node(),
91 &max_node_id, *root.get()); 93 &max_node_id, *root.get());
92 details_->set_max_id(std::max(max_node_id, details_->max_id())); 94 details_->set_max_id(std::max(max_node_id, details_->max_id()));
93 UMA_HISTOGRAM_TIMES("Bookmarks.DecodeTime", 95 UMA_HISTOGRAM_TIMES("Bookmarks.DecodeTime",
94 TimeTicks::Now() - start_time); 96 TimeTicks::Now() - start_time);
95 97
96 start_time = TimeTicks::Now(); 98 start_time = TimeTicks::Now();
97 AddBookmarksToIndex(details_->bb_node()); 99 AddBookmarksToIndex(details_->bb_node());
98 AddBookmarksToIndex(details_->other_folder_node()); 100 AddBookmarksToIndex(details_->other_folder_node());
(...skipping 19 matching lines...) Expand all
118 } else { 120 } else {
119 for (int i = 0; i < node->GetChildCount(); ++i) 121 for (int i = 0; i < node->GetChildCount(); ++i)
120 AddBookmarksToIndex(node->GetChild(i)); 122 AddBookmarksToIndex(node->GetChild(i));
121 } 123 }
122 } 124 }
123 125
124 const FilePath path_; 126 const FilePath path_;
125 MessageLoop* loop_; 127 MessageLoop* loop_;
126 scoped_refptr<BookmarkStorage> storage_; 128 scoped_refptr<BookmarkStorage> storage_;
127 LoadDetails* details_; 129 LoadDetails* details_;
130 bool persist_ids_;
128 131
129 DISALLOW_COPY_AND_ASSIGN(LoadTask); 132 DISALLOW_COPY_AND_ASSIGN(LoadTask);
130 }; 133 };
131 134
132 // BookmarkStorage ------------------------------------------------------------- 135 // BookmarkStorage -------------------------------------------------------------
133 136
134 BookmarkStorage::BookmarkStorage(Profile* profile, BookmarkModel* model) 137 BookmarkStorage::BookmarkStorage(Profile* profile, BookmarkModel* model)
135 : profile_(profile), 138 : profile_(profile),
136 model_(model), 139 model_(model),
137 backend_thread_(g_browser_process->file_thread()), 140 backend_thread_(g_browser_process->file_thread()),
(...skipping 14 matching lines...) Expand all
152 DCHECK(!details_.get()); 155 DCHECK(!details_.get());
153 DCHECK(details); 156 DCHECK(details);
154 details_.reset(details); 157 details_.reset(details);
155 DoLoadBookmarks(writer_.path()); 158 DoLoadBookmarks(writer_.path());
156 } 159 }
157 160
158 void BookmarkStorage::DoLoadBookmarks(const FilePath& path) { 161 void BookmarkStorage::DoLoadBookmarks(const FilePath& path) {
159 Task* task = new LoadTask(path, 162 Task* task = new LoadTask(path,
160 backend_thread() ? MessageLoop::current() : NULL, 163 backend_thread() ? MessageLoop::current() : NULL,
161 this, 164 this,
162 details_.get()); 165 details_.get(),
166 model_->PersistIDs());
163 RunTaskOnBackendThread(task); 167 RunTaskOnBackendThread(task);
164 } 168 }
165 169
166 void BookmarkStorage::MigrateFromHistory() { 170 void BookmarkStorage::MigrateFromHistory() {
167 // We need to wait until history has finished loading before reading 171 // We need to wait until history has finished loading before reading
168 // from generated bookmarks file. 172 // from generated bookmarks file.
169 HistoryService* history = 173 HistoryService* history =
170 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); 174 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
171 if (!history) { 175 if (!history) {
172 // This happens in unit tests. 176 // This happens in unit tests.
(...skipping 25 matching lines...) Expand all
198 202
199 void BookmarkStorage::BookmarkModelDeleted() { 203 void BookmarkStorage::BookmarkModelDeleted() {
200 // We need to save now as otherwise by the time SaveNow is invoked 204 // We need to save now as otherwise by the time SaveNow is invoked
201 // the model is gone. 205 // the model is gone.
202 if (writer_.HasPendingWrite()) 206 if (writer_.HasPendingWrite())
203 SaveNow(); 207 SaveNow();
204 model_ = NULL; 208 model_ = NULL;
205 } 209 }
206 210
207 bool BookmarkStorage::SerializeData(std::string* output) { 211 bool BookmarkStorage::SerializeData(std::string* output) {
208 BookmarkCodec codec; 212 BookmarkCodec codec(model_->PersistIDs());
209 scoped_ptr<Value> value(codec.Encode(model_)); 213 scoped_ptr<Value> value(codec.Encode(model_));
210 JSONStringValueSerializer serializer(output); 214 JSONStringValueSerializer serializer(output);
211 serializer.set_pretty_print(true); 215 serializer.set_pretty_print(true);
212 return serializer.Serialize(*(value.get())); 216 return serializer.Serialize(*(value.get()));
213 } 217 }
214 218
215 void BookmarkStorage::OnLoadFinished(bool file_exists, const FilePath& path) { 219 void BookmarkStorage::OnLoadFinished(bool file_exists, const FilePath& path) {
216 if (path == writer_.path() && !file_exists) { 220 if (path == writer_.path() && !file_exists) {
217 // The file doesn't exist. This means one of two things: 221 // The file doesn't exist. This means one of two things:
218 // 1. A clean profile. 222 // 1. A clean profile.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 } 273 }
270 274
271 void BookmarkStorage::RunTaskOnBackendThread(Task* task) const { 275 void BookmarkStorage::RunTaskOnBackendThread(Task* task) const {
272 if (backend_thread()) { 276 if (backend_thread()) {
273 backend_thread()->message_loop()->PostTask(FROM_HERE, task); 277 backend_thread()->message_loop()->PostTask(FROM_HERE, task);
274 } else { 278 } else {
275 task->Run(); 279 task->Run();
276 delete task; 280 delete task;
277 } 281 }
278 } 282 }
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/bookmark_model.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698