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

Side by Side Diff: chrome/browser/ui/bookmarks/bookmark_utils_desktop.cc

Issue 2809003002: Making bookmark folder context menu display the number of bookmarks that will be opened by Open All (Closed)
Patch Set: All changes to add count to context menu Created 3 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/ui/bookmarks/bookmark_utils_desktop.h" 5 #include "chrome/browser/ui/bookmarks/bookmark_utils_desktop.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 using bookmarks::BookmarkNode; 57 using bookmarks::BookmarkNode;
58 58
59 namespace chrome { 59 namespace chrome {
60 60
61 int num_bookmark_urls_before_prompting = 15; 61 int num_bookmark_urls_before_prompting = 15;
62 62
63 namespace { 63 namespace {
64 64
65 // Iterator that iterates through a set of BookmarkNodes returning the URLs 65 // Iterator that iterates through a set of BookmarkNodes returning the URLs
66 // for nodes that are urls, or the URLs for the children of non-url urls. 66 // for nodes that are urls, or the URLs for the children of non-url urls.
67 // This does not recurse through all descendants, only immediate children. 67 // This does not recurse through all descendants, only immediate children.
Peter Kasting 2017/04/13 04:52:09 Why this limitation? Does this mean we won't coun
Paezagon 2017/04/14 01:00:29 That's correct, when you use Open All on a bookmar
68 // The following illustrates 68 // The following illustrates
69 // typical usage: 69 // typical usage:
70 // OpenURLIterator iterator(nodes); 70 // OpenURLIterator iterator(nodes);
71 // while (iterator.has_next()) { 71 // while (iterator.has_next()) {
72 // const GURL* url = iterator.NextURL(); 72 // const GURL* url = iterator.NextURL();
73 // // do something with |urll|. 73 // // do something with |urll|.
74 // } 74 // }
75 class OpenURLIterator { 75 class OpenURLIterator {
Peter Kasting 2017/04/13 04:52:09 In general I wonder if this is really the right wa
Paezagon 2017/04/14 01:00:29 I have done my best to replace the iterator with a
76 public: 76 public:
77 explicit OpenURLIterator(const std::vector<const BookmarkNode*>& nodes) 77 explicit OpenURLIterator(const std::vector<const BookmarkNode*>& nodes)
78 : child_index_(0), 78 : child_index_(0),
79 next_(NULL), 79 next_(NULL),
80 parent_(nodes.begin()), 80 parent_(nodes.begin()),
81 end_(nodes.end()) { 81 end_(nodes.end()) {
82 FindNext(); 82 FindNext();
83 } 83 }
84 84
85 bool has_next() { return next_ != NULL;} 85 bool has_next() { return next_ != NULL;}
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 void OpenAll(gfx::NativeWindow parent, 220 void OpenAll(gfx::NativeWindow parent,
221 content::PageNavigator* navigator, 221 content::PageNavigator* navigator,
222 const BookmarkNode* node, 222 const BookmarkNode* node,
223 WindowOpenDisposition initial_disposition, 223 WindowOpenDisposition initial_disposition,
224 content::BrowserContext* browser_context) { 224 content::BrowserContext* browser_context) {
225 std::vector<const BookmarkNode*> nodes; 225 std::vector<const BookmarkNode*> nodes;
226 nodes.push_back(node); 226 nodes.push_back(node);
227 OpenAll(parent, navigator, nodes, initial_disposition, browser_context); 227 OpenAll(parent, navigator, nodes, initial_disposition, browser_context);
228 } 228 }
229 229
230 int OpenCount(gfx::NativeWindow parent,
231 const std::vector<const bookmarks::BookmarkNode*>& nodes,
232 bool offTheRecord,
233 content::BrowserContext* browser_context) {
234 int count = 0;
235 if (!ShouldOpenAll(parent, nodes))
236 return count;
237 // Counts all |nodes| of type URL and any children of |nodes| that are of type
238 // URL.
239 OpenURLIterator iterator(nodes);
240 while (iterator.has_next()) {
Peter Kasting 2017/04/13 04:52:09 This feels very copy-and-pasted from OpenAll(). I
Paezagon 2017/04/14 01:00:29 I have added a second get vector function that ret
241 const GURL* url = iterator.NextURL();
242 // When |initial_disposition| is OFF_THE_RECORD, a node which can't be
243 // opened in incognito window, it is detected using |browser_context|, is
244 // not opened.
Peter Kasting 2017/04/13 04:52:09 This comment doesn't make much sense. I realize y
Paezagon 2017/04/14 01:00:29 Done.
245 if (offTheRecord && !IsURLAllowedInIncognito(*url, browser_context))
246 continue;
247
248 count++;
249 }
250 return count;
251 }
252
253 int OpenCount(gfx::NativeWindow parent,
254 const BookmarkNode* node,
255 bool offTheRecord,
256 content::BrowserContext* browser_context) {
257 std::vector<const BookmarkNode*> nodes;
258 nodes.push_back(node);
259 return OpenCount(parent, nodes, offTheRecord, browser_context);
Peter Kasting 2017/04/13 04:52:09 Nit: Simpler: return OpenCount(parent, {node},
Paezagon 2017/04/14 01:00:29 When I make the change, the compiler complains tha
Peter Kasting 2017/04/14 08:17:14 Might need to do something like: return OpenCou
Paezagon 2017/04/14 18:47:24 Done.
260 }
261
230 bool ConfirmDeleteBookmarkNode(const BookmarkNode* node, 262 bool ConfirmDeleteBookmarkNode(const BookmarkNode* node,
231 gfx::NativeWindow window) { 263 gfx::NativeWindow window) {
232 DCHECK(node && node->is_folder() && !node->empty()); 264 DCHECK(node && node->is_folder() && !node->empty());
233 return ShowQuestionMessageBox( 265 return ShowQuestionMessageBox(
234 window, l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), 266 window, l10n_util::GetStringUTF16(IDS_PRODUCT_NAME),
235 l10n_util::GetPluralStringFUTF16( 267 l10n_util::GetPluralStringFUTF16(
236 IDS_BOOKMARK_EDITOR_CONFIRM_DELETE, 268 IDS_BOOKMARK_EDITOR_CONFIRM_DELETE,
237 ChildURLCountTotal(node))) == 269 ChildURLCountTotal(node))) ==
238 MESSAGE_BOX_RESULT_YES; 270 MESSAGE_BOX_RESULT_YES;
239 } 271 }
(...skipping 25 matching lines...) Expand all
265 while (iterator.has_next()) { 297 while (iterator.has_next()) {
266 const GURL* url = iterator.NextURL(); 298 const GURL* url = iterator.NextURL();
267 if (IsURLAllowedInIncognito(*url, browser_context)) 299 if (IsURLAllowedInIncognito(*url, browser_context))
268 return true; 300 return true;
269 } 301 }
270 return false; 302 return false;
271 } 303 }
272 #endif // !defined(OS_ANDROID) 304 #endif // !defined(OS_ANDROID)
273 305
274 } // namespace chrome 306 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698