Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/jumplist_win.h" | 5 #include "chrome/browser/jumplist_win.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <shobjidl.h> | 8 #include <shobjidl.h> |
| 9 #include <propkey.h> | 9 #include <propkey.h> |
| 10 #include <propvarutil.h> | 10 #include <propvarutil.h> |
| 11 | 11 |
| 12 #include <string> | 12 #include <string> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/bind.h" | 15 #include "base/bind.h" |
| 16 #include "base/bind_helpers.h" | 16 #include "base/bind_helpers.h" |
| 17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
| 18 #include "base/file_util.h" | 18 #include "base/file_util.h" |
| 19 #include "base/path_service.h" | 19 #include "base/path_service.h" |
| 20 #include "base/string_util.h" | 20 #include "base/string_util.h" |
| 21 #include "base/threading/thread.h" | 21 #include "base/threading/thread.h" |
| 22 #include "base/time.h" | |
| 22 #include "base/utf_string_conversions.h" | 23 #include "base/utf_string_conversions.h" |
| 23 #include "base/win/scoped_comptr.h" | 24 #include "base/win/scoped_comptr.h" |
| 24 #include "base/win/windows_version.h" | 25 #include "base/win/windows_version.h" |
| 25 #include "chrome/browser/favicon/favicon_service.h" | 26 #include "chrome/browser/favicon/favicon_service.h" |
| 26 #include "chrome/browser/favicon/favicon_service_factory.h" | 27 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 27 #include "chrome/browser/history/history.h" | 28 #include "chrome/browser/history/history.h" |
| 28 #include "chrome/browser/history/page_usage_data.h" | 29 #include "chrome/browser/history/page_usage_data.h" |
| 29 #include "chrome/browser/history/top_sites.h" | 30 #include "chrome/browser/history/top_sites.h" |
| 30 #include "chrome/browser/profiles/profile.h" | 31 #include "chrome/browser/profiles/profile.h" |
| 31 #include "chrome/browser/sessions/session_types.h" | 32 #include "chrome/browser/sessions/session_types.h" |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 481 return false; | 482 return false; |
| 482 | 483 |
| 483 return true; | 484 return true; |
| 484 } | 485 } |
| 485 | 486 |
| 486 } // namespace | 487 } // namespace |
| 487 | 488 |
| 488 JumpList::JumpList() | 489 JumpList::JumpList() |
| 489 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), | 490 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), |
| 490 profile_(NULL), | 491 profile_(NULL), |
| 491 task_id_(CancelableTaskTracker::kBadTaskId) { | 492 task_id_(CancelableTaskTracker::kBadTaskId), |
| 493 status_(UPDATE_NOT_RUN) { | |
| 492 } | 494 } |
| 493 | 495 |
| 494 JumpList::~JumpList() { | 496 JumpList::~JumpList() { |
| 495 Terminate(); | 497 Terminate(); |
| 496 } | 498 } |
| 497 | 499 |
| 498 // static | 500 // static |
| 499 bool JumpList::Enabled() { | 501 bool JumpList::Enabled() { |
| 500 return (base::win::GetVersion() >= base::win::VERSION_WIN7 && | 502 return (base::win::GetVersion() >= base::win::VERSION_WIN7 && |
| 501 !CommandLine::ForCurrentProcess()->HasSwitch( | 503 !CommandLine::ForCurrentProcess()->HasSwitch( |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 688 } | 690 } |
| 689 } | 691 } |
| 690 | 692 |
| 691 void JumpList::StartLoadingFavicon() { | 693 void JumpList::StartLoadingFavicon() { |
| 692 GURL url; | 694 GURL url; |
| 693 { | 695 { |
| 694 base::AutoLock auto_lock(list_lock_); | 696 base::AutoLock auto_lock(list_lock_); |
| 695 if (icon_urls_.empty()) { | 697 if (icon_urls_.empty()) { |
| 696 // No more favicons are needed by the application JumpList. Schedule a | 698 // No more favicons are needed by the application JumpList. Schedule a |
| 697 // RunUpdate call. | 699 // RunUpdate call. |
| 698 BrowserThread::PostTask( | 700 switch (status_) { |
| 699 BrowserThread::FILE, FROM_HERE, | 701 case UPDATE_NOT_RUN: |
| 700 base::Bind(&JumpList::RunUpdate, this)); | 702 BrowserThread::PostDelayedTask( |
| 703 BrowserThread::FILE, FROM_HERE, | |
| 704 base::Bind(&JumpList::RunUpdate, this), | |
| 705 base::TimeDelta::FromSeconds(15)); | |
|
jeremy
2012/12/11 14:57:22
Some startups are longer than 15 seconds, in other
Cait (Slow)
2012/12/11 15:37:44
In this case, would NOTIFICATION_LOAD_COMPLETED_MA
jeremy
2012/12/11 16:50:02
Only for telling when startup is complete, thanks!
Cait (Slow)
2012/12/11 20:54:34
Done.
| |
| 706 status_ = UPDATE_PENDING; | |
| 707 break; | |
| 708 case UPDATE_PENDING: | |
| 709 break; | |
| 710 case NONE_PENDING: | |
| 711 BrowserThread::PostTask( | |
| 712 BrowserThread::FILE, FROM_HERE, | |
| 713 base::Bind(&JumpList::RunUpdate, this)); | |
| 714 break; | |
| 715 } | |
| 716 | |
| 701 return; | 717 return; |
| 702 } | 718 } |
| 703 // Ask FaviconService if it has a favicon of a URL. | 719 // Ask FaviconService if it has a favicon of a URL. |
| 704 // When FaviconService has one, it will call OnFaviconDataAvailable(). | 720 // When FaviconService has one, it will call OnFaviconDataAvailable(). |
| 705 url = GURL(icon_urls_.front().first); | 721 url = GURL(icon_urls_.front().first); |
| 706 } | 722 } |
| 707 FaviconService* favicon_service = | 723 FaviconService* favicon_service = |
| 708 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | 724 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
| 709 task_id_ = favicon_service->GetFaviconImageForURL( | 725 task_id_ = favicon_service->GetFaviconImageForURL( |
| 710 FaviconService::FaviconForURLParams(profile_, | 726 FaviconService::FaviconForURLParams(profile_, |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 737 // Check whether we need to load more favicons. | 753 // Check whether we need to load more favicons. |
| 738 StartLoadingFavicon(); | 754 StartLoadingFavicon(); |
| 739 } | 755 } |
| 740 | 756 |
| 741 void JumpList::RunUpdate() { | 757 void JumpList::RunUpdate() { |
| 742 ShellLinkItemList local_most_visited_pages; | 758 ShellLinkItemList local_most_visited_pages; |
| 743 ShellLinkItemList local_recently_closed_pages; | 759 ShellLinkItemList local_recently_closed_pages; |
| 744 | 760 |
| 745 { | 761 { |
| 746 base::AutoLock auto_lock(list_lock_); | 762 base::AutoLock auto_lock(list_lock_); |
| 763 status_ = NONE_PENDING; | |
| 747 // Make sure we are not out of date: if icon_urls_ is not empty, then | 764 // Make sure we are not out of date: if icon_urls_ is not empty, then |
| 748 // another notification has been received since we processed this one | 765 // another notification has been received since we processed this one |
| 749 if (!icon_urls_.empty()) | 766 if (!icon_urls_.empty()) |
| 750 return; | 767 return; |
| 751 | 768 |
| 752 // Make local copies of lists so we can release the lock. | 769 // Make local copies of lists so we can release the lock. |
| 753 local_most_visited_pages = most_visited_pages_; | 770 local_most_visited_pages = most_visited_pages_; |
| 754 local_recently_closed_pages = recently_closed_pages_; | 771 local_recently_closed_pages = recently_closed_pages_; |
| 755 } | 772 } |
| 756 | 773 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 778 } | 795 } |
| 779 | 796 |
| 780 void JumpList::CreateIconFiles(const ShellLinkItemList& item_list) { | 797 void JumpList::CreateIconFiles(const ShellLinkItemList& item_list) { |
| 781 for (ShellLinkItemList::const_iterator item = item_list.begin(); | 798 for (ShellLinkItemList::const_iterator item = item_list.begin(); |
| 782 item != item_list.end(); ++item) { | 799 item != item_list.end(); ++item) { |
| 783 FilePath icon_path; | 800 FilePath icon_path; |
| 784 if (CreateIconFile((*item)->data(), icon_dir_, &icon_path)) | 801 if (CreateIconFile((*item)->data(), icon_dir_, &icon_path)) |
| 785 (*item)->SetIcon(icon_path.value(), 0, true); | 802 (*item)->SetIcon(icon_path.value(), 0, true); |
| 786 } | 803 } |
| 787 } | 804 } |
| OLD | NEW |