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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 if (!IconUtil::CreateIconFileFromImageFamily(image_family, path, | 116 if (!IconUtil::CreateIconFileFromImageFamily(image_family, path, |
117 IconUtil::NORMAL_WRITE)) | 117 IconUtil::NORMAL_WRITE)) |
118 return false; | 118 return false; |
119 | 119 |
120 // Add this icon file to the list and return its absolute path. | 120 // Add this icon file to the list and return its absolute path. |
121 // The IShellLink::SetIcon() function needs the absolute path to an icon. | 121 // The IShellLink::SetIcon() function needs the absolute path to an icon. |
122 *icon_path = path; | 122 *icon_path = path; |
123 return true; | 123 return true; |
124 } | 124 } |
125 | 125 |
126 // Helper method for RunUpdate to create icon files for the asynchrounously | 126 // Helper method for RunUpdateJumpList to create icon files for the |
grt (UTC plus 2)
2017/04/28 07:37:07
please follow the function comment style guideline
chengx
2017/04/28 22:29:29
Done. I've updated the comments throughout the fil
| |
127 // loaded icons. | 127 // asynchrounously loaded icons. |
128 void CreateIconFiles(const base::FilePath& icon_dir, | 128 void CreateIconFiles(const base::FilePath& icon_dir, |
129 const ShellLinkItemList& item_list, | 129 const ShellLinkItemList& item_list, |
130 size_t max_items) { | 130 size_t max_items) { |
131 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. | 131 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. |
132 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplist.CreateIconFilesDuration"); | 132 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplist.CreateIconFilesDuration"); |
133 | 133 |
134 for (ShellLinkItemList::const_iterator item = item_list.begin(); | 134 for (ShellLinkItemList::const_iterator item = item_list.begin(); |
135 item != item_list.end() && max_items > 0; ++item, --max_items) { | 135 item != item_list.end() && max_items > 0; ++item, --max_items) { |
136 base::FilePath icon_path; | 136 base::FilePath icon_path; |
137 if (CreateIconFile((*item)->icon_image(), icon_dir, &icon_path)) | 137 if (CreateIconFile((*item)->icon_image(), icon_dir, &icon_path)) |
138 (*item)->set_icon(icon_path.value(), 0); | 138 (*item)->set_icon(icon_path.value(), 0); |
139 } | 139 } |
140 } | 140 } |
141 | 141 |
142 // Helper method for RunUpdateJumpList to update icon files in |icon_dir|, which | |
143 // includes deleting old icons and creating at most |slot_limit| new icons for | |
144 // |page_list|. | |
145 void UpdateIconFiles(const base::FilePath& icon_dir, | |
146 const ShellLinkItemList& page_list, | |
147 size_t slot_limit) { | |
148 DeleteDirectoryContentAndLogRuntime(icon_dir, kFileDeleteLimit); | |
149 | |
150 if (!base::DirectoryExists(icon_dir)) | |
grt (UTC plus 2)
2017/04/28 07:37:07
base::CreateDirectory returns true if the director
chengx
2017/04/28 22:29:29
Done.
| |
151 base::CreateDirectory(icon_dir); | |
152 | |
153 // If the directory still doesn't exist or is non-empty, skip updating the | |
154 // jumplist icons for this jumplist category. The jumplist links should be | |
155 // updated later on anyway, as it doesn't involve disk IO. In this case, | |
grt (UTC plus 2)
2017/04/28 07:37:07
regarding this comment, are you saying that callin
chengx
2017/04/28 22:29:29
No, I didn't mean that. Calling the shell function
| |
156 // Chrome's icon will be used for the new links. | |
157 if (base::DirectoryExists(icon_dir) && base::IsDirectoryEmpty(icon_dir)) | |
158 CreateIconFiles(icon_dir, page_list, slot_limit); | |
159 } | |
160 | |
142 // Updates the "Tasks" category of the JumpList. | 161 // Updates the "Tasks" category of the JumpList. |
143 bool UpdateTaskCategory( | 162 bool UpdateTaskCategory( |
144 JumpListUpdater* jumplist_updater, | 163 JumpListUpdater* jumplist_updater, |
145 IncognitoModePrefs::Availability incognito_availability) { | 164 IncognitoModePrefs::Availability incognito_availability) { |
146 base::FilePath chrome_path; | 165 base::FilePath chrome_path; |
147 if (!PathService::Get(base::FILE_EXE, &chrome_path)) | 166 if (!PathService::Get(base::FILE_EXE, &chrome_path)) |
148 return false; | 167 return false; |
149 | 168 |
150 int icon_index = install_static::GetIconResourceIndex(); | 169 int icon_index = install_static::GetIconResourceIndex(); |
151 | 170 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 | 253 |
235 size_t most_visited_items = | 254 size_t most_visited_items = |
236 MulDiv(user_max_items_adjusted, kMostVisited, kTotal); | 255 MulDiv(user_max_items_adjusted, kMostVisited, kTotal); |
237 size_t recently_closed_items = user_max_items_adjusted - most_visited_items; | 256 size_t recently_closed_items = user_max_items_adjusted - most_visited_items; |
238 if (recently_closed_pages.size() < recently_closed_items) { | 257 if (recently_closed_pages.size() < recently_closed_items) { |
239 most_visited_items += recently_closed_items - recently_closed_pages.size(); | 258 most_visited_items += recently_closed_items - recently_closed_pages.size(); |
240 recently_closed_items = recently_closed_pages.size(); | 259 recently_closed_items = recently_closed_pages.size(); |
241 } | 260 } |
242 | 261 |
243 if (most_visited_pages_have_updates) { | 262 if (most_visited_pages_have_updates) { |
244 // Delete the content in JumpListIconsMostVisited folder and log the results | 263 // Delete the content in JumpListIconsMostVisited folder and log the runtime |
245 // to UMA. | 264 // to UMA. |
246 base::FilePath icon_dir_most_visited = icon_dir.DirName().Append( | 265 base::FilePath icon_dir_most_visited = icon_dir.DirName().Append( |
247 icon_dir.BaseName().value() + FILE_PATH_LITERAL("MostVisited")); | 266 icon_dir.BaseName().value() + FILE_PATH_LITERAL("MostVisited")); |
248 | 267 |
249 DeleteDirectoryContentAndLogResults(icon_dir_most_visited, | 268 UpdateIconFiles(icon_dir_most_visited, most_visited_pages, |
250 kFileDeleteLimit); | 269 most_visited_items); |
251 | |
252 // If the directory doesn't exist (we have tried to create it in | |
253 // DeleteDirectoryContentAndLogResults) or is not empty, skip updating the | |
254 // jumplist icons. The jumplist links should be updated anyway, as it | |
255 // doesn't involve disk IO. In this case, Chrome's icon will be used for the | |
256 // new links. | |
257 if (base::DirectoryExists(icon_dir_most_visited) && | |
258 base::IsDirectoryEmpty(icon_dir_most_visited)) { | |
259 // Create icon files for shortcuts in the "Most Visited" category. | |
260 CreateIconFiles(icon_dir_most_visited, most_visited_pages, | |
261 most_visited_items); | |
262 } | |
263 } | 270 } |
264 | 271 |
265 if (recently_closed_pages_have_updates) { | 272 if (recently_closed_pages_have_updates) { |
266 // Delete the content in JumpListIconsRecentClosed folder and log the | 273 // Delete the content in JumpListIconsRecentClosed folder and log the |
267 // results to UMA. | 274 // runtime to UMA. |
268 base::FilePath icon_dir_recent_closed = icon_dir.DirName().Append( | 275 base::FilePath icon_dir_recent_closed = icon_dir.DirName().Append( |
269 icon_dir.BaseName().value() + FILE_PATH_LITERAL("RecentClosed")); | 276 icon_dir.BaseName().value() + FILE_PATH_LITERAL("RecentClosed")); |
270 | 277 |
271 DeleteDirectoryContentAndLogResults(icon_dir_recent_closed, | 278 UpdateIconFiles(icon_dir_recent_closed, recently_closed_pages, |
272 kFileDeleteLimit); | 279 recently_closed_items); |
273 | |
274 if (base::DirectoryExists(icon_dir_recent_closed) && | |
275 base::IsDirectoryEmpty(icon_dir_recent_closed)) { | |
276 // Create icon files for shortcuts in the "Recently Closed" category. | |
277 CreateIconFiles(icon_dir_recent_closed, recently_closed_pages, | |
278 recently_closed_items); | |
279 } | |
280 } | 280 } |
281 | 281 |
282 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. | 282 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. |
283 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplist.UpdateJumpListDuration"); | 283 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplist.UpdateJumpListDuration"); |
284 | 284 |
285 // Update the "Most Visited" category of the JumpList if it exists. | 285 // Update the "Most Visited" category of the JumpList if it exists. |
286 // This update request is applied into the JumpList when we commit this | 286 // This update request is applied into the JumpList when we commit this |
287 // transaction. | 287 // transaction. |
288 if (!jumplist_updater.AddCustomCategory( | 288 if (!jumplist_updater.AddCustomCategory( |
289 l10n_util::GetStringUTF16(IDS_NEW_TAB_MOST_VISITED), | 289 l10n_util::GetStringUTF16(IDS_NEW_TAB_MOST_VISITED), |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
387 // When we add this object to the observer list, we save the pointer to this | 387 // When we add this object to the observer list, we save the pointer to this |
388 // TabRestoreService object. This pointer is used when we remove this object | 388 // TabRestoreService object. This pointer is used when we remove this object |
389 // from the observer list. | 389 // from the observer list. |
390 sessions::TabRestoreService* tab_restore_service = | 390 sessions::TabRestoreService* tab_restore_service = |
391 TabRestoreServiceFactory::GetForProfile(profile_); | 391 TabRestoreServiceFactory::GetForProfile(profile_); |
392 if (!tab_restore_service) | 392 if (!tab_restore_service) |
393 return; | 393 return; |
394 | 394 |
395 app_id_ = | 395 app_id_ = |
396 shell_integration::win::GetChromiumModelIdForProfile(profile_->GetPath()); | 396 shell_integration::win::GetChromiumModelIdForProfile(profile_->GetPath()); |
397 icon_dir_ = profile_->GetPath().Append(chrome::kJumpListIconDirname); | 397 icon_dir_ = profile_->GetPath().Append(chrome::kJumpListIconDirname); |
grt (UTC plus 2)
2017/04/28 07:37:07
this directory isn't used anymore, right? i think
chengx
2017/04/28 22:29:29
Agreed. I'll use another small CL for this as it d
| |
398 | 398 |
399 scoped_refptr<history::TopSites> top_sites = | 399 scoped_refptr<history::TopSites> top_sites = |
400 TopSitesFactory::GetForProfile(profile_); | 400 TopSitesFactory::GetForProfile(profile_); |
401 if (top_sites) { | 401 if (top_sites) { |
402 // TopSites updates itself after a delay. This is especially noticable when | 402 // TopSites updates itself after a delay. This is especially noticable when |
403 // your profile is empty. Ask TopSites to update itself when jumplist is | 403 // your profile is empty. Ask TopSites to update itself when jumplist is |
404 // initialized. | 404 // initialized. |
405 top_sites->SyncWithHistory(); | 405 top_sites->SyncWithHistory(); |
406 // Register as TopSitesObserver so that we can update ourselves when the | 406 // Register as TopSitesObserver so that we can update ourselves when the |
407 // TopSites changes. | 407 // TopSites changes. |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
679 // Post a task to update the JumpList, which consists of 1) delete old icons, | 679 // Post a task to update the JumpList, which consists of 1) delete old icons, |
680 // 2) create new icons, 3) notify the OS. | 680 // 2) create new icons, 3) notify the OS. |
681 update_jumplist_task_runner_->PostTask( | 681 update_jumplist_task_runner_->PostTask( |
682 FROM_HERE, base::Bind(&RunUpdateJumpList, incognito_availability, app_id_, | 682 FROM_HERE, base::Bind(&RunUpdateJumpList, incognito_availability, app_id_, |
683 icon_dir_, base::RetainedRef(jumplist_data_))); | 683 icon_dir_, base::RetainedRef(jumplist_data_))); |
684 | 684 |
685 // Post a task to delete JumpListIcons folder as it's no longer needed. | 685 // Post a task to delete JumpListIcons folder as it's no longer needed. |
686 // Now we have JumpListIconsMostVisited folder and JumpListIconsRecentClosed | 686 // Now we have JumpListIconsMostVisited folder and JumpListIconsRecentClosed |
687 // folder instead. | 687 // folder instead. |
688 delete_jumplisticons_task_runner_->PostTask( | 688 delete_jumplisticons_task_runner_->PostTask( |
689 FROM_HERE, | 689 FROM_HERE, base::Bind(&DeleteDirectory, icon_dir_, kFileDeleteLimit)); |
690 base::Bind(&DeleteDirectoryAndLogResults, icon_dir_, kFileDeleteLimit)); | |
691 | 690 |
692 // Post a task to delete JumpListIconsOld folder as it's no longer needed. | 691 // Post a task to delete JumpListIconsOld folder as it's no longer needed. |
693 base::FilePath icon_dir_old = icon_dir_.DirName().Append( | 692 base::FilePath icon_dir_old = icon_dir_.DirName().Append( |
694 icon_dir_.BaseName().value() + FILE_PATH_LITERAL("Old")); | 693 icon_dir_.BaseName().value() + FILE_PATH_LITERAL("Old")); |
695 | 694 |
696 delete_jumplisticons_task_runner_->PostTask( | 695 delete_jumplisticons_task_runner_->PostTask( |
697 FROM_HERE, base::Bind(&DeleteDirectoryAndLogResults, | 696 FROM_HERE, |
698 std::move(icon_dir_old), kFileDeleteLimit)); | 697 base::Bind(&DeleteDirectory, std::move(icon_dir_old), kFileDeleteLimit)); |
699 } | 698 } |
700 | 699 |
701 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { | 700 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { |
702 } | 701 } |
703 | 702 |
704 void JumpList::TopSitesChanged(history::TopSites* top_sites, | 703 void JumpList::TopSitesChanged(history::TopSites* top_sites, |
705 ChangeReason change_reason) { | 704 ChangeReason change_reason) { |
706 top_sites->GetMostVisitedURLs( | 705 top_sites->GetMostVisitedURLs( |
707 base::Bind(&JumpList::OnMostVisitedURLsAvailable, | 706 base::Bind(&JumpList::OnMostVisitedURLsAvailable, |
708 weak_ptr_factory_.GetWeakPtr()), | 707 weak_ptr_factory_.GetWeakPtr()), |
709 false); | 708 false); |
710 } | 709 } |
OLD | NEW |