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

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

Issue 7327007: Moving notification types which are chrome specific to a new header file chrome_notification_type... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 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_storage.h ('k') | chrome/browser/bookmarks/bookmark_utils.cc » ('j') | 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) 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 #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/file_util_proxy.h" 9 #include "base/file_util_proxy.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "base/time.h" 11 #include "base/time.h"
12 #include "chrome/browser/bookmarks/bookmark_codec.h" 12 #include "chrome/browser/bookmarks/bookmark_codec.h"
13 #include "chrome/browser/bookmarks/bookmark_model.h" 13 #include "chrome/browser/bookmarks/bookmark_model.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/common/chrome_constants.h" 15 #include "chrome/common/chrome_constants.h"
16 #include "chrome/common/chrome_notification_types.h"
16 #include "content/browser/browser_thread.h" 17 #include "content/browser/browser_thread.h"
17 #include "content/common/json_value_serializer.h" 18 #include "content/common/json_value_serializer.h"
18 #include "content/common/notification_source.h" 19 #include "content/common/notification_source.h"
19 #include "content/common/notification_type.h"
20 20
21 using base::TimeTicks; 21 using base::TimeTicks;
22 22
23 namespace { 23 namespace {
24 24
25 // Extension used for backup files (copy of main file created during startup). 25 // Extension used for backup files (copy of main file created during startup).
26 const FilePath::CharType kBackupExtension[] = FILE_PATH_LITERAL("bak"); 26 const FilePath::CharType kBackupExtension[] = FILE_PATH_LITERAL("bak");
27 27
28 // How often we save. 28 // How often we save.
29 const int kSaveDelayMS = 2500; 29 const int kSaveDelayMS = 2500;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 HistoryService* history = 167 HistoryService* history =
168 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); 168 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
169 if (!history) { 169 if (!history) {
170 // This happens in unit tests. 170 // This happens in unit tests.
171 if (model_) 171 if (model_)
172 model_->DoneLoading(details_.release()); 172 model_->DoneLoading(details_.release());
173 return; 173 return;
174 } 174 }
175 if (!history->BackendLoaded()) { 175 if (!history->BackendLoaded()) {
176 // The backend isn't finished loading. Wait for it. 176 // The backend isn't finished loading. Wait for it.
177 notification_registrar_.Add(this, NotificationType::HISTORY_LOADED, 177 notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_LOADED,
178 Source<Profile>(profile_)); 178 Source<Profile>(profile_));
179 } else { 179 } else {
180 DoLoadBookmarks(tmp_history_path_); 180 DoLoadBookmarks(tmp_history_path_);
181 } 181 }
182 } 182 }
183 183
184 void BookmarkStorage::OnHistoryFinishedWriting() { 184 void BookmarkStorage::OnHistoryFinishedWriting() {
185 notification_registrar_.Remove(this, NotificationType::HISTORY_LOADED, 185 notification_registrar_.Remove(this, chrome::NOTIFICATION_HISTORY_LOADED,
186 Source<Profile>(profile_)); 186 Source<Profile>(profile_));
187 187
188 // This is used when migrating bookmarks data from database to file. 188 // This is used when migrating bookmarks data from database to file.
189 // History wrote the file for us, and now we want to load data from it. 189 // History wrote the file for us, and now we want to load data from it.
190 DoLoadBookmarks(tmp_history_path_); 190 DoLoadBookmarks(tmp_history_path_);
191 } 191 }
192 192
193 void BookmarkStorage::ScheduleSave() { 193 void BookmarkStorage::ScheduleSave() {
194 writer_.ScheduleWrite(this); 194 writer_.ScheduleWrite(this);
195 } 195 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 234
235 // Clean up after migration from history. 235 // Clean up after migration from history.
236 base::FileUtilProxy::Delete( 236 base::FileUtilProxy::Delete(
237 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), 237 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE),
238 tmp_history_path_, 238 tmp_history_path_,
239 false, 239 false,
240 NULL); 240 NULL);
241 } 241 }
242 } 242 }
243 243
244 void BookmarkStorage::Observe(NotificationType type, 244 void BookmarkStorage::Observe(int type,
245 const NotificationSource& source, 245 const NotificationSource& source,
246 const NotificationDetails& details) { 246 const NotificationDetails& details) {
247 switch (type.value) { 247 switch (type) {
248 case NotificationType::HISTORY_LOADED: 248 case chrome::NOTIFICATION_HISTORY_LOADED:
249 OnHistoryFinishedWriting(); 249 OnHistoryFinishedWriting();
250 break; 250 break;
251 251
252 default: 252 default:
253 NOTREACHED(); 253 NOTREACHED();
254 break; 254 break;
255 } 255 }
256 } 256 }
257 257
258 bool BookmarkStorage::SaveNow() { 258 bool BookmarkStorage::SaveNow() {
259 if (!model_ || !model_->IsLoaded()) { 259 if (!model_ || !model_->IsLoaded()) {
260 // We should only get here if we have a valid model and it's finished 260 // We should only get here if we have a valid model and it's finished
261 // loading. 261 // loading.
262 NOTREACHED(); 262 NOTREACHED();
263 return false; 263 return false;
264 } 264 }
265 265
266 std::string data; 266 std::string data;
267 if (!SerializeData(&data)) 267 if (!SerializeData(&data))
268 return false; 268 return false;
269 writer_.WriteNow(data); 269 writer_.WriteNow(data);
270 return true; 270 return true;
271 } 271 }
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/bookmark_storage.h ('k') | chrome/browser/bookmarks/bookmark_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698