OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/win/jumplist.h" | 5 #include "chrome/browser/win/jumplist.h" |
6 | 6 |
7 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 TabRestoreServiceFactory::GetForProfile(profile_); | 214 TabRestoreServiceFactory::GetForProfile(profile_); |
215 if (!tab_restore_service) | 215 if (!tab_restore_service) |
216 return; | 216 return; |
217 | 217 |
218 app_id_ = | 218 app_id_ = |
219 shell_integration::win::GetChromiumModelIdForProfile(profile_->GetPath()); | 219 shell_integration::win::GetChromiumModelIdForProfile(profile_->GetPath()); |
220 | 220 |
221 scoped_refptr<history::TopSites> top_sites = | 221 scoped_refptr<history::TopSites> top_sites = |
222 TopSitesFactory::GetForProfile(profile_); | 222 TopSitesFactory::GetForProfile(profile_); |
223 if (top_sites) { | 223 if (top_sites) { |
224 // TopSites updates itself after a delay. This is especially noticable when | |
225 // your profile is empty. Ask TopSites to update itself when jumplist is | |
226 // initialized. | |
227 top_sites->SyncWithHistory(); | |
228 // Register as TopSitesObserver so that we can update ourselves when the | 224 // Register as TopSitesObserver so that we can update ourselves when the |
229 // TopSites changes. | 225 // TopSites changes. TopSites updates itself after a delay. This is |
226 // especially noticable when your profile is empty. | |
230 top_sites->AddObserver(this); | 227 top_sites->AddObserver(this); |
231 } | 228 } |
232 tab_restore_service->AddObserver(this); | 229 tab_restore_service->AddObserver(this); |
233 pref_change_registrar_.reset(new PrefChangeRegistrar); | 230 pref_change_registrar_.reset(new PrefChangeRegistrar); |
234 pref_change_registrar_->Init(profile_->GetPrefs()); | 231 pref_change_registrar_->Init(profile_->GetPrefs()); |
235 pref_change_registrar_->Add( | 232 pref_change_registrar_->Add( |
236 prefs::kIncognitoModeAvailability, | 233 prefs::kIncognitoModeAvailability, |
237 base::Bind(&JumpList::OnIncognitoAvailabilityChanged, this)); | 234 base::Bind(&JumpList::OnIncognitoAvailabilityChanged, this)); |
238 } | 235 } |
239 | 236 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
276 | 273 |
277 void JumpList::ShutdownOnUIThread() { | 274 void JumpList::ShutdownOnUIThread() { |
278 DCHECK(CalledOnValidThread()); | 275 DCHECK(CalledOnValidThread()); |
279 Terminate(); | 276 Terminate(); |
280 } | 277 } |
281 | 278 |
282 void JumpList::OnMostVisitedURLsAvailable( | 279 void JumpList::OnMostVisitedURLsAvailable( |
283 const history::MostVisitedURLList& urls) { | 280 const history::MostVisitedURLList& urls) { |
284 DCHECK(CalledOnValidThread()); | 281 DCHECK(CalledOnValidThread()); |
285 | 282 |
286 // At most 9 JumpList items can be displayed for the "Most Visited" | 283 // At most 5 JumpList items can be displayed for the "Most Visited" |
287 // category. | 284 // category. |
288 const int kMostVistedCount = 9; | 285 const int kMostVistedCount = 5; |
289 { | 286 { |
290 JumpListData* data = &jumplist_data_->data; | 287 JumpListData* data = &jumplist_data_->data; |
291 base::AutoLock auto_lock(data->list_lock_); | 288 base::AutoLock auto_lock(data->list_lock_); |
292 data->most_visited_pages_.clear(); | 289 data->most_visited_pages_.clear(); |
293 | 290 |
294 for (size_t i = 0; i < urls.size() && i < kMostVistedCount; i++) { | 291 for (size_t i = 0; i < urls.size() && i < kMostVistedCount; i++) { |
295 const history::MostVisitedURL& url = urls[i]; | 292 const history::MostVisitedURL& url = urls[i]; |
296 scoped_refptr<ShellLinkItem> link = CreateShellLink(); | 293 scoped_refptr<ShellLinkItem> link = CreateShellLink(); |
297 std::string url_string = url.url.spec(); | 294 std::string url_string = url.url.spec(); |
298 base::string16 url_string_wide = base::UTF8ToUTF16(url_string); | 295 base::string16 url_string_wide = base::UTF8ToUTF16(url_string); |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
525 base::Bind(&JumpList::DeferredTopSitesChanged, base::Unretained(this))); | 522 base::Bind(&JumpList::DeferredTopSitesChanged, base::Unretained(this))); |
526 } | 523 } |
527 } | 524 } |
528 | 525 |
529 void JumpList::DeferredTopSitesChanged() { | 526 void JumpList::DeferredTopSitesChanged() { |
530 if (updates_to_skip_ > 0) { | 527 if (updates_to_skip_ > 0) { |
531 --updates_to_skip_; | 528 --updates_to_skip_; |
532 return; | 529 return; |
533 } | 530 } |
534 | 531 |
532 // Opening the first tab in one session triggers a TopSite history sync. | |
533 // Delay this sync till the first tab is closed to allow the "recently closed" | |
534 // category from last session stay longer. | |
535 if (!has_tab_closed_) | |
536 return; | |
537 | |
535 scoped_refptr<history::TopSites> top_sites = | 538 scoped_refptr<history::TopSites> top_sites = |
536 TopSitesFactory::GetForProfile(profile_); | 539 TopSitesFactory::GetForProfile(profile_); |
537 if (top_sites) { | 540 if (top_sites) { |
538 top_sites->GetMostVisitedURLs( | 541 top_sites->GetMostVisitedURLs( |
539 base::Bind(&JumpList::OnMostVisitedURLsAvailable, | 542 base::Bind(&JumpList::OnMostVisitedURLsAvailable, |
540 weak_ptr_factory_.GetWeakPtr()), | 543 weak_ptr_factory_.GetWeakPtr()), |
541 false); | 544 false); |
542 } | 545 } |
543 } | 546 } |
544 | 547 |
545 void JumpList::DeferredTabRestoreServiceChanged() { | 548 void JumpList::DeferredTabRestoreServiceChanged() { |
546 if (updates_to_skip_ > 0) { | 549 if (updates_to_skip_ > 0) { |
grt (UTC plus 2)
2017/05/18 09:35:14
please add
DCHECK(CalledOnValidThread());
since
chengx
2017/05/19 02:11:58
Done.
| |
547 --updates_to_skip_; | 550 --updates_to_skip_; |
548 return; | 551 return; |
549 } | 552 } |
550 | 553 |
554 // Force to do a TopSite history sync when closing a first tab in one session. | |
grt (UTC plus 2)
2017/05/18 09:35:14
nit: "Force a TopSite..."
chengx
2017/05/19 02:11:58
Done.
| |
555 if (!has_tab_closed_) { | |
556 has_tab_closed_ = true; | |
557 scoped_refptr<history::TopSites> top_sites = | |
558 TopSitesFactory::GetForProfile(profile_); | |
559 if (top_sites) | |
560 top_sites->SyncWithHistory(); | |
561 } | |
562 | |
551 // Create a list of ShellLinkItems from the "Recently Closed" pages. | 563 // Create a list of ShellLinkItems from the "Recently Closed" pages. |
552 // As noted above, we create a ShellLinkItem objects with the following | 564 // As noted above, we create a ShellLinkItem objects with the following |
553 // parameters. | 565 // parameters. |
554 // * arguments | 566 // * arguments |
555 // The last URL of the tab object. | 567 // The last URL of the tab object. |
556 // * title | 568 // * title |
557 // The title of the last URL. | 569 // The title of the last URL. |
558 // * icon | 570 // * icon |
559 // An empty string. This value is to be updated in OnFaviconDataAvailable(). | 571 // An empty string. This value is to be updated in OnFaviconDataAvailable(). |
560 const int kRecentlyClosedCount = 3; | 572 const int kRecentlyClosedCount = 3; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
635 // than the maximum allowed time, as it's very likely the following update | 647 // than the maximum allowed time, as it's very likely the following update |
636 // steps will also take a long time. As we've not updated the icons on the | 648 // steps will also take a long time. As we've not updated the icons on the |
637 // disk, discarding this update wont't affect the current JumpList used by OS. | 649 // disk, discarding this update wont't affect the current JumpList used by OS. |
638 if (begin_update_timer.Elapsed() >= kTimeOutForJumplistBeginUpdate) { | 650 if (begin_update_timer.Elapsed() >= kTimeOutForJumplistBeginUpdate) { |
639 updates_to_skip_ = kUpdatesToSkipUnderHeavyLoad; | 651 updates_to_skip_ = kUpdatesToSkipUnderHeavyLoad; |
640 return false; | 652 return false; |
641 } | 653 } |
642 | 654 |
643 // The default maximum number of items to display in JumpList is 10. | 655 // The default maximum number of items to display in JumpList is 10. |
644 // https://msdn.microsoft.com/library/windows/desktop/dd378398.aspx | 656 // https://msdn.microsoft.com/library/windows/desktop/dd378398.aspx |
645 // The "Most visited" category title always takes 1 of the JumpList slots if | 657 // The "Most visited" and "Recently closed" category titles always takes 2 of |
646 // |most_visited_pages| isn't empty. | 658 // the JumpList slots. For the remaining slots, we allocate 5/8 (i.e., 5 slots |
647 // The "Recently closed" category title will also take 1 if | 659 // by default) to "most-visited" items and 3/8 (i.e., 3 slots by default) to |
648 // |recently_closed_pages| isn't empty. | 660 // "recently-closed" items, respectively. |
649 // For the remaining slots, we allocate 5/8 (i.e., 5 slots if both categories | |
650 // present) to "most-visited" items and 3/8 (i.e., 3 slots if both categories | |
651 // present) to "recently-closed" items, respectively. | |
652 // Nevertheless, if there are not so many items in |recently_closed_pages|, | |
653 // we give the remaining slots to "most-visited" items. | |
654 | 661 |
655 const int kMostVisited = 50; | 662 const int kMostVisited = 50; |
656 const int kRecentlyClosed = 30; | 663 const int kRecentlyClosed = 30; |
657 const int kTotal = kMostVisited + kRecentlyClosed; | 664 const int kTotal = kMostVisited + kRecentlyClosed; |
658 | 665 |
659 // Adjust the available jumplist slots to account for the category titles. | 666 // Adjust the available jumplist slots to account for the two category titles. |
660 size_t user_max_items_adjusted = jumplist_updater.user_max_items(); | 667 size_t user_max_items_adjusted = jumplist_updater.user_max_items() - 2; |
661 if (!most_visited_pages.empty()) | |
662 --user_max_items_adjusted; | |
663 if (!recently_closed_pages.empty()) | |
664 --user_max_items_adjusted; | |
665 | 668 |
669 // Cap 5 items for "Most visited" category, and 3 items for "Recently closed" | |
670 // category. | |
671 user_max_items_adjusted = std::min((int)jumplist_updater.user_max_items(), 8); | |
666 size_t most_visited_items = | 672 size_t most_visited_items = |
667 MulDiv(user_max_items_adjusted, kMostVisited, kTotal); | 673 MulDiv(user_max_items_adjusted, kMostVisited, kTotal); |
668 size_t recently_closed_items = user_max_items_adjusted - most_visited_items; | 674 size_t recently_closed_items = user_max_items_adjusted - most_visited_items; |
669 if (recently_closed_pages.size() < recently_closed_items) { | |
670 most_visited_items += recently_closed_items - recently_closed_pages.size(); | |
671 recently_closed_items = recently_closed_pages.size(); | |
672 } | |
673 | 675 |
674 // Record the desired number of icons to create in this JumpList update. | 676 // Record the desired number of icons to create in this JumpList update. |
675 int icons_to_create = 0; | 677 int icons_to_create = 0; |
676 | 678 |
677 // Update the icons for "Most Visisted" category of the JumpList if needed. | 679 // Update the icons for "Most Visisted" category of the JumpList if needed. |
678 if (most_visited_pages_have_updates) { | 680 if (most_visited_pages_have_updates) { |
679 base::FilePath icon_dir_most_visited = GenerateJumplistIconDirName( | 681 base::FilePath icon_dir_most_visited = GenerateJumplistIconDirName( |
680 profile_dir, FILE_PATH_LITERAL("MostVisited")); | 682 profile_dir, FILE_PATH_LITERAL("MostVisited")); |
681 | 683 |
682 UpdateIconFiles(icon_dir_most_visited, most_visited_pages, | 684 UpdateIconFiles(icon_dir_most_visited, most_visited_pages, |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
788 app_id, profile_dir, local_most_visited_pages, | 790 app_id, profile_dir, local_most_visited_pages, |
789 local_recently_closed_pages, most_visited_pages_have_updates, | 791 local_recently_closed_pages, most_visited_pages_have_updates, |
790 recently_closed_pages_have_updates, incognito_availability)) { | 792 recently_closed_pages_have_updates, incognito_availability)) { |
791 base::AutoLock auto_lock(data->list_lock_); | 793 base::AutoLock auto_lock(data->list_lock_); |
792 if (most_visited_pages_have_updates) | 794 if (most_visited_pages_have_updates) |
793 data->most_visited_pages_have_updates_ = true; | 795 data->most_visited_pages_have_updates_ = true; |
794 if (recently_closed_pages_have_updates) | 796 if (recently_closed_pages_have_updates) |
795 data->recently_closed_pages_have_updates_ = true; | 797 data->recently_closed_pages_have_updates_ = true; |
796 } | 798 } |
797 } | 799 } |
OLD | NEW |