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

Unified Diff: chrome/browser/bookmarks/bookmark_utils.cc

Issue 184663002: Omnibox: Make URLs of Bookmarks Searchable (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Peter's comments 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/bookmarks/bookmark_utils.cc
diff --git a/chrome/browser/bookmarks/bookmark_utils.cc b/chrome/browser/bookmarks/bookmark_utils.cc
index 5f146689ffd40931021d2fe1c6450150df5fab6a..847ae174abd593dad456901f11a3e875c3827b70 100644
--- a/chrome/browser/bookmarks/bookmark_utils.cc
+++ b/chrome/browser/bookmarks/bookmark_utils.cc
@@ -22,6 +22,7 @@
#include "content/public/browser/user_metrics.h"
#include "net/base/net_util.h"
#include "ui/base/models/tree_node_iterator.h"
+#include "url/gurl.h"
#if !defined(OS_ANDROID)
#include "chrome/browser/bookmarks/scoped_group_bookmark_actions.h"
@@ -31,6 +32,10 @@ using base::Time;
namespace {
+// The maximum length of URL or title returned by the Cleanup functions.
+static const size_t kCleanedUpUrlMaxLength = 1024u;
tfarina 2014/04/18 00:26:04 No static needed. You are already in an unnamed na
Mark P 2014/04/18 14:52:43 Done. (here and below)
+static const size_t kCleanedUpTitleMaxLength = 1024u;
+
void CloneBookmarkNodeImpl(BookmarkModel* model,
const BookmarkNodeData::Element& element,
const BookmarkNode* parent,
@@ -112,6 +117,22 @@ bool HasSelectedAncestor(BookmarkModel* model,
return HasSelectedAncestor(model, selected_nodes, node->parent());
}
+// Attempts to shorten a URL safely (i.e., by preventing the end of the URL
+// from being in the middle of an escape sequence) to no more than
+// kCleanedUpUrlMaxLength characters, returning the result.
+std::string TruncateUrl(const std::string& url) {
+ if (url.length() <= kCleanedUpUrlMaxLength)
+ return url;
+
+ // If we're in the middle of an escape sequence, truncate just before it.
+ if (url[kCleanedUpUrlMaxLength - 1] == '%')
+ return url.substr(0, kCleanedUpUrlMaxLength - 1);
+ if (url[kCleanedUpUrlMaxLength - 2] == '%')
+ return url.substr(0, kCleanedUpUrlMaxLength - 2);
+
+ return url.substr(0, kCleanedUpUrlMaxLength);
+}
+
} // namespace
namespace bookmark_utils {
@@ -375,4 +396,17 @@ void RemoveAllBookmarks(BookmarkModel* model, const GURL& url) {
}
}
+base::string16 CleanUpUrlForMatching(const GURL& gurl,
+ const std::string& languages) {
+ return base::i18n::ToLower(net::FormatUrl(
+ GURL(TruncateUrl(gurl.spec())), languages,
+ net::kFormatUrlOmitUsernamePassword,
+ net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS,
+ NULL, NULL, NULL));
+}
+
+base::string16 CleanUpTitleForMatching(const base::string16& title) {
+ return base::i18n::ToLower(title.substr(0u, kCleanedUpTitleMaxLength));
+}
+
} // namespace bookmark_utils

Powered by Google App Engine
This is Rietveld 408576698