diff options
author | munjal@chromium.org <munjal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-13 21:17:39 +0000 |
---|---|---|
committer | munjal@chromium.org <munjal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-13 21:17:39 +0000 |
commit | dffeb89734143d57a09c96ae473552463fd579bb (patch) | |
tree | 8986f934595990980cc000dd72a337459c2cd19f /chrome/browser | |
parent | 5e96b65b0470d18a169f4d9eacc8784d1fcfeb6d (diff) | |
download | chromium_src-dffeb89734143d57a09c96ae473552463fd579bb.zip chromium_src-dffeb89734143d57a09c96ae473552463fd579bb.tar.gz chromium_src-dffeb89734143d57a09c96ae473552463fd579bb.tar.bz2 |
Always persist bookmark IDs.
Remove the preference to persist IDs.
NOTE that we need to save the file the first time with IDs
since existing bookmark files won't have IDs and the file
won't be saved until something changes in the bookmark model.
So we need to explicitly save once when we assign ids for the
first time.
TEST=NONE
BUG=16068
Review URL: http://codereview.chromium.org/149310
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20532 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
20 files changed, 193 insertions, 194 deletions
diff --git a/chrome/browser/bookmarks/bookmark_codec.cc b/chrome/browser/bookmarks/bookmark_codec.cc index 4e4f5ed..92f6dcf 100644 --- a/chrome/browser/bookmarks/bookmark_codec.cc +++ b/chrome/browser/bookmarks/bookmark_codec.cc @@ -17,7 +17,7 @@ UniqueIDGenerator::UniqueIDGenerator() { Reset(); } -int UniqueIDGenerator::GetUniqueID(int id) { +int64 UniqueIDGenerator::GetUniqueID(int64 id) { // If the given ID is already assigned, generate new ID. if (IsIdAssigned(id)) id = current_max_ + 1; @@ -31,7 +31,7 @@ int UniqueIDGenerator::GetUniqueID(int id) { return id; } -bool UniqueIDGenerator::IsIdAssigned(int id) const { +bool UniqueIDGenerator::IsIdAssigned(int64 id) const { // If the set is already instantiated, then use the set to determine if the // given ID is assigned. Otherwise use the current maximum to determine if the // given ID is assigned. @@ -41,7 +41,7 @@ bool UniqueIDGenerator::IsIdAssigned(int id) const { return id <= current_max_; } -void UniqueIDGenerator::RecordId(int id) { +void UniqueIDGenerator::RecordId(int64 id) { // If the set is instantiated, then use the set. if (assigned_ids_.get()) { assigned_ids_->insert(id); @@ -55,8 +55,8 @@ void UniqueIDGenerator::RecordId(int id) { ++current_max_; return; } - assigned_ids_.reset(new std::set<int>); - for (int i = 0; i <= current_max_; ++i) + assigned_ids_.reset(new std::set<int64>); + for (int64 i = 0; i <= current_max_; ++i) assigned_ids_->insert(i); assigned_ids_->insert(id); } @@ -85,11 +85,7 @@ const wchar_t* BookmarkCodec::kTypeFolder = L"folder"; static const int kCurrentVersion = 1; BookmarkCodec::BookmarkCodec() - : persist_ids_(false) { -} - -BookmarkCodec::BookmarkCodec(bool persist_ids) - : persist_ids_(persist_ids) { + : ids_reassigned_(false) { } Value* BookmarkCodec::Encode(BookmarkModel* model) { @@ -98,6 +94,7 @@ Value* BookmarkCodec::Encode(BookmarkModel* model) { Value* BookmarkCodec::Encode(const BookmarkNode* bookmark_bar_node, const BookmarkNode* other_folder_node) { + ids_reassigned_ = false; InitializeChecksum(); DictionaryValue* roots = new DictionaryValue(); roots->Set(kRootFolderNameKey, EncodeNode(bookmark_bar_node)); @@ -116,12 +113,16 @@ Value* BookmarkCodec::Encode(const BookmarkNode* bookmark_bar_node, bool BookmarkCodec::Decode(BookmarkNode* bb_node, BookmarkNode* other_folder_node, - int* max_id, + int64* max_id, const Value& value) { + // TODO(munjal): Instead of paying the price of ID generator in al lcases, we + // should only pay the price if we detect the file has changed and do a second + // pass to reassign IDs. See issue 16357. id_generator_.Reset(); + ids_reassigned_ = false; stored_checksum_.clear(); InitializeChecksum(); - bool success = DecodeHelper(bb_node, other_folder_node, max_id, value); + bool success = DecodeHelper(bb_node, other_folder_node, value); FinalizeChecksum(); *max_id = id_generator_.current_max() + 1; return success; @@ -130,10 +131,8 @@ bool BookmarkCodec::Decode(BookmarkNode* bb_node, Value* BookmarkCodec::EncodeNode(const BookmarkNode* node) { DictionaryValue* value = new DictionaryValue(); std::string id; - if (persist_ids_) { - id = IntToString(node->id()); - value->SetString(kIdKey, id); - } + id = Int64ToString(node->id()); + value->SetString(kIdKey, id); const std::wstring& title = node->GetTitle(); value->SetString(kNameKey, title); value->SetString(kDateAddedKey, @@ -160,7 +159,6 @@ Value* BookmarkCodec::EncodeNode(const BookmarkNode* node) { bool BookmarkCodec::DecodeHelper(BookmarkNode* bb_node, BookmarkNode* other_folder_node, - int* max_id, const Value& value) { if (value.GetType() != Value::TYPE_DICTIONARY) return false; // Unexpected type. @@ -231,13 +229,14 @@ bool BookmarkCodec::DecodeNode(const DictionaryValue& value, BookmarkNode* parent, BookmarkNode* node) { std::string id_string; - int id = 0; - if (persist_ids_) { - if (value.GetString(kIdKey, &id_string)) - if (!StringToInt(id_string, &id)) - return false; - } - id = id_generator_.GetUniqueID(id); + int64 id = 0; + if (value.GetString(kIdKey, &id_string)) + if (!StringToInt64(id_string, &id)) + return false; + int64 new_id = id_generator_.GetUniqueID(id); + if (new_id != id) + ids_reassigned_ = true; + id = new_id; std::wstring title; if (!value.GetString(kNameKey, &title)) diff --git a/chrome/browser/bookmarks/bookmark_codec.h b/chrome/browser/bookmarks/bookmark_codec.h index e6292a8..2c13cef 100644 --- a/chrome/browser/bookmarks/bookmark_codec.h +++ b/chrome/browser/bookmarks/bookmark_codec.h @@ -22,7 +22,7 @@ class DictionaryValue; class ListValue; class Value; -// Utility class to help assign unique integer IDs. +// Utility class to help assign unique 64-bit IDs. class UniqueIDGenerator { public: UniqueIDGenerator(); @@ -31,25 +31,26 @@ class UniqueIDGenerator { // returns the id itself, otherwise generates a new unique id in a simple way // and returns that. // NOTE that if id is 0, a new unique id is returned. - int GetUniqueID(int id); + int64 GetUniqueID(int64 id); // Resets the ID generator to initial state. void Reset(); // Returns the current maximum. - int current_max() const { return current_max_; } + int64 current_max() const { return current_max_; } private: // Checks if the given ID is already assigned. - bool IsIdAssigned(int id) const; + bool IsIdAssigned(int64 id) const; // Records the given ID as assigned. - void RecordId(int id); + void RecordId(int64 id); // Maximum value we have seen so far. - int current_max_; + int64 current_max_; + // All IDs assigned so far. - scoped_ptr<std::set<int> > assigned_ids_; + scoped_ptr<std::set<int64> > assigned_ids_; DISALLOW_COPY_AND_ASSIGN(UniqueIDGenerator); }; @@ -59,14 +60,11 @@ class UniqueIDGenerator { class BookmarkCodec { public: - // Creates an instance of the codec. Encodes/decodes bookmark IDs also if - // persist_ids is true. The default constructor will not encode/decode IDs. - // During decoding, if persist_ids is true and if the IDs in the file are not - // unique, we will reassign IDs to make them unique. There are no guarantees - // on how the IDs are reassigned or about doing minimal reassignments to - // achieve uniqueness. + // Creates an instance of the codec. During decoding, if the IDs in the file + // are not unique, we will reassign IDs to make them unique. There are no + // guarantees on how the IDs are reassigned or about doing minimal + // reassignments to achieve uniqueness. BookmarkCodec(); - explicit BookmarkCodec(bool persist_ids); // Encodes the model to a JSON value. It's up to the caller to delete the // returned object. This is invoked to encode the contents of the bookmark bar @@ -88,7 +86,7 @@ class BookmarkCodec { // |max_node_id| is set to the max id of the nodes. bool Decode(BookmarkNode* bb_node, BookmarkNode* other_folder_node, - int* max_node_id, + int64* max_node_id, const Value& value); // Returns the checksum computed during last encoding/decoding call. @@ -101,6 +99,10 @@ class BookmarkCodec { // user. const std::string& stored_checksum() const { return stored_checksum_; } + // Returns whether the IDs were reassigned during decoding. Always returns + // false after encoding. + bool ids_reassigned() const { return ids_reassigned_; } + // Names of the various keys written to the Value. static const wchar_t* kRootsKey; static const wchar_t* kRootFolderNameKey; @@ -127,7 +129,6 @@ class BookmarkCodec { // Helper to perform decoding. bool DecodeHelper(BookmarkNode* bb_node, BookmarkNode* other_folder_node, - int* max_id, const Value& value); // Decodes the children of the specified node. Returns true on success. @@ -160,11 +161,12 @@ class BookmarkCodec { void InitializeChecksum(); void FinalizeChecksum(); - // Whether to persist IDs or not. - bool persist_ids_; // Unique ID generator used during decoding. UniqueIDGenerator id_generator_; + // Whether or not IDs were reassigned by the codec. + bool ids_reassigned_; + // MD5 context used to compute MD5 hash of all bookmark data. MD5Context md5_context_; diff --git a/chrome/browser/bookmarks/bookmark_codec_unittest.cc b/chrome/browser/bookmarks/bookmark_codec_unittest.cc index d6a3424..ed3996e 100644 --- a/chrome/browser/bookmarks/bookmark_codec_unittest.cc +++ b/chrome/browser/bookmarks/bookmark_codec_unittest.cc @@ -106,7 +106,7 @@ class BookmarkCodecTest : public testing::Test { } bool Decode(BookmarkCodec* codec, BookmarkModel* model, const Value& value) { - int max_id; + int64 max_id; bool result = codec->Decode(AsMutable(model->GetBookmarkBarNode()), AsMutable(model->other_node()), &max_id, value); @@ -201,11 +201,11 @@ TEST_F(BookmarkCodecTest, ChecksumManualEditTest) { TEST_F(BookmarkCodecTest, PersistIDsTest) { scoped_ptr<BookmarkModel> model_to_encode(CreateTestModel3()); - BookmarkCodec encoder(true); + BookmarkCodec encoder; scoped_ptr<Value> model_value(encoder.Encode(model_to_encode.get())); BookmarkModel decoded_model(NULL); - BookmarkCodec decoder(true); + BookmarkCodec decoder; ASSERT_TRUE(Decode(&decoder, &decoded_model, *model_value.get())); BookmarkModelTestUtils::AssertModelsEqual(model_to_encode.get(), &decoded_model, @@ -220,11 +220,11 @@ TEST_F(BookmarkCodecTest, PersistIDsTest) { bookmark_bar, bookmark_bar->GetChildCount(), kGroup2Title); decoded_model.AddURL(group2_node, 0, kUrl4Title, GURL(kUrl4Url)); - BookmarkCodec encoder2(true); + BookmarkCodec encoder2; scoped_ptr<Value> model_value2(encoder2.Encode(&decoded_model)); BookmarkModel decoded_model2(NULL); - BookmarkCodec decoder2(true); + BookmarkCodec decoder2; ASSERT_TRUE(Decode(&decoder2, &decoded_model2, *model_value2.get())); BookmarkModelTestUtils::AssertModelsEqual(&decoded_model, &decoded_model2, @@ -235,17 +235,17 @@ class UniqueIDGeneratorTest : public testing::Test { protected: void TestMixed(UniqueIDGenerator* gen) { // Few unique numbers. - for (int i = 1; i <= 5; ++i) { + for (int64 i = 1; i <= 5; ++i) { EXPECT_EQ(i, gen->GetUniqueID(i)); } // All numbers from 1 to 5 should produce numbers 6 to 10. - for (int i = 1; i <= 5; ++i) { + for (int64 i = 1; i <= 5; ++i) { EXPECT_EQ(5 + i, gen->GetUniqueID(i)); } // 10 should produce 11, then 11 should produce 12, and so on. - for (int i = 1; i <= 5; ++i) { + for (int64 i = 1; i <= 5; ++i) { EXPECT_EQ(10 + i, gen->GetUniqueID(9 + i)); } @@ -272,14 +272,14 @@ class UniqueIDGeneratorTest : public testing::Test { TEST_F(UniqueIDGeneratorTest, SerialNumbersTest) { UniqueIDGenerator gen; - for (int i = 1; i <= 10; ++i) { + for (int64 i = 1; i <= 10; ++i) { EXPECT_EQ(i, gen.GetUniqueID(i)); } } TEST_F(UniqueIDGeneratorTest, UniqueSortedNumbersTest) { UniqueIDGenerator gen; - for (int i = 1; i <= 10; i += 2) { + for (int64 i = 1; i <= 10; i += 2) { EXPECT_EQ(i, gen.GetUniqueID(i)); } } @@ -287,7 +287,7 @@ TEST_F(UniqueIDGeneratorTest, UniqueSortedNumbersTest) { TEST_F(UniqueIDGeneratorTest, UniqueUnsortedConsecutiveNumbersTest) { UniqueIDGenerator gen; int numbers[] = {2, 10, 6, 3, 8, 5, 1, 7, 4, 9}; - for (int i = 0; i < ARRAYSIZE(numbers); ++i) { + for (int64 i = 0; i < ARRAYSIZE(numbers); ++i) { EXPECT_EQ(numbers[i], gen.GetUniqueID(numbers[i])); } } @@ -295,14 +295,14 @@ TEST_F(UniqueIDGeneratorTest, UniqueUnsortedConsecutiveNumbersTest) { TEST_F(UniqueIDGeneratorTest, UniqueUnsortedNumbersTest) { UniqueIDGenerator gen; int numbers[] = {20, 100, 60, 30, 80, 50, 10, 70, 40, 90}; - for (int i = 0; i < ARRAYSIZE(numbers); ++i) { + for (int64 i = 0; i < ARRAYSIZE(numbers); ++i) { EXPECT_EQ(numbers[i], gen.GetUniqueID(numbers[i])); } } TEST_F(UniqueIDGeneratorTest, AllDuplicatesTest) { UniqueIDGenerator gen; - for (int i = 1; i <= 10; ++i) { + for (int64 i = 1; i <= 10; ++i) { EXPECT_EQ(i, gen.GetUniqueID(1)); } } @@ -314,7 +314,7 @@ TEST_F(UniqueIDGeneratorTest, MixedTest) { TEST_F(UniqueIDGeneratorTest, ResetTest) { UniqueIDGenerator gen; - for (int i = 0; i < 5; ++i) { + for (int64 i = 0; i < 5; ++i) { TestMixed(&gen); gen.Reset(); } diff --git a/chrome/browser/bookmarks/bookmark_drag_data.cc b/chrome/browser/bookmarks/bookmark_drag_data.cc index 732d119..bf3ae05 100644 --- a/chrome/browser/bookmarks/bookmark_drag_data.cc +++ b/chrome/browser/bookmarks/bookmark_drag_data.cc @@ -41,7 +41,7 @@ void BookmarkDragData::Element::WriteToPickle(Pickle* pickle) const { pickle->WriteBool(is_url); pickle->WriteString(url.spec()); pickle->WriteWString(title); - pickle->WriteInt(id_); + pickle->WriteInt64(id_); if (!is_url) { pickle->WriteSize(children.size()); for (std::vector<Element>::const_iterator i = children.begin(); @@ -57,7 +57,7 @@ bool BookmarkDragData::Element::ReadFromPickle(Pickle* pickle, if (!pickle->ReadBool(iterator, &is_url) || !pickle->ReadString(iterator, &url_spec) || !pickle->ReadWString(iterator, &title) || - !pickle->ReadInt(iterator, &id_)) { + !pickle->ReadInt64(iterator, &id_)) { return false; } url = GURL(url_spec); diff --git a/chrome/browser/bookmarks/bookmark_drag_data.h b/chrome/browser/bookmarks/bookmark_drag_data.h index 88cb6d4..9af3c20 100644 --- a/chrome/browser/bookmarks/bookmark_drag_data.h +++ b/chrome/browser/bookmarks/bookmark_drag_data.h @@ -62,7 +62,7 @@ struct BookmarkDragData { bool ReadFromPickle(Pickle* pickle, void** iterator); // ID of the node. - int id_; + int64 id_; }; BookmarkDragData() { } diff --git a/chrome/browser/bookmarks/bookmark_model.cc b/chrome/browser/bookmarks/bookmark_model.cc index 5d87da1..9bcc8c3 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(int id, const GURL& url) +BookmarkNode::BookmarkNode(int64 id, const GURL& url) : url_(url){ Initialize(id); } -void BookmarkNode::Initialize(int id) { +void BookmarkNode::Initialize(int64 id) { id_ = id; loaded_favicon_ = false; favicon_load_handle_ = 0; @@ -77,9 +77,6 @@ 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*, @@ -110,7 +107,6 @@ 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), @@ -122,8 +118,6 @@ BookmarkModel::BookmarkModel(Profile* profile) // Profile is null during testing. DoneLoading(CreateLoadDetails()); } - RegisterPreferences(); - LoadPreferences(); } BookmarkModel::~BookmarkModel() { @@ -282,7 +276,7 @@ bool BookmarkModel::IsBookmarked(const GURL& url) { return IsBookmarkedNoLock(url); } -const BookmarkNode* BookmarkModel::GetNodeByID(int id) { +const BookmarkNode* BookmarkModel::GetNodeByID(int64 id) { // TODO(sky): TreeNode needs a method that visits all nodes using a predicate. return GetNodeByID(&root_, id); } @@ -408,19 +402,6 @@ 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) != @@ -477,6 +458,15 @@ 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(); @@ -587,7 +577,7 @@ void BookmarkModel::BlockTillLoaded() { } const BookmarkNode* BookmarkModel::GetNodeByID(const BookmarkNode* node, - int id) { + int64 id) { if (node->id() == id) return node; @@ -725,18 +715,12 @@ void BookmarkModel::PopulateNodesByURL(BookmarkNode* node) { PopulateNodesByURL(node->GetChild(i)); } -int BookmarkModel::generate_next_node_id() { +int64 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() { @@ -745,18 +729,3 @@ 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 9726624..c8ba083 100644 --- a/chrome/browser/bookmarks/bookmark_model.h +++ b/chrome/browser/bookmarks/bookmark_model.h @@ -53,19 +53,18 @@ class BookmarkNode : public TreeNode<BookmarkNode> { // Creates a new node with the specified url and id of 0 explicit BookmarkNode(const GURL& url); // Creates a new node with the specified url and id. - BookmarkNode(int id, const GURL& url); + BookmarkNode(int64 id, const GURL& url); virtual ~BookmarkNode() {} // Returns the URL. const GURL& GetURL() const { return url_; } // Returns a unique id for this node. - // - // NOTE: this id is only unique for the session and NOT unique across - // sessions. Don't persist it! - int id() const { return id_; } + // For bookmark nodes that are managed by the bookmark model, the IDs are + // persisted across sessions. + int64 id() const { return id_; } // Sets the id to the given value. - void set_id(int id) { id_ = id; } + void set_id(int64 id) { id_ = id; } // Returns the type of this node. BookmarkNode::Type GetType() const { return type_; } @@ -126,10 +125,10 @@ class BookmarkNode : public TreeNode<BookmarkNode> { private: // helper to initialize various fields during construction. - void Initialize(int id); + void Initialize(int64 id); // Unique identifier for this node. - int id_; + int64 id_; // Whether the favicon has been loaded. bool loaded_favicon_; @@ -292,7 +291,7 @@ class BookmarkModel : public NotificationObserver, public BookmarkService { // Returns the node with the specified id, or NULL if there is no node with // the specified id. - const BookmarkNode* GetNodeByID(int id); + const BookmarkNode* GetNodeByID(int64 id); // Adds a new group node at the specified position. const BookmarkNode* AddGroup(const BookmarkNode* parent, @@ -355,10 +354,6 @@ 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); - // Returns whether the bookmarks file changed externally. bool file_changed() const { return file_changed_; } @@ -404,7 +399,7 @@ class BookmarkModel : public NotificationObserver, public BookmarkService { bool was_bookmarked); // Implementation of GetNodeByID. - const BookmarkNode* GetNodeByID(const BookmarkNode* node, int id); + const BookmarkNode* GetNodeByID(const BookmarkNode* node, int64 id); // Returns true if the parent and index are valid. bool IsValidIndex(const BookmarkNode* parent, int index, bool allow_end); @@ -444,13 +439,12 @@ class BookmarkModel : public NotificationObserver, public BookmarkService { const NotificationDetails& details); // Generates and returns the next node ID. - int generate_next_node_id(); + int64 generate_next_node_id(); // Sets the maximum node ID to the given value. // This is used by BookmarkCodec to report the maximum ID after it's done - // decoding since during decoding codec can assign IDs to nodes if IDs are - // persisted. - void set_next_node_id(int id) { next_node_id_ = id; } + // decoding since during decoding codec assigns node IDs. + void set_next_node_id(int64 id) { next_node_id_ = id; } // Records that the bookmarks file was changed externally. void SetFileChanged(); @@ -459,11 +453,6 @@ 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_; @@ -471,9 +460,6 @@ 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_; - // Whether the bookmarks file was changed externally. This is set after // loading is complete and once set the value never changes. bool file_changed_; @@ -486,7 +472,7 @@ class BookmarkModel : public NotificationObserver, public BookmarkService { BookmarkNode* other_node_; // The maximum ID assigned to the bookmark nodes in the model. - int next_node_id_; + int64 next_node_id_; // The observers. ObserverList<BookmarkModelObserver> observers_; diff --git a/chrome/browser/bookmarks/bookmark_model_unittest.cc b/chrome/browser/bookmarks/bookmark_model_unittest.cc index 05d0843..627a058 100644 --- a/chrome/browser/bookmarks/bookmark_model_unittest.cc +++ b/chrome/browser/bookmarks/bookmark_model_unittest.cc @@ -593,7 +593,7 @@ class BookmarkModelTestWithProfile : public testing::Test, void VerifyNoDuplicateIDs(BookmarkModel* model) { TreeNodeIterator<const BookmarkNode> it(model->root_node()); - base::hash_set<int> ids; + base::hash_set<int64> ids; while (it.has_next()) ASSERT_TRUE(ids.insert(it.Next()->id()).second); } diff --git a/chrome/browser/bookmarks/bookmark_storage.cc b/chrome/browser/bookmarks/bookmark_storage.cc index a530158..d7dbe19 100644 --- a/chrome/browser/bookmarks/bookmark_storage.cc +++ b/chrome/browser/bookmarks/bookmark_storage.cc @@ -68,13 +68,11 @@ class BookmarkStorage::LoadTask : public Task { LoadTask(const FilePath& path, MessageLoop* loop, BookmarkStorage* storage, - LoadDetails* details, - bool persist_ids) + LoadDetails* details) : path_(path), loop_(loop), storage_(storage), - details_(details), - persist_ids_(persist_ids) { + details_(details) { } virtual void Run() { @@ -86,14 +84,15 @@ class BookmarkStorage::LoadTask : public Task { if (root.get()) { // Building the index cane take a while, so we do it on the background // thread. - int max_node_id = 0; - BookmarkCodec codec(persist_ids_); + int64 max_node_id = 0; + BookmarkCodec codec; TimeTicks start_time = TimeTicks::Now(); codec.Decode(details_->bb_node(), details_->other_folder_node(), &max_node_id, *root.get()); details_->set_max_id(std::max(max_node_id, details_->max_id())); details_->set_computed_checksum(codec.computed_checksum()); details_->set_stored_checksum(codec.stored_checksum()); + details_->set_ids_reassigned(codec.ids_reassigned()); UMA_HISTOGRAM_TIMES("Bookmarks.DecodeTime", TimeTicks::Now() - start_time); @@ -129,7 +128,6 @@ class BookmarkStorage::LoadTask : public Task { MessageLoop* loop_; scoped_refptr<BookmarkStorage> storage_; LoadDetails* details_; - bool persist_ids_; DISALLOW_COPY_AND_ASSIGN(LoadTask); }; @@ -164,8 +162,7 @@ void BookmarkStorage::DoLoadBookmarks(const FilePath& path) { Task* task = new LoadTask(path, backend_thread() ? MessageLoop::current() : NULL, this, - details_.get(), - model_->PersistIDs()); + details_.get()); RunTaskOnBackendThread(task); } @@ -211,7 +208,7 @@ void BookmarkStorage::BookmarkModelDeleted() { } bool BookmarkStorage::SerializeData(std::string* output) { - BookmarkCodec codec(model_->PersistIDs()); + BookmarkCodec codec; scoped_ptr<Value> value(codec.Encode(model_)); JSONStringValueSerializer serializer(output); serializer.set_pretty_print(true); diff --git a/chrome/browser/bookmarks/bookmark_storage.h b/chrome/browser/bookmarks/bookmark_storage.h index cc18b60..0ad633e 100644 --- a/chrome/browser/bookmarks/bookmark_storage.h +++ b/chrome/browser/bookmarks/bookmark_storage.h @@ -44,7 +44,7 @@ class BookmarkStorage : public NotificationObserver, LoadDetails(BookmarkNode* bb_node, BookmarkNode* other_folder_node, BookmarkIndex* index, - int max_id) + int64 max_id) : bb_node_(bb_node), other_folder_node_(other_folder_node), index_(index), @@ -62,8 +62,8 @@ class BookmarkStorage : public NotificationObserver, BookmarkIndex* index() { return index_.get(); } // Max id of the nodes. - void set_max_id(int max_id) { max_id_ = max_id; } - int max_id() const { return max_id_; } + void set_max_id(int64 max_id) { max_id_ = max_id; } + int64 max_id() const { return max_id_; } // Computed checksum. void set_computed_checksum(const std::string& value) { @@ -77,13 +77,18 @@ class BookmarkStorage : public NotificationObserver, } const std::string& stored_checksum() const { return stored_checksum_; } + // Whether ids were reassigned. + void set_ids_reassigned(bool value) { ids_reassigned_ = value; } + bool ids_reassigned() const { return ids_reassigned_; } + private: scoped_ptr<BookmarkNode> bb_node_; scoped_ptr<BookmarkNode> other_folder_node_; scoped_ptr<BookmarkIndex> index_; - int max_id_; + int64 max_id_; std::string computed_checksum_; std::string stored_checksum_; + bool ids_reassigned_; DISALLOW_COPY_AND_ASSIGN(LoadDetails); }; diff --git a/chrome/browser/extensions/extension_bookmarks_module.cc b/chrome/browser/extensions/extension_bookmarks_module.cc index 9c9d635..808050a 100644 --- a/chrome/browser/extensions/extension_bookmarks_module.cc +++ b/chrome/browser/extensions/extension_bookmarks_module.cc @@ -5,6 +5,7 @@ #include "chrome/browser/extensions/extension_bookmarks_module.h" #include "base/json_writer.h" +#include "base/string_util.h" #include "chrome/browser/bookmarks/bookmark_codec.h" #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/bookmarks/bookmark_utils.h" @@ -25,11 +26,11 @@ class ExtensionBookmarks { static DictionaryValue* GetNodeDictionary(const BookmarkNode* node, bool recurse) { DictionaryValue* dict = new DictionaryValue(); - dict->SetInteger(keys::kIdKey, node->id()); + dict->SetString(keys::kIdKey, Int64ToString(node->id())); const BookmarkNode* parent = node->GetParent(); if (parent) - dict->SetInteger(keys::kParentIdKey, parent->id()); + dict->SetString(keys::kParentIdKey, Int64ToString(parent->id())); if (!node->is_folder()) { dict->SetString(keys::kUrlKey, node->GetURL().spec()); @@ -68,7 +69,7 @@ class ExtensionBookmarks { list->Append(dict); } - static bool RemoveNode(BookmarkModel* model, int id, bool recursive, + static bool RemoveNode(BookmarkModel* model, int64 id, bool recursive, std::string* error) { const BookmarkNode* node = model->GetNodeByID(id); if (!node) { @@ -114,6 +115,15 @@ void BookmarksFunction::Run() { SendResponse(RunImpl()); } +bool BookmarksFunction::GetBookmarkIdAsInt64( + const std::string& id_string, int64* id) { + if (StringToInt64(id_string, id)) + return true; + + error_ = keys::kInvalidIdError; + return false; +} + void BookmarksFunction::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { @@ -161,11 +171,12 @@ void ExtensionBookmarkEventRouter::BookmarkNodeMoved( int new_index) { ListValue args; const BookmarkNode* node = new_parent->GetChild(new_index); - args.Append(new FundamentalValue(node->id())); + args.Append(new StringValue(Int64ToString(node->id()))); DictionaryValue* object_args = new DictionaryValue(); - object_args->SetInteger(keys::kParentIdKey, new_parent->id()); + object_args->SetString(keys::kParentIdKey, Int64ToString(new_parent->id())); object_args->SetInteger(keys::kIndexKey, new_index); - object_args->SetInteger(keys::kOldParentIdKey, old_parent->id()); + object_args->SetString(keys::kOldParentIdKey, + Int64ToString(old_parent->id())); object_args->SetInteger(keys::kOldIndexKey, old_index); args.Append(object_args); @@ -179,7 +190,7 @@ void ExtensionBookmarkEventRouter::BookmarkNodeAdded(BookmarkModel* model, int index) { ListValue args; const BookmarkNode* node = parent->GetChild(index); - args.Append(new FundamentalValue(node->id())); + args.Append(new StringValue(Int64ToString(node->id()))); DictionaryValue* obj = ExtensionBookmarks::GetNodeDictionary(node, false); // Remove id since it's already being passed as the first argument. @@ -205,9 +216,9 @@ void ExtensionBookmarkEventRouter::BookmarkNodeRemoved( int index, const BookmarkNode* node) { ListValue args; - args.Append(new FundamentalValue(node->id())); + args.Append(new StringValue(Int64ToString(node->id()))); DictionaryValue* object_args = new DictionaryValue(); - object_args->SetInteger(keys::kParentIdKey, parent->id()); + object_args->SetString(keys::kParentIdKey, Int64ToString(parent->id())); object_args->SetInteger(keys::kIndexKey, index); args.Append(object_args); @@ -219,7 +230,7 @@ void ExtensionBookmarkEventRouter::BookmarkNodeRemoved( void ExtensionBookmarkEventRouter::BookmarkNodeChanged( BookmarkModel* model, const BookmarkNode* node) { ListValue args; - args.Append(new FundamentalValue(node->id())); + args.Append(new StringValue(Int64ToString(node->id()))); // TODO(erikkay) The only two things that BookmarkModel sends this // notification for are title and favicon. Since we're currently ignoring @@ -243,12 +254,12 @@ void ExtensionBookmarkEventRouter::BookmarkNodeFavIconLoaded( void ExtensionBookmarkEventRouter::BookmarkNodeChildrenReordered( BookmarkModel* model, const BookmarkNode* node) { ListValue args; - args.Append(new FundamentalValue(node->id())); + args.Append(new StringValue(Int64ToString(node->id()))); int childCount = node->GetChildCount(); ListValue* children = new ListValue(); for (int i = 0; i < childCount; ++i) { const BookmarkNode* child = node->GetChild(i); - Value* child_id = new FundamentalValue(child->id()); + Value* child_id = new StringValue(Int64ToString(child->id())); children->Append(child_id); } args.Append(children); @@ -268,8 +279,11 @@ bool GetBookmarksFunction::RunImpl() { size_t count = ids->GetSize(); EXTENSION_FUNCTION_VALIDATE(count > 0); for (size_t i = 0; i < count; ++i) { - int id = 0; - EXTENSION_FUNCTION_VALIDATE(ids->GetInteger(i, &id)); + int64 id; + std::string id_string; + EXTENSION_FUNCTION_VALIDATE(ids->GetString(i, &id_string)); + if (!GetBookmarkIdAsInt64(id_string, &id)) + return false; const BookmarkNode* node = model->GetNodeByID(id); if (!node) { error_ = keys::kNoNodeError; @@ -279,8 +293,11 @@ bool GetBookmarksFunction::RunImpl() { } } } else { - int id; - EXTENSION_FUNCTION_VALIDATE(args_->GetAsInteger(&id)); + int64 id; + std::string id_string; + EXTENSION_FUNCTION_VALIDATE(args_->GetAsString(&id_string)); + if (!GetBookmarkIdAsInt64(id_string, &id)) + return false; const BookmarkNode* node = model->GetNodeByID(id); if (!node) { error_ = keys::kNoNodeError; @@ -295,8 +312,11 @@ bool GetBookmarksFunction::RunImpl() { bool GetBookmarkChildrenFunction::RunImpl() { BookmarkModel* model = profile()->GetBookmarkModel(); - int id; - EXTENSION_FUNCTION_VALIDATE(args_->GetAsInteger(&id)); + int64 id; + std::string id_string; + EXTENSION_FUNCTION_VALIDATE(args_->GetAsString(&id_string)); + if (!GetBookmarkIdAsInt64(id_string, &id)) + return false; scoped_ptr<ListValue> json(new ListValue()); const BookmarkNode* node = model->GetNodeByID(id); if (!node) { @@ -350,8 +370,9 @@ bool RemoveBookmarkFunction::RunImpl() { EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(1, &recursive)); BookmarkModel* model = profile()->GetBookmarkModel(); - int id; - if (args->GetInteger(0, &id)) { + int64 id; + std::string id_string; + if (args->GetString(0, &id_string) && StringToInt64(id_string, &id)) { return ExtensionBookmarks::RemoveNode(model, id, recursive, &error_); } else { ListValue* ids; @@ -359,7 +380,9 @@ bool RemoveBookmarkFunction::RunImpl() { size_t count = ids->GetSize(); EXTENSION_FUNCTION_VALIDATE(count > 0); for (size_t i = 0; i < count; ++i) { - EXTENSION_FUNCTION_VALIDATE(ids->GetInteger(i, &id)); + EXTENSION_FUNCTION_VALIDATE(ids->GetString(i, &id_string)); + if (!GetBookmarkIdAsInt64(id_string, &id)) + return false; if (!ExtensionBookmarks::RemoveNode(model, id, recursive, &error_)) return false; } @@ -372,13 +395,16 @@ bool CreateBookmarkFunction::RunImpl() { DictionaryValue* json = static_cast<DictionaryValue*>(args_); BookmarkModel* model = profile()->GetBookmarkModel(); - int parentId; + int64 parentId; if (!json->HasKey(keys::kParentIdKey)) { // Optional, default to "other bookmarks". parentId = model->other_node()->id(); } else { - EXTENSION_FUNCTION_VALIDATE(json->GetInteger(keys::kParentIdKey, - &parentId)); + std::string parentId_string; + EXTENSION_FUNCTION_VALIDATE(json->GetString(keys::kParentIdKey, + &parentId_string)); + if (!GetBookmarkIdAsInt64(parentId_string, &parentId)) + return false; } const BookmarkNode* parent = model->GetNodeByID(parentId); if (!parent) { @@ -431,8 +457,11 @@ bool CreateBookmarkFunction::RunImpl() { bool MoveBookmarkFunction::RunImpl() { EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST)); const ListValue* args = static_cast<const ListValue*>(args_); - int id; - EXTENSION_FUNCTION_VALIDATE(args->GetInteger(0, &id)); + int64 id; + std::string id_string; + EXTENSION_FUNCTION_VALIDATE(args->GetString(0, &id_string)); + if (!GetBookmarkIdAsInt64(id_string, &id)) + return false; DictionaryValue* destination; EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(1, &destination)); @@ -493,8 +522,11 @@ bool SetBookmarkTitleFunction::RunImpl() { json->GetString(keys::kTitleKey, &title); // Optional (empty is clear). BookmarkModel* model = profile()->GetBookmarkModel(); - int id = 0; - EXTENSION_FUNCTION_VALIDATE(json->GetInteger(keys::kIdKey, &id)); + int64 id = 0; + std::string id_string; + EXTENSION_FUNCTION_VALIDATE(json->GetString(keys::kIdKey, &id_string)); + if (!GetBookmarkIdAsInt64(id_string, &id)) + return false; const BookmarkNode* node = model->GetNodeByID(id); if (!node) { error_ = keys::kNoNodeError; diff --git a/chrome/browser/extensions/extension_bookmarks_module.h b/chrome/browser/extensions/extension_bookmarks_module.h index cfa32de..7cfc1ca2 100644 --- a/chrome/browser/extensions/extension_bookmarks_module.h +++ b/chrome/browser/extensions/extension_bookmarks_module.h @@ -70,6 +70,12 @@ class BookmarksFunction : public AsyncExtensionFunction, virtual void Run(); virtual bool RunImpl() = 0; + protected: + // Helper to get the bookmark id as int64 from the given string id. + // Sets error_ to an errro string if the given id string can't be parsed + // as an int64. In case of error, doesn't change id and returns false. + bool GetBookmarkIdAsInt64(const std::string& id_string, int64* id); + private: virtual void Observe(NotificationType type, const NotificationSource& source, diff --git a/chrome/browser/extensions/extension_bookmarks_module_constants.cc b/chrome/browser/extensions/extension_bookmarks_module_constants.cc index cdf602d..24d7c92 100644 --- a/chrome/browser/extensions/extension_bookmarks_module_constants.cc +++ b/chrome/browser/extensions/extension_bookmarks_module_constants.cc @@ -22,6 +22,7 @@ const char kNoNodeError[] = "Can't find bookmark for id."; const char kNoParentError[] = "Can't find parent bookmark for id."; const char kFolderNotEmptyError[] = "Can't remove non-empty folder (use recursive to force)."; +const char kInvalidIdError[] = "Bookmark id is invalid."; const char kInvalidIndexError[] = "Index out of bounds."; const char kInvalidUrlError[] = "Invalid URL."; const char kModifySpecialError[] = "Can't modify the root bookmark folders."; diff --git a/chrome/browser/extensions/extension_bookmarks_module_constants.h b/chrome/browser/extensions/extension_bookmarks_module_constants.h index 3b504e6..665747c 100644 --- a/chrome/browser/extensions/extension_bookmarks_module_constants.h +++ b/chrome/browser/extensions/extension_bookmarks_module_constants.h @@ -26,6 +26,7 @@ extern const wchar_t kDateGroupModifiedKey[]; extern const char kNoNodeError[]; extern const char kNoParentError[]; extern const char kFolderNotEmptyError[]; +extern const char kInvalidIdError[]; extern const char kInvalidIndexError[]; extern const char kInvalidUrlError[]; extern const char kModifySpecialError[]; diff --git a/chrome/browser/gtk/bookmark_editor_gtk.cc b/chrome/browser/gtk/bookmark_editor_gtk.cc index 1a6171c..9824f44 100644 --- a/chrome/browser/gtk/bookmark_editor_gtk.cc +++ b/chrome/browser/gtk/bookmark_editor_gtk.cc @@ -152,7 +152,7 @@ void BookmarkEditorGtk::Init(GtkWindow* parent_window) { if (show_tree_) { GtkTreeIter selected_iter; - int selected_id = node_ ? node_->GetParent()->id() : 0; + int64 selected_id = node_ ? node_->GetParent()->id() : 0; tree_store_ = bookmark_utils::MakeFolderTreeStore(); bookmark_utils::AddToTreeStore(bb_model_, selected_id, tree_store_, &selected_iter); @@ -328,7 +328,7 @@ void BookmarkEditorGtk::AddNewGroup(GtkTreeIter* parent, GtkTreeIter* child) { bookmark_utils::GetFolderIcon(), bookmark_utils::FOLDER_NAME, l10n_util::GetStringUTF8(IDS_BOOMARK_EDITOR_NEW_FOLDER_NAME).c_str(), - bookmark_utils::ITEM_ID, 0, + bookmark_utils::ITEM_ID, static_cast<int64>(0), -1); } diff --git a/chrome/browser/gtk/bookmark_manager_gtk.cc b/chrome/browser/gtk/bookmark_manager_gtk.cc index d43b422..77a7c6a 100644 --- a/chrome/browser/gtk/bookmark_manager_gtk.cc +++ b/chrome/browser/gtk/bookmark_manager_gtk.cc @@ -37,8 +37,8 @@ const int kRecentlyBookmarkedCount = 50; // IDs for the recently added and search nodes. These values assume that node // IDs will be strictly non-negative, which is an implementation detail of // BookmarkModel, so this is sort of a hack. -const int kRecentID = -1; -const int kSearchID = -2; +const int64 kRecentID = -1; +const int64 kSearchID = -2; // Padding between "Search:" and the entry field, in pixels. const int kSearchPadding = 5; diff --git a/chrome/browser/gtk/bookmark_tree_model.cc b/chrome/browser/gtk/bookmark_tree_model.cc index ab3b24e..34eedb0 100644 --- a/chrome/browser/gtk/bookmark_tree_model.cc +++ b/chrome/browser/gtk/bookmark_tree_model.cc @@ -41,7 +41,7 @@ void RecursiveResolve(BookmarkModel* bb_model, const BookmarkNode* bb_node, GtkTreeIter child_iter; if (gtk_tree_model_iter_children(tree_model, &child_iter, parent_iter)) { do { - int id = bookmark_utils::GetIdFromTreeIter(tree_model, &child_iter); + int64 id = bookmark_utils::GetIdFromTreeIter(tree_model, &child_iter); std::wstring title = bookmark_utils::GetTitleFromTreeIter(tree_model, &child_iter); const BookmarkNode* child_bb_node = NULL; @@ -74,10 +74,10 @@ namespace bookmark_utils { GtkTreeStore* MakeFolderTreeStore() { return gtk_tree_store_new(FOLDER_STORE_NUM_COLUMNS, GDK_TYPE_PIXBUF, - G_TYPE_STRING, G_TYPE_INT); + G_TYPE_STRING, G_TYPE_INT64); } -void AddToTreeStore(BookmarkModel* model, int selected_id, +void AddToTreeStore(BookmarkModel* model, int64 selected_id, GtkTreeStore* store, GtkTreeIter* selected_iter) { const BookmarkNode* root_node = model->root_node(); for (int i = 0; i < root_node->GetChildCount(); ++i) { @@ -86,7 +86,7 @@ void AddToTreeStore(BookmarkModel* model, int selected_id, } } -void AddToTreeStoreAt(const BookmarkNode* node, int selected_id, +void AddToTreeStoreAt(const BookmarkNode* node, int64 selected_id, GtkTreeStore* store, GtkTreeIter* selected_iter, GtkTreeIter* parent) { if (!node->is_folder()) @@ -128,7 +128,7 @@ const BookmarkNode* CommitTreeStoreDifferencesBetween( DCHECK(GetIdFromTreeIter(tree_model, &tree_root) != 0) << "It should be impossible to add another toplevel node"; - int id = GetIdFromTreeIter(tree_model, &tree_root); + int64 id = GetIdFromTreeIter(tree_model, &tree_root); const BookmarkNode* child_node = NULL; for (int j = 0; j < root_node->GetChildCount(); ++j) { const BookmarkNode* node = root_node->GetChild(j); @@ -148,12 +148,12 @@ const BookmarkNode* CommitTreeStoreDifferencesBetween( return node_to_return; } -int GetIdFromTreeIter(GtkTreeModel* model, GtkTreeIter* iter) { +int64 GetIdFromTreeIter(GtkTreeModel* model, GtkTreeIter* iter) { GValue value = { 0, }; - int ret_val = -1; + int64 ret_val = -1; gtk_tree_model_get_value(model, iter, ITEM_ID, &value); - if (G_VALUE_HOLDS_INT(&value)) - ret_val = g_value_get_int(&value); + if (G_VALUE_HOLDS_INT64(&value)) + ret_val = g_value_get_int64(&value); else NOTREACHED() << "Impossible type mismatch"; diff --git a/chrome/browser/gtk/bookmark_tree_model.h b/chrome/browser/gtk/bookmark_tree_model.h index c691212..96e9fd5 100644 --- a/chrome/browser/gtk/bookmark_tree_model.h +++ b/chrome/browser/gtk/bookmark_tree_model.h @@ -6,6 +6,7 @@ #define CHROME_BROWSER_GTK_BOOKMARK_TREE_MODEL_H_ #include <string> +#include "base/basictypes.h" class BookmarkModel; class BookmarkNode; @@ -36,12 +37,12 @@ GtkTreeStore* MakeFolderTreeStore(); // |recursive| indicates whether to recurse into sub-directories (if false, // the tree store will effectively be a list). |only_folders| indicates whether // to include bookmarks in the tree, or to only show folders. -void AddToTreeStore(BookmarkModel* model, int selected_id, +void AddToTreeStore(BookmarkModel* model, int64 selected_id, GtkTreeStore* store, GtkTreeIter* selected_iter); // As above, but inserts just the tree rooted at |node| as a child of |parent|. // If |parent| is NULL, add it at the top level. -void AddToTreeStoreAt(const BookmarkNode* node, int selected_id, +void AddToTreeStoreAt(const BookmarkNode* node, int64 selected_id, GtkTreeStore* store, GtkTreeIter* selected_iter, GtkTreeIter* parent); @@ -53,7 +54,7 @@ const BookmarkNode* CommitTreeStoreDifferencesBetween( GtkTreeIter* selected); // Returns the id field of the row pointed to by |iter|. -int GetIdFromTreeIter(GtkTreeModel* model, GtkTreeIter* iter); +int64 GetIdFromTreeIter(GtkTreeModel* model, GtkTreeIter* iter); // Returns the title field of the row pointed to by |iter|. std::wstring GetTitleFromTreeIter(GtkTreeModel* model, GtkTreeIter* iter); diff --git a/chrome/browser/views/bookmark_editor_view.cc b/chrome/browser/views/bookmark_editor_view.cc index 5843504..9001d2b 100644 --- a/chrome/browser/views/bookmark_editor_view.cc +++ b/chrome/browser/views/bookmark_editor_view.cc @@ -443,7 +443,7 @@ void BookmarkEditorView::ExpandAndSelect() { tree_view_->ExpandAll(); const BookmarkNode* to_select = node_ ? node_->GetParent() : parent_; - int group_id_to_select = to_select->id(); + int64 group_id_to_select = to_select->id(); DCHECK(group_id_to_select); // GetMostRecentParent should never return NULL. EditorNode* b_node = FindNodeWithID(tree_model_->GetRoot(), group_id_to_select); @@ -478,7 +478,7 @@ void BookmarkEditorView::CreateNodes(const BookmarkNode* bb_node, BookmarkEditorView::EditorNode* BookmarkEditorView::FindNodeWithID( BookmarkEditorView::EditorNode* node, - int id) { + int64 id) { if (node->value == id) return node; for (int i = 0; i < node->GetChildCount(); ++i) { diff --git a/chrome/browser/views/bookmark_editor_view.h b/chrome/browser/views/bookmark_editor_view.h index a03d3e9..98f5269 100644 --- a/chrome/browser/views/bookmark_editor_view.h +++ b/chrome/browser/views/bookmark_editor_view.h @@ -113,7 +113,7 @@ class BookmarkEditorView : public BookmarkEditor, private: // Type of node in the tree. - typedef TreeNodeWithValue<int> EditorNode; + typedef TreeNodeWithValue<int64> EditorNode; // Model for the TreeView. Trivial subclass that doesn't allow titles with // empty strings. @@ -175,7 +175,7 @@ class BookmarkEditorView : public BookmarkEditor, void CreateNodes(const BookmarkNode* bb_node, EditorNode* b_node); // Returns the node with the specified id, or NULL if one can't be found. - EditorNode* FindNodeWithID(BookmarkEditorView::EditorNode* node, int id); + EditorNode* FindNodeWithID(BookmarkEditorView::EditorNode* node, int64 id); // Invokes ApplyEdits with the selected node. void ApplyEdits(); |