summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormunjal@chromium.org <munjal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-27 20:16:41 +0000
committermunjal@chromium.org <munjal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-27 20:16:41 +0000
commitb059d497ff6d968640617f9b998c38aa788275f3 (patch)
tree5d05df0f5e9a3f417fa897902f11ed1bb26908e1
parentb10b847afa383deba1d0da676c8fbebc5b6e6ab9 (diff)
downloadchromium_src-b059d497ff6d968640617f9b998c38aa788275f3.zip
chromium_src-b059d497ff6d968640617f9b998c38aa788275f3.tar.gz
chromium_src-b059d497ff6d968640617f9b998c38aa788275f3.tar.bz2
Add a preference to enable/disable ID persistence in bookmark model and
add methods in bookmark model to get/set this preference. Review URL: http://codereview.chromium.org/113882 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17017 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/bookmarks/bookmark_model.cc32
-rw-r--r--chrome/browser/bookmarks/bookmark_model.h12
-rw-r--r--chrome/browser/bookmarks/bookmark_storage.cc14
3 files changed, 53 insertions, 5 deletions
diff --git a/chrome/browser/bookmarks/bookmark_model.cc b/chrome/browser/bookmarks/bookmark_model.cc
index be1d566..5fc0af8 100644
--- a/chrome/browser/bookmarks/bookmark_model.cc
+++ b/chrome/browser/bookmarks/bookmark_model.cc
@@ -14,6 +14,7 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profile.h"
#include "chrome/common/notification_service.h"
+#include "chrome/common/pref_service.h"
#include "grit/generated_resources.h"
using base::Time;
@@ -54,6 +55,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<BookmarkNode*,
@@ -84,6 +88,7 @@ class SortComparator : public std::binary_function<BookmarkNode*,
BookmarkModel::BookmarkModel(Profile* profile)
: profile_(profile),
loaded_(false),
+ persist_ids_(false),
root_(GURL()),
bookmark_bar_node_(NULL),
other_node_(NULL),
@@ -94,6 +99,8 @@ BookmarkModel::BookmarkModel(Profile* profile)
// Profile is null during testing.
DoneLoading(CreateLoadDetails());
}
+ RegisterPreferences();
+ LoadPreferences();
}
BookmarkModel::~BookmarkModel() {
@@ -377,6 +384,16 @@ 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_);
+ }
+}
+
bool BookmarkModel::IsBookmarkedNoLock(const GURL& url) {
BookmarkNode tmp_node(url);
return (nodes_ordered_by_url_set_.find(&tmp_node) !=
@@ -689,3 +706,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);
+}
diff --git a/chrome/browser/bookmarks/bookmark_model.h b/chrome/browser/bookmarks/bookmark_model.h
index 2e745a5..669a0b5 100644
--- a/chrome/browser/bookmarks/bookmark_model.h
+++ b/chrome/browser/bookmarks/bookmark_model.h
@@ -324,6 +324,10 @@ class BookmarkModel : public NotificationObserver, public BookmarkService {
// testing.
void ClearStore();
+ // Sets/returns whether or not bookmark IDs are persisted or not.
+ bool PersistIDs() const { return persist_ids_; }
+ void SetPersistIDs(bool value);
+
private:
// Used to order BookmarkNodes by URL.
class NodeURLComparator {
@@ -418,6 +422,11 @@ class BookmarkModel : public NotificationObserver, public BookmarkService {
// the returned object.
BookmarkStorage::LoadDetails* CreateLoadDetails();
+ // Registers bookmarks related prefs.
+ void RegisterPreferences();
+ // Loads bookmark related preferences.
+ void LoadPreferences();
+
NotificationRegistrar registrar_;
Profile* profile_;
@@ -425,6 +434,9 @@ class BookmarkModel : public NotificationObserver, public BookmarkService {
// Whether the initial set of data has been loaded.
bool loaded_;
+ // Whether to persist bookmark IDs.
+ bool persist_ids_;
+
// The root node. This contains the bookmark bar node and the 'other' node as
// children.
BookmarkNode root_;
diff --git a/chrome/browser/bookmarks/bookmark_storage.cc b/chrome/browser/bookmarks/bookmark_storage.cc
index 5680852..e438e186 100644
--- a/chrome/browser/bookmarks/bookmark_storage.cc
+++ b/chrome/browser/bookmarks/bookmark_storage.cc
@@ -68,11 +68,13 @@ class BookmarkStorage::LoadTask : public Task {
LoadTask(const FilePath& path,
MessageLoop* loop,
BookmarkStorage* storage,
- LoadDetails* details)
+ LoadDetails* details,
+ bool persist_ids)
: path_(path),
loop_(loop),
storage_(storage),
- details_(details) {
+ details_(details),
+ persist_ids_(persist_ids) {
}
virtual void Run() {
@@ -85,7 +87,7 @@ class BookmarkStorage::LoadTask : public Task {
// Building the index cane take a while, so we do it on the background
// thread.
int max_node_id = 0;
- BookmarkCodec codec;
+ BookmarkCodec codec(persist_ids_);
TimeTicks start_time = TimeTicks::Now();
codec.Decode(details_->bb_node(), details_->other_folder_node(),
&max_node_id, *root.get());
@@ -125,6 +127,7 @@ class BookmarkStorage::LoadTask : public Task {
MessageLoop* loop_;
scoped_refptr<BookmarkStorage> storage_;
LoadDetails* details_;
+ bool persist_ids_;
DISALLOW_COPY_AND_ASSIGN(LoadTask);
};
@@ -159,7 +162,8 @@ void BookmarkStorage::DoLoadBookmarks(const FilePath& path) {
Task* task = new LoadTask(path,
backend_thread() ? MessageLoop::current() : NULL,
this,
- details_.get());
+ details_.get(),
+ model_->PersistIDs());
RunTaskOnBackendThread(task);
}
@@ -205,7 +209,7 @@ void BookmarkStorage::BookmarkModelDeleted() {
}
bool BookmarkStorage::SerializeData(std::string* output) {
- BookmarkCodec codec;
+ BookmarkCodec codec(model_->PersistIDs());
scoped_ptr<Value> value(codec.Encode(model_));
JSONStringValueSerializer serializer(output);
serializer.set_pretty_print(true);