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

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

Issue 386283002: Move bookmark_utils into bookmarks namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 <algorithm> 5 #include <algorithm>
6 6
7 #include "chrome/browser/extensions/api/bookmarks/bookmarks_api.h" 7 #include "chrome/browser/extensions/api/bookmarks/bookmarks_api.h"
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 #include "grit/generated_resources.h" 54 #include "grit/generated_resources.h"
55 #include "ui/base/l10n/l10n_util.h" 55 #include "ui/base/l10n/l10n_util.h"
56 56
57 #if defined(OS_WIN) 57 #if defined(OS_WIN)
58 #include "ui/aura/remote_window_tree_host_win.h" 58 #include "ui/aura/remote_window_tree_host_win.h"
59 #endif 59 #endif
60 60
61 namespace extensions { 61 namespace extensions {
62 62
63 namespace keys = bookmark_api_constants; 63 namespace keys = bookmark_api_constants;
64 namespace bookmarks = api::bookmarks; 64 namespace bookmarks = api::bookmarks;
sky 2014/07/14 17:05:50 I think we should name this to avoid confusing. Or
65 65
66 using base::TimeDelta; 66 using base::TimeDelta;
67 using bookmarks::BookmarkTreeNode; 67 using bookmarks::BookmarkTreeNode;
68 using bookmarks::CreateDetails; 68 using bookmarks::CreateDetails;
69 using content::BrowserContext; 69 using content::BrowserContext;
70 using content::BrowserThread; 70 using content::BrowserThread;
71 using content::WebContents; 71 using content::WebContents;
72 72
73 typedef QuotaLimitHeuristic::Bucket Bucket; 73 typedef QuotaLimitHeuristic::Bucket Bucket;
74 typedef QuotaLimitHeuristic::Config Config; 74 typedef QuotaLimitHeuristic::Config Config;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 error_ = keys::kInvalidIdError; 190 error_ = keys::kInvalidIdError;
191 return false; 191 return false;
192 } 192 }
193 193
194 const BookmarkNode* BookmarksFunction::GetBookmarkNodeFromId( 194 const BookmarkNode* BookmarksFunction::GetBookmarkNodeFromId(
195 const std::string& id_string) { 195 const std::string& id_string) {
196 int64 id; 196 int64 id;
197 if (!GetBookmarkIdAsInt64(id_string, &id)) 197 if (!GetBookmarkIdAsInt64(id_string, &id))
198 return NULL; 198 return NULL;
199 199
200 const BookmarkNode* node = GetBookmarkNodeByID( 200 const BookmarkNode* node = ::bookmarks::GetBookmarkNodeByID(
201 BookmarkModelFactory::GetForProfile(GetProfile()), id); 201 BookmarkModelFactory::GetForProfile(GetProfile()), id);
202 if (!node) 202 if (!node)
203 error_ = keys::kNoNodeError; 203 error_ = keys::kNoNodeError;
204 204
205 return node; 205 return node;
206 } 206 }
207 207
208 const BookmarkNode* BookmarksFunction::CreateBookmarkNode( 208 const BookmarkNode* BookmarksFunction::CreateBookmarkNode(
209 BookmarkModel* model, 209 BookmarkModel* model,
210 const CreateDetails& details, 210 const CreateDetails& details,
211 const BookmarkNode::MetaInfoMap* meta_info) { 211 const BookmarkNode::MetaInfoMap* meta_info) {
212 int64 parentId; 212 int64 parentId;
213 213
214 if (!details.parent_id.get()) { 214 if (!details.parent_id.get()) {
215 // Optional, default to "other bookmarks". 215 // Optional, default to "other bookmarks".
216 parentId = model->other_node()->id(); 216 parentId = model->other_node()->id();
217 } else { 217 } else {
218 if (!GetBookmarkIdAsInt64(*details.parent_id, &parentId)) 218 if (!GetBookmarkIdAsInt64(*details.parent_id, &parentId))
219 return NULL; 219 return NULL;
220 } 220 }
221 const BookmarkNode* parent = GetBookmarkNodeByID(model, parentId); 221 const BookmarkNode* parent =
222 ::bookmarks::GetBookmarkNodeByID(model, parentId);
222 if (!CanBeModified(parent)) 223 if (!CanBeModified(parent))
223 return NULL; 224 return NULL;
224 225
225 int index; 226 int index;
226 if (!details.index.get()) { // Optional (defaults to end). 227 if (!details.index.get()) { // Optional (defaults to end).
227 index = parent->child_count(); 228 index = parent->child_count();
228 } else { 229 } else {
229 index = *details.index; 230 index = *details.index;
230 if (index > parent->child_count() || index < 0) { 231 if (index > parent->child_count() || index < 0) {
231 error_ = keys::kInvalidIndexError; 232 error_ = keys::kInvalidIndexError;
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 } 531 }
531 532
532 bool BookmarksGetRecentFunction::RunOnReady() { 533 bool BookmarksGetRecentFunction::RunOnReady() {
533 scoped_ptr<bookmarks::GetRecent::Params> params( 534 scoped_ptr<bookmarks::GetRecent::Params> params(
534 bookmarks::GetRecent::Params::Create(*args_)); 535 bookmarks::GetRecent::Params::Create(*args_));
535 EXTENSION_FUNCTION_VALIDATE(params.get()); 536 EXTENSION_FUNCTION_VALIDATE(params.get());
536 if (params->number_of_items < 1) 537 if (params->number_of_items < 1)
537 return false; 538 return false;
538 539
539 std::vector<const BookmarkNode*> nodes; 540 std::vector<const BookmarkNode*> nodes;
540 bookmark_utils::GetMostRecentlyAddedEntries( 541 ::bookmarks::GetMostRecentlyAddedEntries(
541 BookmarkModelFactory::GetForProfile(GetProfile()), 542 BookmarkModelFactory::GetForProfile(GetProfile()),
542 params->number_of_items, 543 params->number_of_items,
543 &nodes); 544 &nodes);
544 545
545 std::vector<linked_ptr<BookmarkTreeNode> > tree_nodes; 546 std::vector<linked_ptr<BookmarkTreeNode> > tree_nodes;
546 std::vector<const BookmarkNode*>::iterator i = nodes.begin(); 547 std::vector<const BookmarkNode*>::iterator i = nodes.begin();
547 for (; i != nodes.end(); ++i) { 548 for (; i != nodes.end(); ++i) {
548 const BookmarkNode* node = *i; 549 const BookmarkNode* node = *i;
549 bookmark_api_helpers::AddNode( 550 bookmark_api_helpers::AddNode(
550 GetChromeBookmarkClient(), node, &tree_nodes, false); 551 GetChromeBookmarkClient(), node, &tree_nodes, false);
(...skipping 29 matching lines...) Expand all
580 581
581 bool BookmarksSearchFunction::RunOnReady() { 582 bool BookmarksSearchFunction::RunOnReady() {
582 scoped_ptr<bookmarks::Search::Params> params( 583 scoped_ptr<bookmarks::Search::Params> params(
583 bookmarks::Search::Params::Create(*args_)); 584 bookmarks::Search::Params::Create(*args_));
584 EXTENSION_FUNCTION_VALIDATE(params.get()); 585 EXTENSION_FUNCTION_VALIDATE(params.get());
585 586
586 PrefService* prefs = user_prefs::UserPrefs::Get(GetProfile()); 587 PrefService* prefs = user_prefs::UserPrefs::Get(GetProfile());
587 std::string lang = prefs->GetString(prefs::kAcceptLanguages); 588 std::string lang = prefs->GetString(prefs::kAcceptLanguages);
588 std::vector<const BookmarkNode*> nodes; 589 std::vector<const BookmarkNode*> nodes;
589 if (params->query.as_string) { 590 if (params->query.as_string) {
590 bookmark_utils::QueryFields query; 591 ::bookmarks::QueryFields query;
591 query.word_phrase_query.reset( 592 query.word_phrase_query.reset(
592 new base::string16(base::UTF8ToUTF16(*params->query.as_string))); 593 new base::string16(base::UTF8ToUTF16(*params->query.as_string)));
593 bookmark_utils::GetBookmarksMatchingProperties( 594 ::bookmarks::GetBookmarksMatchingProperties(
594 BookmarkModelFactory::GetForProfile(GetProfile()), 595 BookmarkModelFactory::GetForProfile(GetProfile()),
595 query, 596 query,
596 std::numeric_limits<int>::max(), 597 std::numeric_limits<int>::max(),
597 lang, 598 lang,
598 &nodes); 599 &nodes);
599 } else { 600 } else {
600 DCHECK(params->query.as_object); 601 DCHECK(params->query.as_object);
601 const bookmarks::Search::Params::Query::Object& object = 602 const bookmarks::Search::Params::Query::Object& object =
602 *params->query.as_object; 603 *params->query.as_object;
603 bookmark_utils::QueryFields query; 604 ::bookmarks::QueryFields query;
604 if (object.query) { 605 if (object.query) {
605 query.word_phrase_query.reset( 606 query.word_phrase_query.reset(
606 new base::string16(base::UTF8ToUTF16(*object.query))); 607 new base::string16(base::UTF8ToUTF16(*object.query)));
607 } 608 }
608 if (object.url) 609 if (object.url)
609 query.url.reset(new base::string16(base::UTF8ToUTF16(*object.url))); 610 query.url.reset(new base::string16(base::UTF8ToUTF16(*object.url)));
610 if (object.title) 611 if (object.title)
611 query.title.reset(new base::string16(base::UTF8ToUTF16(*object.title))); 612 query.title.reset(new base::string16(base::UTF8ToUTF16(*object.title)));
612 bookmark_utils::GetBookmarksMatchingProperties( 613 ::bookmarks::GetBookmarksMatchingProperties(
613 BookmarkModelFactory::GetForProfile(GetProfile()), 614 BookmarkModelFactory::GetForProfile(GetProfile()),
614 query, 615 query,
615 std::numeric_limits<int>::max(), 616 std::numeric_limits<int>::max(),
616 lang, 617 lang,
617 &nodes); 618 &nodes);
618 } 619 }
619 620
620 std::vector<linked_ptr<BookmarkTreeNode> > tree_nodes; 621 std::vector<linked_ptr<BookmarkTreeNode> > tree_nodes;
621 ChromeBookmarkClient* client = GetChromeBookmarkClient(); 622 ChromeBookmarkClient* client = GetChromeBookmarkClient();
622 for (std::vector<const BookmarkNode*>::iterator node_iter = nodes.begin(); 623 for (std::vector<const BookmarkNode*>::iterator node_iter = nodes.begin();
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 716
716 const BookmarkNode* parent = NULL; 717 const BookmarkNode* parent = NULL;
717 if (!params->destination.parent_id.get()) { 718 if (!params->destination.parent_id.get()) {
718 // Optional, defaults to current parent. 719 // Optional, defaults to current parent.
719 parent = node->parent(); 720 parent = node->parent();
720 } else { 721 } else {
721 int64 parentId; 722 int64 parentId;
722 if (!GetBookmarkIdAsInt64(*params->destination.parent_id, &parentId)) 723 if (!GetBookmarkIdAsInt64(*params->destination.parent_id, &parentId))
723 return false; 724 return false;
724 725
725 parent = GetBookmarkNodeByID(model, parentId); 726 parent = ::bookmarks::GetBookmarkNodeByID(model, parentId);
726 } 727 }
727 if (!CanBeModified(parent) || !CanBeModified(node)) 728 if (!CanBeModified(parent) || !CanBeModified(node))
728 return false; 729 return false;
729 730
730 int index; 731 int index;
731 if (params->destination.index.get()) { // Optional (defaults to end). 732 if (params->destination.index.get()) { // Optional (defaults to end).
732 index = *params->destination.index; 733 index = *params->destination.index;
733 if (index > parent->child_count() || index < 0) { 734 if (index > parent->child_count() || index < 0) {
734 error_ = keys::kInvalidIndexError; 735 error_ = keys::kInvalidIndexError;
735 return false; 736 return false;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 std::string parent_id; 839 std::string parent_id;
839 if (json->HasKey(keys::kParentIdKey)) { 840 if (json->HasKey(keys::kParentIdKey)) {
840 if (!json->GetString(keys::kParentIdKey, &parent_id)) 841 if (!json->GetString(keys::kParentIdKey, &parent_id))
841 return; 842 return;
842 } 843 }
843 BookmarkModel* model = BookmarkModelFactory::GetForProfile( 844 BookmarkModel* model = BookmarkModelFactory::GetForProfile(
844 Profile::FromBrowserContext(browser_context_)); 845 Profile::FromBrowserContext(browser_context_));
845 846
846 int64 parent_id_int64; 847 int64 parent_id_int64;
847 base::StringToInt64(parent_id, &parent_id_int64); 848 base::StringToInt64(parent_id, &parent_id_int64);
848 const BookmarkNode* parent = GetBookmarkNodeByID(model, parent_id_int64); 849 const BookmarkNode* parent =
850 ::bookmarks::GetBookmarkNodeByID(model, parent_id_int64);
849 if (!parent) 851 if (!parent)
850 return; 852 return;
851 853
852 std::string bucket_id = base::UTF16ToUTF8(parent->GetTitle()); 854 std::string bucket_id = base::UTF16ToUTF8(parent->GetTitle());
853 std::string title; 855 std::string title;
854 json->GetString(keys::kTitleKey, &title); 856 json->GetString(keys::kTitleKey, &title);
855 std::string url_string; 857 std::string url_string;
856 json->GetString(keys::kUrlKey, &url_string); 858 json->GetString(keys::kUrlKey, &url_string);
857 859
858 bucket_id += title; 860 bucket_id += title;
(...skipping 18 matching lines...) Expand all
877 IdList ids; 879 IdList ids;
878 bool invalid_id = false; 880 bool invalid_id = false;
879 if (!BookmarksRemoveFunction::ExtractIds(args, &ids, &invalid_id) || 881 if (!BookmarksRemoveFunction::ExtractIds(args, &ids, &invalid_id) ||
880 invalid_id) { 882 invalid_id) {
881 return; 883 return;
882 } 884 }
883 885
884 for (IdList::iterator it = ids.begin(); it != ids.end(); ++it) { 886 for (IdList::iterator it = ids.begin(); it != ids.end(); ++it) {
885 BookmarkModel* model = BookmarkModelFactory::GetForProfile( 887 BookmarkModel* model = BookmarkModelFactory::GetForProfile(
886 Profile::FromBrowserContext(browser_context_)); 888 Profile::FromBrowserContext(browser_context_));
887 const BookmarkNode* node = GetBookmarkNodeByID(model, *it); 889 const BookmarkNode* node = ::bookmarks::GetBookmarkNodeByID(model, *it);
888 if (!node || node->is_root()) 890 if (!node || node->is_root())
889 return; 891 return;
890 892
891 std::string bucket_id; 893 std::string bucket_id;
892 bucket_id += base::UTF16ToUTF8(node->parent()->GetTitle()); 894 bucket_id += base::UTF16ToUTF8(node->parent()->GetTitle());
893 bucket_id += base::UTF16ToUTF8(node->GetTitle()); 895 bucket_id += base::UTF16ToUTF8(node->GetTitle());
894 bucket_id += node->url().spec(); 896 bucket_id += node->url().spec();
895 buckets->push_back(GetBucket(base::SHA1HashString(bucket_id))); 897 buckets->push_back(GetBucket(base::SHA1HashString(bucket_id)));
896 } 898 }
897 } 899 }
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 void BookmarksExportFunction::FileSelected(const base::FilePath& path, 1110 void BookmarksExportFunction::FileSelected(const base::FilePath& path,
1109 int index, 1111 int index,
1110 void* params) { 1112 void* params) {
1111 // TODO(jgreenwald): remove ifdef once extensions are no longer built on 1113 // TODO(jgreenwald): remove ifdef once extensions are no longer built on
1112 // Android. 1114 // Android.
1113 bookmark_html_writer::WriteBookmarks(GetProfile(), path, NULL); 1115 bookmark_html_writer::WriteBookmarks(GetProfile(), path, NULL);
1114 Release(); // Balanced in BookmarksIOFunction::SelectFile() 1116 Release(); // Balanced in BookmarksIOFunction::SelectFile()
1115 } 1117 }
1116 1118
1117 } // namespace extensions 1119 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698