summaryrefslogtreecommitdiffstats
path: root/chrome/browser/bookmarks/bookmark_model.cc
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-08 14:41:08 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-08 14:41:08 +0000
commit6c116404c0e4ebcbfea94ff91e0979bee67222e4 (patch)
treec749a0f0f2f538ed7651da2f0cda4a5667cd8fcc /chrome/browser/bookmarks/bookmark_model.cc
parent6f45d5f57decad87b06a63239d77657ed458e361 (diff)
downloadchromium_src-6c116404c0e4ebcbfea94ff91e0979bee67222e4.zip
chromium_src-6c116404c0e4ebcbfea94ff91e0979bee67222e4.tar.gz
chromium_src-6c116404c0e4ebcbfea94ff91e0979bee67222e4.tar.bz2
Converted BookmarkStorage to use ImportantFileWriter
Also made BookmarkStorage completely responsible for migration of bookmark data from history database. Previously the logic crossed file and class boundaries a few times. This made it a bit hard to follow. Now it should be a bit more clear. Made ImportantFileWriter also batch data serializations. TEST=Make sure that bookmarks still work. Also test migrating bookmarks from history database. http://crbug.com/10618 Review URL: http://codereview.chromium.org/99192 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15635 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/bookmarks/bookmark_model.cc')
-rw-r--r--chrome/browser/bookmarks/bookmark_model.cc80
1 files changed, 3 insertions, 77 deletions
diff --git a/chrome/browser/bookmarks/bookmark_model.cc b/chrome/browser/bookmarks/bookmark_model.cc
index e944419..646aa3f 100644
--- a/chrome/browser/bookmarks/bookmark_model.cc
+++ b/chrome/browser/bookmarks/bookmark_model.cc
@@ -109,7 +109,6 @@ BookmarkModel::BookmarkModel(Profile* profile)
bookmark_bar_node_(NULL),
other_node_(NULL),
observers_(ObserverList<BookmarkModelObserver>::NOTIFY_EXISTING_ONLY),
- waiting_for_history_load_(false),
loaded_signal_(TRUE, FALSE)
{
// Create the bookmark bar and other bookmarks folders. These always exist.
@@ -135,11 +134,6 @@ BookmarkModel::~BookmarkModel() {
this, NotificationType::FAVICON_CHANGED, Source<Profile>(profile_));
}
- if (waiting_for_history_load_) {
- NotificationService::current()->RemoveObserver(
- this, NotificationType::HISTORY_LOADED, Source<Profile>(profile_));
- }
-
FOR_EACH_OBSERVER(BookmarkModelObserver, observers_,
BookmarkModelBeingDeleted(this));
@@ -167,7 +161,7 @@ void BookmarkModel::Load() {
// Load the bookmarks. BookmarkStorage notifies us when done.
store_ = new BookmarkStorage(profile_, this);
- store_->LoadBookmarks(false);
+ store_->LoadBookmarks();
}
BookmarkNode* BookmarkModel::GetParentForNewNodes() {
@@ -437,65 +431,9 @@ void BookmarkModel::RemoveNode(BookmarkNode* node,
RemoveNode(node->GetChild(i), removed_urls);
}
-void BookmarkModel::OnBookmarkStorageLoadedBookmarks(
- bool file_exists,
- bool loaded_from_history) {
- if (loaded_) {
- NOTREACHED();
- return;
- }
-
- LOG(INFO) << "Loaded bookmarks, file_exists=" << file_exists <<
- " from_history=" << loaded_from_history;
-
- if (file_exists || loaded_from_history || !profile_ ||
- !profile_->GetHistoryService(Profile::EXPLICIT_ACCESS)) {
- // The file exists, we're loaded.
- DoneLoading();
-
- if (loaded_from_history) {
- // We were just populated from the historical file. Schedule a save so
- // that the main file is up to date.
- store_->ScheduleSave();
- }
- return;
- }
-
- // The file doesn't exist. This means one of two things:
- // 1. A clean profile.
- // 2. The user is migrating from an older version where bookmarks were saved
- // in history.
- // We assume step 2. If history had the bookmarks, history will write the
- // bookmarks to a file for us. We need to wait until history has finished
- // loading before reading from that file.
- HistoryService* history =
- profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
- if (!history->backend_loaded()) {
- // The backend isn't finished loading. Wait for it.
- LOG(INFO) << " waiting for history to finish";
-
- waiting_for_history_load_ = true;
- NotificationService::current()->AddObserver(
- this, NotificationType::HISTORY_LOADED, Source<Profile>(profile_));
- } else {
- OnHistoryDone();
- }
-}
-
-void BookmarkModel::OnHistoryDone() {
- if (loaded_) {
- NOTREACHED();
- return;
- }
-
- LOG(INFO) << " history done, reloading";
-
- // If the bookmarks were stored in the db the db will have migrated them to
- // a file now. Try loading from the file.
- store_->LoadBookmarks(true);
-}
-
void BookmarkModel::DoneLoading() {
+ DCHECK(!loaded_);
+
{
AutoLock url_lock(url_lock_);
// Update nodes_ordered_by_url_set_ from the nodes.
@@ -718,18 +656,6 @@ void BookmarkModel::Observe(NotificationType type,
break;
}
- case NotificationType::HISTORY_LOADED: {
- if (waiting_for_history_load_) {
- waiting_for_history_load_ = false;
- NotificationService::current()->RemoveObserver(
- this,NotificationType::HISTORY_LOADED, Source<Profile>(profile_));
- OnHistoryDone();
- } else {
- NOTREACHED();
- }
- break;
- }
-
default:
NOTREACHED();
break;