Chromium Code Reviews| 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::vector<GURL>& page_urls, |
| 439 const std::vector<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) |
| 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 for (const GURL& icon_url : icon_urls) { |
| 451 FOR_EACH_OBSERVER(BookmarkModelObserver, | 453 std::vector<const BookmarkNode*> nodes; |
| 452 observers_, | 454 GetNodesByIconURL(icon_url, &nodes); |
| 453 BookmarkNodeFaviconChanged(this, node)); | 455 for (const BookmarkNode* node : nodes) |
| 454 } | 456 to_update.insert(node); |
| 457 } | |
| 458 | |
| 459 for (const BookmarkNode* node : to_update) { | |
| 460 // Rerequest the favicon. | |
| 461 BookmarkNode* mutable_node = AsMutable(node); | |
| 462 mutable_node->InvalidateFavicon(); | |
| 463 CancelPendingFaviconLoadRequests(mutable_node); | |
| 464 FOR_EACH_OBSERVER(BookmarkModelObserver, | |
| 465 observers_, | |
| 466 BookmarkNodeFaviconChanged(this, node)); | |
| 455 } | 467 } |
| 456 } | 468 } |
| 457 | 469 |
| 458 void BookmarkModel::SetDateAdded(const BookmarkNode* node, Time date_added) { | 470 void BookmarkModel::SetDateAdded(const BookmarkNode* node, Time date_added) { |
| 459 DCHECK(node && !is_permanent_node(node)); | 471 DCHECK(node && !is_permanent_node(node)); |
| 460 | 472 |
| 461 if (node->date_added() == date_added) | 473 if (node->date_added() == date_added) |
| 462 return; | 474 return; |
| 463 | 475 |
| 464 AsMutable(node)->set_date_added(date_added); | 476 AsMutable(node)->set_date_added(date_added); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 476 std::vector<const BookmarkNode*>* nodes) { | 488 std::vector<const BookmarkNode*>* nodes) { |
| 477 base::AutoLock url_lock(url_lock_); | 489 base::AutoLock url_lock(url_lock_); |
| 478 BookmarkNode tmp_node(url); | 490 BookmarkNode tmp_node(url); |
| 479 NodesOrderedByURLSet::iterator i = nodes_ordered_by_url_set_.find(&tmp_node); | 491 NodesOrderedByURLSet::iterator i = nodes_ordered_by_url_set_.find(&tmp_node); |
| 480 while (i != nodes_ordered_by_url_set_.end() && (*i)->url() == url) { | 492 while (i != nodes_ordered_by_url_set_.end() && (*i)->url() == url) { |
| 481 nodes->push_back(*i); | 493 nodes->push_back(*i); |
| 482 ++i; | 494 ++i; |
| 483 } | 495 } |
| 484 } | 496 } |
| 485 | 497 |
| 498 void BookmarkModel::GetNodesByIconURL(const GURL& icon_url, | |
| 499 std::vector<const BookmarkNode*>* nodes) { | |
| 500 // Log Histogram to determine how often this method is called in practice. | |
|
sky
2015/06/19 16:38:02
WDYT of moving this to OnFaviconsChanged? What we
| |
| 501 // TODO(pkotwicz): Do something more efficient if this method gets called many | |
| 502 // times a day for each user. | |
| 503 UMA_HISTOGRAM_BOOLEAN("Bookmarks.GetNodesByIconURL", true); | |
| 504 | |
| 505 base::AutoLock url_lock(url_lock_); | |
| 506 for (const BookmarkNode* node : nodes_ordered_by_url_set_) { | |
|
sky
2015/06/19 16:38:02
I prefer inlining this in OnFaviconsChanged and ch
| |
| 507 if (node->icon_url() == icon_url) | |
| 508 nodes->push_back(node); | |
| 509 } | |
| 510 } | |
| 511 | |
| 486 const BookmarkNode* BookmarkModel::GetMostRecentlyAddedUserNodeForURL( | 512 const BookmarkNode* BookmarkModel::GetMostRecentlyAddedUserNodeForURL( |
| 487 const GURL& url) { | 513 const GURL& url) { |
| 488 std::vector<const BookmarkNode*> nodes; | 514 std::vector<const BookmarkNode*> nodes; |
| 489 GetNodesByURL(url, &nodes); | 515 GetNodesByURL(url, &nodes); |
| 490 std::sort(nodes.begin(), nodes.end(), &MoreRecentlyAdded); | 516 std::sort(nodes.begin(), nodes.end(), &MoreRecentlyAdded); |
| 491 | 517 |
| 492 // Look for the first node that the user can edit. | 518 // Look for the first node that the user can edit. |
| 493 for (size_t i = 0; i < nodes.size(); ++i) { | 519 for (size_t i = 0; i < nodes.size(); ++i) { |
| 494 if (client_->CanBeEditedByUser(nodes[i])) | 520 if (client_->CanBeEditedByUser(nodes[i])) |
| 495 return nodes[i]; | 521 return nodes[i]; |
| (...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1028 return scoped_ptr<BookmarkLoadDetails>(new BookmarkLoadDetails( | 1054 return scoped_ptr<BookmarkLoadDetails>(new BookmarkLoadDetails( |
| 1029 bb_node, | 1055 bb_node, |
| 1030 other_node, | 1056 other_node, |
| 1031 mobile_node, | 1057 mobile_node, |
| 1032 client_->GetLoadExtraNodesCallback(), | 1058 client_->GetLoadExtraNodesCallback(), |
| 1033 new BookmarkIndex(client_, accept_languages), | 1059 new BookmarkIndex(client_, accept_languages), |
| 1034 next_node_id_)); | 1060 next_node_id_)); |
| 1035 } | 1061 } |
| 1036 | 1062 |
| 1037 } // namespace bookmarks | 1063 } // namespace bookmarks |
| OLD | NEW |