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

Side by Side 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: Created 6 years, 9 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.
Mark P 2014/02/28 15:48:03 All changes here are simply a cut-and-paste of fun
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/bookmarks/bookmark_utils.h" 5 #include "chrome/browser/bookmarks/bookmark_utils.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/i18n/case_conversion.h" 11 #include "base/i18n/case_conversion.h"
12 #include "base/i18n/string_search.h" 12 #include "base/i18n/string_search.h"
13 #include "base/prefs/pref_service.h" 13 #include "base/prefs/pref_service.h"
14 #include "base/strings/string16.h" 14 #include "base/strings/string16.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "chrome/browser/bookmarks/bookmark_model.h" 17 #include "chrome/browser/bookmarks/bookmark_model.h"
18 #include "chrome/browser/history/query_parser.h" 18 #include "chrome/browser/history/query_parser.h"
19 #include "chrome/browser/undo/bookmark_undo_service.h" 19 #include "chrome/browser/undo/bookmark_undo_service.h"
20 #include "chrome/browser/undo/bookmark_undo_service_factory.h" 20 #include "chrome/browser/undo/bookmark_undo_service_factory.h"
21 #include "chrome/browser/undo/bookmark_undo_utils.h" 21 #include "chrome/browser/undo/bookmark_undo_utils.h"
22 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
23 #include "components/user_prefs/pref_registry_syncable.h" 23 #include "components/user_prefs/pref_registry_syncable.h"
24 #include "content/public/browser/user_metrics.h" 24 #include "content/public/browser/user_metrics.h"
25 #include "net/base/net_util.h" 25 #include "net/base/net_util.h"
26 #include "ui/base/models/tree_node_iterator.h" 26 #include "ui/base/models/tree_node_iterator.h"
27 #include "url/gurl.h"
27 28
28 using base::Time; 29 using base::Time;
29 30
30 namespace { 31 namespace {
31 32
33 // The maximum length of URL or title returned by the Cleanup functions.
34 static const size_t kCleanedUpUrlMaxLength = 1024u;
35 static const size_t kCleanedUpTitleMaxLength = 1024u;
36
32 void CloneBookmarkNodeImpl(BookmarkModel* model, 37 void CloneBookmarkNodeImpl(BookmarkModel* model,
33 const BookmarkNodeData::Element& element, 38 const BookmarkNodeData::Element& element,
34 const BookmarkNode* parent, 39 const BookmarkNode* parent,
35 int index_to_add_at, 40 int index_to_add_at,
36 bool reset_node_times) { 41 bool reset_node_times) {
37 const BookmarkNode* cloned_node = NULL; 42 const BookmarkNode* cloned_node = NULL;
38 if (element.is_url) { 43 if (element.is_url) {
39 if (reset_node_times) { 44 if (reset_node_times) {
40 cloned_node = model->AddURL(parent, index_to_add_at, element.title, 45 cloned_node = model->AddURL(parent, index_to_add_at, element.title,
41 element.url); 46 element.url);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 if (!node || model->is_permanent_node(node)) 108 if (!node || model->is_permanent_node(node))
104 return false; 109 return false;
105 110
106 for (size_t i = 0; i < selected_nodes.size(); ++i) 111 for (size_t i = 0; i < selected_nodes.size(); ++i)
107 if (node->id() == selected_nodes[i]->id()) 112 if (node->id() == selected_nodes[i]->id())
108 return true; 113 return true;
109 114
110 return HasSelectedAncestor(model, selected_nodes, node->parent()); 115 return HasSelectedAncestor(model, selected_nodes, node->parent());
111 } 116 }
112 117
118 // Attempts to shorten a URL safely (i.e., by preventing the end of the URL
119 // from being in the middle of an escape sequence) to no more than
120 // kCleanedUpUrlMaxLength characters, returning the result.
121 std::string TruncateUrl(const std::string& url) {
122 if (url.length() <= kCleanedUpUrlMaxLength)
123 return url;
124
125 // If we're in the middle of an escape sequence, truncate just before it.
126 if (url[kCleanedUpUrlMaxLength - 1] == '%')
127 return url.substr(0, kCleanedUpUrlMaxLength - 1);
128 if (url[kCleanedUpUrlMaxLength - 2] == '%')
129 return url.substr(0, kCleanedUpUrlMaxLength - 2);
130
131 return url.substr(0, kCleanedUpUrlMaxLength);
132 }
133
113 } // namespace 134 } // namespace
114 135
115 namespace bookmark_utils { 136 namespace bookmark_utils {
116 137
117 QueryFields::QueryFields() {} 138 QueryFields::QueryFields() {}
118 QueryFields::~QueryFields() {} 139 QueryFields::~QueryFields() {}
119 140
120 void CloneBookmarkNode(BookmarkModel* model, 141 void CloneBookmarkNode(BookmarkModel* model,
121 const std::vector<BookmarkNodeData::Element>& elements, 142 const std::vector<BookmarkNodeData::Element>& elements,
122 const BookmarkNode* parent, 143 const BookmarkNode* parent,
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 387
367 // Remove all the bookmarks. 388 // Remove all the bookmarks.
368 for (size_t i = 0; i < bookmarks.size(); ++i) { 389 for (size_t i = 0; i < bookmarks.size(); ++i) {
369 const BookmarkNode* node = bookmarks[i]; 390 const BookmarkNode* node = bookmarks[i];
370 int index = node->parent()->GetIndexOf(node); 391 int index = node->parent()->GetIndexOf(node);
371 if (index > -1) 392 if (index > -1)
372 model->Remove(node->parent(), index); 393 model->Remove(node->parent(), index);
373 } 394 }
374 } 395 }
375 396
397 base::string16 CleanUpUrlForMatching(const GURL& gurl,
398 const std::string& languages) {
399 return base::i18n::ToLower(net::FormatUrl(
400 GURL(TruncateUrl(gurl.spec())), languages,
401 net::kFormatUrlOmitUsernamePassword,
402 net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS,
403 NULL, NULL, NULL));
404 }
405
406 base::string16 CleanUpTitleForMatching(const base::string16& title) {
407 return base::i18n::ToLower(title.substr(0u, kCleanedUpTitleMaxLength));
408 }
409
376 } // namespace bookmark_utils 410 } // namespace bookmark_utils
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698