summaryrefslogtreecommitdiffstats
path: root/chrome/browser/bookmarks/bookmark_model.cc
diff options
context:
space:
mode:
authortc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-13 21:54:33 +0000
committertc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-13 21:54:33 +0000
commitbe341c7eacdfccf1720a3e7d96ff96a38a4fb187 (patch)
tree7f70477ac5b95d5821593bc66a7bae44deee24e2 /chrome/browser/bookmarks/bookmark_model.cc
parentec584a1b5c8d4a454a8c008492774a725f0c5513 (diff)
downloadchromium_src-be341c7eacdfccf1720a3e7d96ff96a38a4fb187.zip
chromium_src-be341c7eacdfccf1720a3e7d96ff96a38a4fb187.tar.gz
chromium_src-be341c7eacdfccf1720a3e7d96ff96a38a4fb187.tar.bz2
Revert "Always persist bookmark IDs."
This reverts commit r20532 because valgrind was complaining about uninitialized memory: http://build.chromium.org/buildbot/waterfall/builders/Chromium%20Linux%20(valgrind)/builds/697/steps/valgrind%20test:%20unit/logs/stdio TBR=munjal Review URL: http://codereview.chromium.org/155448 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20550 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/bookmarks/bookmark_model.cc')
-rw-r--r--chrome/browser/bookmarks/bookmark_model.cc59
1 files changed, 45 insertions, 14 deletions
diff --git a/chrome/browser/bookmarks/bookmark_model.cc b/chrome/browser/bookmarks/bookmark_model.cc
index 9bcc8c3..5d87da1 100644
--- a/chrome/browser/bookmarks/bookmark_model.cc
+++ b/chrome/browser/bookmarks/bookmark_model.cc
@@ -35,12 +35,12 @@ BookmarkNode::BookmarkNode(const GURL& url)
Initialize(0);
}
-BookmarkNode::BookmarkNode(int64 id, const GURL& url)
+BookmarkNode::BookmarkNode(int id, const GURL& url)
: url_(url){
Initialize(id);
}
-void BookmarkNode::Initialize(int64 id) {
+void BookmarkNode::Initialize(int id) {
id_ = id;
loaded_favicon_ = false;
favicon_load_handle_ = 0;
@@ -77,6 +77,9 @@ void BookmarkNode::Reset(const history::StarredEntry& entry) {
namespace {
+// Constant for persist IDs prefernece.
+const wchar_t kPrefPersistIDs[] = L"bookmarks.persist_ids";
+
// Comparator used when sorting bookmarks. Folders are sorted first, then
// bookmarks.
class SortComparator : public std::binary_function<const BookmarkNode*,
@@ -107,6 +110,7 @@ class SortComparator : public std::binary_function<const BookmarkNode*,
BookmarkModel::BookmarkModel(Profile* profile)
: profile_(profile),
loaded_(false),
+ persist_ids_(false),
file_changed_(false),
root_(GURL()),
bookmark_bar_node_(NULL),
@@ -118,6 +122,8 @@ BookmarkModel::BookmarkModel(Profile* profile)
// Profile is null during testing.
DoneLoading(CreateLoadDetails());
}
+ RegisterPreferences();
+ LoadPreferences();
}
BookmarkModel::~BookmarkModel() {
@@ -276,7 +282,7 @@ bool BookmarkModel::IsBookmarked(const GURL& url) {
return IsBookmarkedNoLock(url);
}
-const BookmarkNode* BookmarkModel::GetNodeByID(int64 id) {
+const BookmarkNode* BookmarkModel::GetNodeByID(int id) {
// TODO(sky): TreeNode needs a method that visits all nodes using a predicate.
return GetNodeByID(&root_, id);
}
@@ -402,6 +408,19 @@ void BookmarkModel::ClearStore() {
store_ = NULL;
}
+void BookmarkModel::SetPersistIDs(bool value) {
+ if (value == persist_ids_)
+ return;
+ persist_ids_ = value;
+ if (profile_) {
+ PrefService* pref_service = profile_->GetPrefs();
+ pref_service->SetBoolean(kPrefPersistIDs, persist_ids_);
+ }
+ // Need to save the bookmark data if the value of persist IDs changes.
+ if (store_.get())
+ store_->ScheduleSave();
+}
+
bool BookmarkModel::IsBookmarkedNoLock(const GURL& url) {
BookmarkNode tmp_node(url);
return (nodes_ordered_by_url_set_.find(&tmp_node) !=
@@ -458,15 +477,6 @@ void BookmarkModel::DoneLoading(
next_node_id_ = details->max_id();
if (details->computed_checksum() != details->stored_checksum())
SetFileChanged();
- if (details->computed_checksum() != details->stored_checksum() ||
- details->ids_reassigned()) {
- // If bookmarks file changed externally, the IDs may have changed
- // externally. In that case, the decoder may have reassigned IDs to make
- // them unique. So when the file has changed externally, we should save the
- // bookmarks file to persist new IDs.
- if (store_.get())
- store_->ScheduleSave();
- }
index_.reset(details->index());
details->release();
@@ -577,7 +587,7 @@ void BookmarkModel::BlockTillLoaded() {
}
const BookmarkNode* BookmarkModel::GetNodeByID(const BookmarkNode* node,
- int64 id) {
+ int id) {
if (node->id() == id)
return node;
@@ -715,12 +725,18 @@ void BookmarkModel::PopulateNodesByURL(BookmarkNode* node) {
PopulateNodesByURL(node->GetChild(i));
}
-int64 BookmarkModel::generate_next_node_id() {
+int BookmarkModel::generate_next_node_id() {
return next_node_id_++;
}
void BookmarkModel::SetFileChanged() {
file_changed_ = true;
+ // If bookmarks file changed externally, the IDs may have changed externally.
+ // in that case, the decoder may have reassigned IDs to make them unique.
+ // So when the file has changed externally and IDs are persisted, we should
+ // save the bookmarks file to persist new IDs.
+ if (persist_ids_ && store_.get())
+ store_->ScheduleSave();
}
BookmarkStorage::LoadDetails* BookmarkModel::CreateLoadDetails() {
@@ -729,3 +745,18 @@ BookmarkStorage::LoadDetails* BookmarkModel::CreateLoadDetails() {
return new BookmarkStorage::LoadDetails(
bb_node, other_folder_node, new BookmarkIndex(), next_node_id_);
}
+
+void BookmarkModel::RegisterPreferences() {
+ if (!profile_)
+ return;
+ PrefService* pref_service = profile_->GetPrefs();
+ if (!pref_service->IsPrefRegistered(kPrefPersistIDs))
+ pref_service->RegisterBooleanPref(kPrefPersistIDs, false);
+}
+
+void BookmarkModel::LoadPreferences() {
+ if (!profile_)
+ return;
+ PrefService* pref_service = profile_->GetPrefs();
+ persist_ids_ = pref_service->GetBoolean(kPrefPersistIDs);
+}