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

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

Issue 308273002: Made the bookmarks extension APIs aware of managed bookmarks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 } 155 }
156 const BookmarkNode* parent = GetBookmarkNodeByID(model, parentId); 156 const BookmarkNode* parent = GetBookmarkNodeByID(model, parentId);
157 if (!parent) { 157 if (!parent) {
158 error_ = keys::kNoParentError; 158 error_ = keys::kNoParentError;
159 return NULL; 159 return NULL;
160 } 160 }
161 if (parent->is_root()) { // Can't create children of the root. 161 if (parent->is_root()) { // Can't create children of the root.
162 error_ = keys::kModifySpecialError; 162 error_ = keys::kModifySpecialError;
163 return NULL; 163 return NULL;
164 } 164 }
165 if (model->IsManaged(parent)) {
166 error_ = keys::kModifyManagedError;
167 return NULL;
168 }
165 169
166 int index; 170 int index;
167 if (!details.index.get()) { // Optional (defaults to end). 171 if (!details.index.get()) { // Optional (defaults to end).
168 index = parent->child_count(); 172 index = parent->child_count();
169 } else { 173 } else {
170 index = *details.index; 174 index = *details.index;
171 if (index > parent->child_count() || index < 0) { 175 if (index > parent->child_count() || index < 0) {
172 error_ = keys::kInvalidIndexError; 176 error_ = keys::kInvalidIndexError;
173 return NULL; 177 return NULL;
174 } 178 }
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 parent = node->parent(); 629 parent = node->parent();
626 } else { 630 } else {
627 int64 parentId; 631 int64 parentId;
628 if (!GetBookmarkIdAsInt64(*params->destination.parent_id, &parentId)) 632 if (!GetBookmarkIdAsInt64(*params->destination.parent_id, &parentId))
629 return false; 633 return false;
630 634
631 parent = GetBookmarkNodeByID(model, parentId); 635 parent = GetBookmarkNodeByID(model, parentId);
632 } 636 }
633 if (!parent) { 637 if (!parent) {
634 error_ = keys::kNoParentError; 638 error_ = keys::kNoParentError;
635 // TODO(erikkay) return an error message. 639 // TODO(erikkay) return an error message.
not at google - send to devlin 2014/06/02 21:49:29 drive-by: remove this TODO?
Joao da Silva 2014/06/03 12:54:00 Done.
636 return false; 640 return false;
637 } 641 }
638 if (parent == model->root_node()) { 642 if (parent == model->root_node()) {
639 error_ = keys::kModifySpecialError; 643 error_ = keys::kModifySpecialError;
640 return false; 644 return false;
641 } 645 }
646 if (model->IsManaged(parent) || model->IsManaged(node)) {
647 error_ = keys::kModifyManagedError;
648 return false;
649 }
642 650
643 int index; 651 int index;
644 if (params->destination.index.get()) { // Optional (defaults to end). 652 if (params->destination.index.get()) { // Optional (defaults to end).
645 index = *params->destination.index; 653 index = *params->destination.index;
646 if (index > parent->child_count() || index < 0) { 654 if (index > parent->child_count() || index < 0) {
647 error_ = keys::kInvalidIndexError; 655 error_ = keys::kInvalidIndexError;
648 return false; 656 return false;
649 } 657 }
650 } else { 658 } else {
651 index = parent->child_count(); 659 index = parent->child_count();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 704
697 const BookmarkNode* node = GetBookmarkNodeFromId(params->id); 705 const BookmarkNode* node = GetBookmarkNodeFromId(params->id);
698 if (!node) 706 if (!node)
699 return false; 707 return false;
700 708
701 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); 709 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile());
702 if (model->is_permanent_node(node)) { 710 if (model->is_permanent_node(node)) {
703 error_ = keys::kModifySpecialError; 711 error_ = keys::kModifySpecialError;
704 return false; 712 return false;
705 } 713 }
714 if (model->IsManaged(node)) {
715 error_ = keys::kModifyManagedError;
716 return false;
717 }
718
706 if (has_title) 719 if (has_title)
707 model->SetTitle(node, title); 720 model->SetTitle(node, title);
708 if (!url.is_empty()) 721 if (!url.is_empty())
709 model->SetURL(node, url); 722 model->SetURL(node, url);
710 723
711 scoped_ptr<BookmarkTreeNode> tree_node( 724 scoped_ptr<BookmarkTreeNode> tree_node(
712 bookmark_api_helpers::GetBookmarkTreeNode(node, false, false)); 725 bookmark_api_helpers::GetBookmarkTreeNode(node, false, false));
713 results_ = bookmarks::Update::Results::Create(*tree_node); 726 results_ = bookmarks::Update::Results::Create(*tree_node);
714 return true; 727 return true;
715 } 728 }
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 } 902 }
890 903
891 void BookmarksMoveFunction::GetQuotaLimitHeuristics( 904 void BookmarksMoveFunction::GetQuotaLimitHeuristics(
892 QuotaLimitHeuristics* heuristics) const { 905 QuotaLimitHeuristics* heuristics) const {
893 BookmarksQuotaLimitFactory::Build<BookmarksMoveFunction>(heuristics); 906 BookmarksQuotaLimitFactory::Build<BookmarksMoveFunction>(heuristics);
894 } 907 }
895 908
896 void BookmarksUpdateFunction::GetQuotaLimitHeuristics( 909 void BookmarksUpdateFunction::GetQuotaLimitHeuristics(
897 QuotaLimitHeuristics* heuristics) const { 910 QuotaLimitHeuristics* heuristics) const {
898 BookmarksQuotaLimitFactory::Build<BookmarksUpdateFunction>(heuristics); 911 BookmarksQuotaLimitFactory::Build<BookmarksUpdateFunction>(heuristics);
899 }; 912 }
900 913
901 void BookmarksCreateFunction::GetQuotaLimitHeuristics( 914 void BookmarksCreateFunction::GetQuotaLimitHeuristics(
902 QuotaLimitHeuristics* heuristics) const { 915 QuotaLimitHeuristics* heuristics) const {
903 BookmarksQuotaLimitFactory::BuildForCreate(heuristics, GetProfile()); 916 BookmarksQuotaLimitFactory::BuildForCreate(heuristics, GetProfile());
904 } 917 }
905 918
906 BookmarksIOFunction::BookmarksIOFunction() {} 919 BookmarksIOFunction::BookmarksIOFunction() {}
907 920
908 BookmarksIOFunction::~BookmarksIOFunction() { 921 BookmarksIOFunction::~BookmarksIOFunction() {
909 // There may be pending file dialogs, we need to tell them that we've gone 922 // There may be pending file dialogs, we need to tell them that we've gone
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 #if !defined(OS_ANDROID) 1038 #if !defined(OS_ANDROID)
1026 // Android does not have support for the standard exporter. 1039 // Android does not have support for the standard exporter.
1027 // TODO(jgreenwald): remove ifdef once extensions are no longer built on 1040 // TODO(jgreenwald): remove ifdef once extensions are no longer built on
1028 // Android. 1041 // Android.
1029 bookmark_html_writer::WriteBookmarks(GetProfile(), path, NULL); 1042 bookmark_html_writer::WriteBookmarks(GetProfile(), path, NULL);
1030 #endif 1043 #endif
1031 Release(); // Balanced in BookmarksIOFunction::SelectFile() 1044 Release(); // Balanced in BookmarksIOFunction::SelectFile()
1032 } 1045 }
1033 1046
1034 } // namespace extensions 1047 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698