OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/bookmarks/browser/bookmark_model.h" | 5 #include "components/bookmarks/browser/bookmark_model.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/i18n/string_compare.h" | 12 #include "base/i18n/string_compare.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/metrics/histogram_macros.h" | |
15 #include "base/profiler/scoped_tracker.h" | 16 #include "base/profiler/scoped_tracker.h" |
16 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
17 #include "components/bookmarks/browser/bookmark_expanded_state_tracker.h" | 18 #include "components/bookmarks/browser/bookmark_expanded_state_tracker.h" |
18 #include "components/bookmarks/browser/bookmark_index.h" | 19 #include "components/bookmarks/browser/bookmark_index.h" |
19 #include "components/bookmarks/browser/bookmark_match.h" | 20 #include "components/bookmarks/browser/bookmark_match.h" |
20 #include "components/bookmarks/browser/bookmark_model_observer.h" | 21 #include "components/bookmarks/browser/bookmark_model_observer.h" |
21 #include "components/bookmarks/browser/bookmark_node_data.h" | 22 #include "components/bookmarks/browser/bookmark_node_data.h" |
22 #include "components/bookmarks/browser/bookmark_storage.h" | 23 #include "components/bookmarks/browser/bookmark_storage.h" |
23 #include "components/bookmarks/browser/bookmark_utils.h" | 24 #include "components/bookmarks/browser/bookmark_utils.h" |
24 #include "components/favicon_base/favicon_types.h" | 25 #include "components/favicon_base/favicon_types.h" |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
427 DCHECK(client_->CanSyncNode(node)); | 428 DCHECK(client_->CanSyncNode(node)); |
428 | 429 |
429 if (sync_transaction_version == node->sync_transaction_version()) | 430 if (sync_transaction_version == node->sync_transaction_version()) |
430 return; | 431 return; |
431 | 432 |
432 AsMutable(node)->set_sync_transaction_version(sync_transaction_version); | 433 AsMutable(node)->set_sync_transaction_version(sync_transaction_version); |
433 if (store_.get()) | 434 if (store_.get()) |
434 store_->ScheduleSave(); | 435 store_->ScheduleSave(); |
435 } | 436 } |
436 | 437 |
437 void BookmarkModel::OnFaviconChanged(const std::set<GURL>& urls) { | 438 void BookmarkModel::OnFaviconsChanged(const std::set<GURL>& page_urls, |
439 const std::set<GURL>& icon_urls) { | |
438 // Ignore events if |Load| has not been called yet. | 440 // Ignore events if |Load| has not been called yet. |
439 if (!store_) | 441 if (!store_) |
440 return; | 442 return; |
441 | 443 |
442 // Prevent the observers from getting confused for multiple favicon loads. | 444 std::set<const BookmarkNode*> to_update; |
443 for (std::set<GURL>::const_iterator i = urls.begin(); i != urls.end(); ++i) { | 445 for (const GURL& page_url : page_urls) { |
444 std::vector<const BookmarkNode*> nodes; | 446 std::vector<const BookmarkNode*> nodes; |
445 GetNodesByURL(*i, &nodes); | 447 GetNodesByURL(page_url, &nodes); |
446 for (size_t i = 0; i < nodes.size(); ++i) { | 448 for (const BookmarkNode* node : nodes) |
sky
2015/06/22 15:19:48
to_update.insert(nodes.begin(), nodes.end())
pkotwicz
2015/06/26 15:14:28
Done.
| |
447 // Got an updated favicon, for a URL, do a new request. | 449 to_update.insert(node); |
448 BookmarkNode* node = AsMutable(nodes[i]); | 450 } |
449 node->InvalidateFavicon(); | 451 |
450 CancelPendingFaviconLoadRequests(node); | 452 if (!icon_urls.empty()) { |
451 FOR_EACH_OBSERVER(BookmarkModelObserver, | 453 // Log Histogram to determine how often |icon_urls| is non empty in |
452 observers_, | 454 // practice. |
453 BookmarkNodeFaviconChanged(this, node)); | 455 // TODO(pkotwicz): Do something more efficient if |icon_urls| is non-empty |
456 // many times a day for each user. | |
457 UMA_HISTOGRAM_BOOLEAN("Bookmarks.OnFaviconsChangedMultipleIconURLs", true); | |
sky
2015/06/22 15:19:48
Can you also include the size of icon_urls?
pkotwicz
2015/06/26 15:14:28
|icon_urls| has at most one element. Do you want m
sky
2015/06/29 14:51:03
In that case why do we need a set? Why not a singl
| |
458 | |
459 base::AutoLock url_lock(url_lock_); | |
460 for (const BookmarkNode* node : nodes_ordered_by_url_set_) { | |
461 if (icon_urls.count(node->icon_url())) | |
462 to_update.insert(node); | |
454 } | 463 } |
455 } | 464 } |
465 | |
466 for (const BookmarkNode* node : to_update) { | |
467 // Rerequest the favicon. | |
468 BookmarkNode* mutable_node = AsMutable(node); | |
469 mutable_node->InvalidateFavicon(); | |
470 CancelPendingFaviconLoadRequests(mutable_node); | |
471 FOR_EACH_OBSERVER(BookmarkModelObserver, | |
472 observers_, | |
473 BookmarkNodeFaviconChanged(this, node)); | |
474 } | |
456 } | 475 } |
457 | 476 |
458 void BookmarkModel::SetDateAdded(const BookmarkNode* node, Time date_added) { | 477 void BookmarkModel::SetDateAdded(const BookmarkNode* node, Time date_added) { |
459 DCHECK(node && !is_permanent_node(node)); | 478 DCHECK(node && !is_permanent_node(node)); |
460 | 479 |
461 if (node->date_added() == date_added) | 480 if (node->date_added() == date_added) |
462 return; | 481 return; |
463 | 482 |
464 AsMutable(node)->set_date_added(date_added); | 483 AsMutable(node)->set_date_added(date_added); |
465 | 484 |
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1028 return scoped_ptr<BookmarkLoadDetails>(new BookmarkLoadDetails( | 1047 return scoped_ptr<BookmarkLoadDetails>(new BookmarkLoadDetails( |
1029 bb_node, | 1048 bb_node, |
1030 other_node, | 1049 other_node, |
1031 mobile_node, | 1050 mobile_node, |
1032 client_->GetLoadExtraNodesCallback(), | 1051 client_->GetLoadExtraNodesCallback(), |
1033 new BookmarkIndex(client_, accept_languages), | 1052 new BookmarkIndex(client_, accept_languages), |
1034 next_node_id_)); | 1053 next_node_id_)); |
1035 } | 1054 } |
1036 | 1055 |
1037 } // namespace bookmarks | 1056 } // namespace bookmarks |
OLD | NEW |