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, |
438 // Prevent the observers from getting confused for multiple favicon loads. | 439 const GURL& icon_url) { |
439 for (std::set<GURL>::const_iterator i = urls.begin(); i != urls.end(); ++i) { | 440 std::set<const BookmarkNode*> to_update; |
| 441 for (const GURL& page_url : page_urls) { |
440 std::vector<const BookmarkNode*> nodes; | 442 std::vector<const BookmarkNode*> nodes; |
441 GetNodesByURL(*i, &nodes); | 443 GetNodesByURL(page_url, &nodes); |
442 for (size_t i = 0; i < nodes.size(); ++i) { | 444 to_update.insert(nodes.begin(), nodes.end()); |
443 // Got an updated favicon, for a URL, do a new request. | 445 } |
444 BookmarkNode* node = AsMutable(nodes[i]); | 446 |
445 node->InvalidateFavicon(); | 447 if (!icon_url.is_empty()) { |
446 CancelPendingFaviconLoadRequests(node); | 448 // Log Histogram to determine how often |icon_url| is non empty in |
447 FOR_EACH_OBSERVER(BookmarkModelObserver, | 449 // practice. |
448 observers_, | 450 // TODO(pkotwicz): Do something more efficient if |icon_url| is non-empty |
449 BookmarkNodeFaviconChanged(this, node)); | 451 // many times a day for each user. |
| 452 UMA_HISTOGRAM_BOOLEAN("Bookmarks.OnFaviconsChangedIconURL", true); |
| 453 |
| 454 base::AutoLock url_lock(url_lock_); |
| 455 for (const BookmarkNode* node : nodes_ordered_by_url_set_) { |
| 456 if (icon_url == node->icon_url()) |
| 457 to_update.insert(node); |
450 } | 458 } |
451 } | 459 } |
| 460 |
| 461 for (const BookmarkNode* node : to_update) { |
| 462 // Rerequest the favicon. |
| 463 BookmarkNode* mutable_node = AsMutable(node); |
| 464 mutable_node->InvalidateFavicon(); |
| 465 CancelPendingFaviconLoadRequests(mutable_node); |
| 466 FOR_EACH_OBSERVER(BookmarkModelObserver, |
| 467 observers_, |
| 468 BookmarkNodeFaviconChanged(this, node)); |
| 469 } |
452 } | 470 } |
453 | 471 |
454 void BookmarkModel::SetDateAdded(const BookmarkNode* node, Time date_added) { | 472 void BookmarkModel::SetDateAdded(const BookmarkNode* node, Time date_added) { |
455 DCHECK(node && !is_permanent_node(node)); | 473 DCHECK(node && !is_permanent_node(node)); |
456 | 474 |
457 if (node->date_added() == date_added) | 475 if (node->date_added() == date_added) |
458 return; | 476 return; |
459 | 477 |
460 AsMutable(node)->set_date_added(date_added); | 478 AsMutable(node)->set_date_added(date_added); |
461 | 479 |
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1024 return scoped_ptr<BookmarkLoadDetails>(new BookmarkLoadDetails( | 1042 return scoped_ptr<BookmarkLoadDetails>(new BookmarkLoadDetails( |
1025 bb_node, | 1043 bb_node, |
1026 other_node, | 1044 other_node, |
1027 mobile_node, | 1045 mobile_node, |
1028 client_->GetLoadExtraNodesCallback(), | 1046 client_->GetLoadExtraNodesCallback(), |
1029 new BookmarkIndex(client_, accept_languages), | 1047 new BookmarkIndex(client_, accept_languages), |
1030 next_node_id_)); | 1048 next_node_id_)); |
1031 } | 1049 } |
1032 | 1050 |
1033 } // namespace bookmarks | 1051 } // namespace bookmarks |
OLD | NEW |