Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: chrome/browser/extensions/api/bookmarks/bookmarks_api.cc

Issue 242823002: Extract GetNodeByID() method from BookmarkModel. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: revert a change in bookmarks_helper.cc that colides with a wstring and cq does not like that Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/api/bookmarks/bookmarks_api.h" 5 #include "chrome/browser/extensions/api/bookmarks/bookmarks_api.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/i18n/file_util_icu.h" 9 #include "base/i18n/file_util_icu.h"
10 #include "base/i18n/time_formatting.h" 10 #include "base/i18n/time_formatting.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 error_ = keys::kInvalidIdError; 124 error_ = keys::kInvalidIdError;
125 return false; 125 return false;
126 } 126 }
127 127
128 const BookmarkNode* BookmarksFunction::GetBookmarkNodeFromId( 128 const BookmarkNode* BookmarksFunction::GetBookmarkNodeFromId(
129 const std::string& id_string) { 129 const std::string& id_string) {
130 int64 id; 130 int64 id;
131 if (!GetBookmarkIdAsInt64(id_string, &id)) 131 if (!GetBookmarkIdAsInt64(id_string, &id))
132 return NULL; 132 return NULL;
133 133
134 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); 134 const BookmarkNode* node = GetBookmarkNodeByID(
135 const BookmarkNode* node = model->GetNodeByID(id); 135 BookmarkModelFactory::GetForProfile(GetProfile()), id);
136 if (!node) 136 if (!node)
137 error_ = keys::kNoNodeError; 137 error_ = keys::kNoNodeError;
138 138
139 return node; 139 return node;
140 } 140 }
141 141
142 bool BookmarksFunction::EditBookmarksEnabled() { 142 bool BookmarksFunction::EditBookmarksEnabled() {
143 PrefService* prefs = user_prefs::UserPrefs::Get(GetProfile()); 143 PrefService* prefs = user_prefs::UserPrefs::Get(GetProfile());
144 if (prefs->GetBoolean(prefs::kEditBookmarksEnabled)) 144 if (prefs->GetBoolean(prefs::kEditBookmarksEnabled))
145 return true; 145 return true;
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); 516 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile());
517 int64 parentId; 517 int64 parentId;
518 518
519 if (!params->bookmark.parent_id.get()) { 519 if (!params->bookmark.parent_id.get()) {
520 // Optional, default to "other bookmarks". 520 // Optional, default to "other bookmarks".
521 parentId = model->other_node()->id(); 521 parentId = model->other_node()->id();
522 } else { 522 } else {
523 if (!GetBookmarkIdAsInt64(*params->bookmark.parent_id, &parentId)) 523 if (!GetBookmarkIdAsInt64(*params->bookmark.parent_id, &parentId))
524 return false; 524 return false;
525 } 525 }
526 const BookmarkNode* parent = model->GetNodeByID(parentId); 526 const BookmarkNode* parent = GetBookmarkNodeByID(model, parentId);
527 if (!parent) { 527 if (!parent) {
528 error_ = keys::kNoParentError; 528 error_ = keys::kNoParentError;
529 return false; 529 return false;
530 } 530 }
531 if (parent->is_root()) { // Can't create children of the root. 531 if (parent->is_root()) { // Can't create children of the root.
532 error_ = keys::kModifySpecialError; 532 error_ = keys::kModifySpecialError;
533 return false; 533 return false;
534 } 534 }
535 535
536 int index; 536 int index;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 604
605 const BookmarkNode* parent = NULL; 605 const BookmarkNode* parent = NULL;
606 if (!params->destination.parent_id.get()) { 606 if (!params->destination.parent_id.get()) {
607 // Optional, defaults to current parent. 607 // Optional, defaults to current parent.
608 parent = node->parent(); 608 parent = node->parent();
609 } else { 609 } else {
610 int64 parentId; 610 int64 parentId;
611 if (!GetBookmarkIdAsInt64(*params->destination.parent_id, &parentId)) 611 if (!GetBookmarkIdAsInt64(*params->destination.parent_id, &parentId))
612 return false; 612 return false;
613 613
614 parent = model->GetNodeByID(parentId); 614 parent = GetBookmarkNodeByID(model, parentId);
615 } 615 }
616 if (!parent) { 616 if (!parent) {
617 error_ = keys::kNoParentError; 617 error_ = keys::kNoParentError;
618 // TODO(erikkay) return an error message. 618 // TODO(erikkay) return an error message.
619 return false; 619 return false;
620 } 620 }
621 if (parent == model->root_node()) { 621 if (parent == model->root_node()) {
622 error_ = keys::kModifySpecialError; 622 error_ = keys::kModifySpecialError;
623 return false; 623 return false;
624 } 624 }
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 std::string parent_id; 732 std::string parent_id;
733 if (json->HasKey(keys::kParentIdKey)) { 733 if (json->HasKey(keys::kParentIdKey)) {
734 if (!json->GetString(keys::kParentIdKey, &parent_id)) 734 if (!json->GetString(keys::kParentIdKey, &parent_id))
735 return; 735 return;
736 } 736 }
737 BookmarkModel* model = BookmarkModelFactory::GetForProfile( 737 BookmarkModel* model = BookmarkModelFactory::GetForProfile(
738 Profile::FromBrowserContext(browser_context_)); 738 Profile::FromBrowserContext(browser_context_));
739 739
740 int64 parent_id_int64; 740 int64 parent_id_int64;
741 base::StringToInt64(parent_id, &parent_id_int64); 741 base::StringToInt64(parent_id, &parent_id_int64);
742 const BookmarkNode* parent = model->GetNodeByID(parent_id_int64); 742 const BookmarkNode* parent = GetBookmarkNodeByID(model, parent_id_int64);
743 if (!parent) 743 if (!parent)
744 return; 744 return;
745 745
746 std::string bucket_id = base::UTF16ToUTF8(parent->GetTitle()); 746 std::string bucket_id = base::UTF16ToUTF8(parent->GetTitle());
747 std::string title; 747 std::string title;
748 json->GetString(keys::kTitleKey, &title); 748 json->GetString(keys::kTitleKey, &title);
749 std::string url_string; 749 std::string url_string;
750 json->GetString(keys::kUrlKey, &url_string); 750 json->GetString(keys::kUrlKey, &url_string);
751 751
752 bucket_id += title; 752 bucket_id += title;
(...skipping 17 matching lines...) Expand all
770 IdList ids; 770 IdList ids;
771 bool invalid_id = false; 771 bool invalid_id = false;
772 if (!BookmarksRemoveFunction::ExtractIds(args, &ids, &invalid_id) || 772 if (!BookmarksRemoveFunction::ExtractIds(args, &ids, &invalid_id) ||
773 invalid_id) { 773 invalid_id) {
774 return; 774 return;
775 } 775 }
776 776
777 for (IdList::iterator it = ids.begin(); it != ids.end(); ++it) { 777 for (IdList::iterator it = ids.begin(); it != ids.end(); ++it) {
778 BookmarkModel* model = BookmarkModelFactory::GetForProfile( 778 BookmarkModel* model = BookmarkModelFactory::GetForProfile(
779 Profile::FromBrowserContext(browser_context_)); 779 Profile::FromBrowserContext(browser_context_));
780 const BookmarkNode* node = model->GetNodeByID(*it); 780 const BookmarkNode* node = GetBookmarkNodeByID(model, *it);
781 if (!node || node->is_root()) 781 if (!node || node->is_root())
782 return; 782 return;
783 783
784 std::string bucket_id; 784 std::string bucket_id;
785 bucket_id += base::UTF16ToUTF8(node->parent()->GetTitle()); 785 bucket_id += base::UTF16ToUTF8(node->parent()->GetTitle());
786 bucket_id += base::UTF16ToUTF8(node->GetTitle()); 786 bucket_id += base::UTF16ToUTF8(node->GetTitle());
787 bucket_id += node->url().spec(); 787 bucket_id += node->url().spec();
788 buckets->push_back(GetBucket(base::SHA1HashString(bucket_id))); 788 buckets->push_back(GetBucket(base::SHA1HashString(bucket_id)));
789 } 789 }
790 } 790 }
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 #if !defined(OS_ANDROID) 1008 #if !defined(OS_ANDROID)
1009 // Android does not have support for the standard exporter. 1009 // Android does not have support for the standard exporter.
1010 // TODO(jgreenwald): remove ifdef once extensions are no longer built on 1010 // TODO(jgreenwald): remove ifdef once extensions are no longer built on
1011 // Android. 1011 // Android.
1012 bookmark_html_writer::WriteBookmarks(GetProfile(), path, NULL); 1012 bookmark_html_writer::WriteBookmarks(GetProfile(), path, NULL);
1013 #endif 1013 #endif
1014 Release(); // Balanced in BookmarksIOFunction::SelectFile() 1014 Release(); // Balanced in BookmarksIOFunction::SelectFile()
1015 } 1015 }
1016 1016
1017 } // namespace extensions 1017 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/bookmarks/bookmark_api_helpers.cc ('k') | chrome/browser/history/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698