Commit a8d71b03 authored by tim@chromium.org's avatar tim@chromium.org

Have the ApplyEdit* bookmark utilities return the BookmarkNode pointer

so that callers know whether or not the original BookmarkNode* passed in
is still valid or not.

Review URL: http://codereview.chromium.org/149140

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19999 0039d316-1c4b-4281-b951-d872f2087c98
parent 776fa7c1
...@@ -513,12 +513,10 @@ bool DoesBookmarkContainText(const BookmarkNode* node, ...@@ -513,12 +513,10 @@ bool DoesBookmarkContainText(const BookmarkNode* node,
return (node->is_url() && DoesBookmarkContainWords(node, words, languages)); return (node->is_url() && DoesBookmarkContainWords(node, words, languages));
} }
void ApplyEditsWithNoGroupChange(BookmarkModel* model, const BookmarkNode* ApplyEditsWithNoGroupChange(BookmarkModel* model,
const BookmarkNode* parent, const BookmarkNode* parent, const BookmarkNode* node,
const BookmarkNode* node, const std::wstring& new_title, const GURL& new_url,
const std::wstring& new_title, BookmarkEditor::Handler* handler) {
const GURL& new_url,
BookmarkEditor::Handler* handler) {
const BookmarkNode* old_parent = node ? node->GetParent() : NULL; const BookmarkNode* old_parent = node ? node->GetParent() : NULL;
const int old_index = old_parent ? old_parent->IndexOfChild(node) : -1; const int old_index = old_parent ? old_parent->IndexOfChild(node) : -1;
...@@ -528,49 +526,49 @@ void ApplyEditsWithNoGroupChange(BookmarkModel* model, ...@@ -528,49 +526,49 @@ void ApplyEditsWithNoGroupChange(BookmarkModel* model,
if (handler) if (handler)
handler->NodeCreated(node); handler->NodeCreated(node);
return; return node;
} }
// If we're not showing the tree we only need to modify the node. // If we're not showing the tree we only need to modify the node.
if (old_index == -1) { if (old_index == -1) {
NOTREACHED(); NOTREACHED();
return; return node;
} }
if (new_url != node->GetURL()) { if (new_url != node->GetURL()) {
model->AddURLWithCreationTime(old_parent, old_index, new_title, const BookmarkNode* new_node = model->AddURLWithCreationTime(old_parent,
new_url, node->date_added()); old_index, new_title, new_url, node->date_added());
model->Remove(old_parent, old_index + 1); model->Remove(old_parent, old_index + 1);
return new_node;
} else { } else {
model->SetTitle(node, new_title); model->SetTitle(node, new_title);
} }
return node;
} }
void ApplyEditsWithPossibleGroupChange(BookmarkModel* model, const BookmarkNode* ApplyEditsWithPossibleGroupChange(BookmarkModel* model,
const BookmarkNode* new_parent, const BookmarkNode* new_parent, const BookmarkNode* node,
const BookmarkNode* node, const std::wstring& new_title, const GURL& new_url,
const std::wstring& new_title, BookmarkEditor::Handler* handler) {
const GURL& new_url,
BookmarkEditor::Handler* handler) {
const BookmarkNode* old_parent = node ? node->GetParent() : NULL; const BookmarkNode* old_parent = node ? node->GetParent() : NULL;
const int old_index = old_parent ? old_parent->IndexOfChild(node) : -1; const int old_index = old_parent ? old_parent->IndexOfChild(node) : -1;
const BookmarkNode* return_node = node;
if (node) { if (node) {
Time date_added = node->date_added(); Time date_added = node->date_added();
if (new_parent == node->GetParent()) { if (new_parent == node->GetParent()) {
// The parent is the same. // The parent is the same.
if (new_url != node->GetURL()) { if (new_url != node->GetURL()) {
model->Remove(old_parent, old_index); model->Remove(old_parent, old_index);
model->AddURLWithCreationTime(old_parent, old_index, return_node = model->AddURLWithCreationTime(old_parent, old_index,
new_title, new_url, date_added); new_title, new_url, date_added);
} else { } else {
model->SetTitle(node, new_title); model->SetTitle(node, new_title);
} }
} else if (new_url != node->GetURL()) { } else if (new_url != node->GetURL()) {
// The parent and URL changed. // The parent and URL changed.
model->Remove(old_parent, old_index); model->Remove(old_parent, old_index);
model->AddURLWithCreationTime(new_parent, new_parent->GetChildCount(), return_node = model->AddURLWithCreationTime(new_parent,
new_title, new_url, date_added); new_parent->GetChildCount(), new_title, new_url, date_added);
} else { } else {
// The parent and title changed. Move the node and change the title. // The parent and title changed. Move the node and change the title.
model->Move(node, new_parent, new_parent->GetChildCount()); model->Move(node, new_parent, new_parent->GetChildCount());
...@@ -578,12 +576,13 @@ void ApplyEditsWithPossibleGroupChange(BookmarkModel* model, ...@@ -578,12 +576,13 @@ void ApplyEditsWithPossibleGroupChange(BookmarkModel* model,
} }
} else { } else {
// We're adding a new URL. // We're adding a new URL.
node = return_node =
model->AddURL(new_parent, new_parent->GetChildCount(), new_title, model->AddURL(new_parent, new_parent->GetChildCount(), new_title,
new_url); new_url);
if (handler) if (handler)
handler->NodeCreated(node); handler->NodeCreated(return_node);
} }
return return_node;
} }
// Formerly in BookmarkBarView // Formerly in BookmarkBarView
......
...@@ -142,22 +142,28 @@ bool DoesBookmarkContainText(const BookmarkNode* node, ...@@ -142,22 +142,28 @@ bool DoesBookmarkContainText(const BookmarkNode* node,
const std::wstring& languages); const std::wstring& languages);
// Modifies a bookmark node (assuming that there's no magic that needs to be // Modifies a bookmark node (assuming that there's no magic that needs to be
// done regarding moving from one folder to another). // done regarding moving from one folder to another). If the URL changed or a
void ApplyEditsWithNoGroupChange(BookmarkModel* model, // new node is explicitly being added, returns a pointer to the new node that
const BookmarkNode* parent, // was created. Otherwise the return value is identically |node|.
const BookmarkNode* node, const BookmarkNode* ApplyEditsWithNoGroupChange(
const std::wstring& new_title, BookmarkModel* model,
const GURL& new_url, const BookmarkNode* parent,
BookmarkEditor::Handler* handler); const BookmarkNode* node,
const std::wstring& new_title,
const GURL& new_url,
BookmarkEditor::Handler* handler);
// Modifies a bookmark node assuming that the parent of the node may have // Modifies a bookmark node assuming that the parent of the node may have
// changed and the node will need to be removed and reinserted. // changed and the node will need to be removed and reinserted. If the URL
void ApplyEditsWithPossibleGroupChange(BookmarkModel* model, // changed or a new node is explicitly being added, returns a pointer to the
const BookmarkNode* new_parent, // new node that was created. Otherwise the return value is identically |node|.
const BookmarkNode* node, const BookmarkNode* ApplyEditsWithPossibleGroupChange(
const std::wstring& new_title, BookmarkModel* model,
const GURL& new_url, const BookmarkNode* new_parent,
BookmarkEditor::Handler* handler); const BookmarkNode* node,
const std::wstring& new_title,
const GURL& new_url,
BookmarkEditor::Handler* handler);
// Toggles whether the bookmark bar is shown only on the new tab page or on // Toggles whether the bookmark bar is shown only on the new tab page or on
// all tabs. This is a preference modifier, not a visual modifier. // all tabs. This is a preference modifier, not a visual modifier.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment