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 <Shlwapi.h> | |
8 | |
9 #include "base/bind.h" | 7 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
11 #include "base/command_line.h" | 9 #include "base/command_line.h" |
12 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
13 #include "base/macros.h" | 11 #include "base/macros.h" |
14 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
15 #include "base/path_service.h" | 13 #include "base/path_service.h" |
16 #include "base/sequenced_task_runner.h" | 14 #include "base/sequenced_task_runner.h" |
17 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
18 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 } | 251 } |
254 | 252 |
255 // Delete the contents in JumpListIcons directory and log the delete status | 253 // Delete the contents in JumpListIcons directory and log the delete status |
256 // to UMA. | 254 // to UMA. |
257 FolderDeleteResult delete_status = | 255 FolderDeleteResult delete_status = |
258 DeleteDirectoryContent(icon_dir, kFileDeleteLimit); | 256 DeleteDirectoryContent(icon_dir, kFileDeleteLimit); |
259 | 257 |
260 UMA_HISTOGRAM_ENUMERATION("WinJumplist.DeleteStatusJumpListIcons", | 258 UMA_HISTOGRAM_ENUMERATION("WinJumplist.DeleteStatusJumpListIcons", |
261 delete_status, END); | 259 delete_status, END); |
262 | 260 |
263 // If JumpListIcons directory is not empty, skip jumplist update and return | 261 // If JumpListIcons directory is not empty, skip updating the jumplist icons. |
264 // early. If the directory doesn't exist which shouldn't though, try to create | 262 // If the directory doesn't exist which shouldn't though, try to create |
265 // a new JumpListIcons directory. If the creation fails, return early. | 263 // a new JumpListIcons directory. If the creation fails, skip updating the |
266 if (base::DirectoryExists(icon_dir)) { | 264 // jumplist icons. The jumplist links should be updated anyway, as it doesn't |
267 DirectoryEmptyStatus empty_status = | 265 // involve disk IO. |
268 ::PathIsDirectoryEmpty(icon_dir.value().c_str()) ? EMPTY : NON_EMPTY; | 266 |
269 UMA_HISTOGRAM_ENUMERATION("WinJumplist.EmptyStatusJumpListIcons", | 267 DirectoryStatus dir_status = NON_EXIST; |
270 empty_status, EMPTY_STATUS_END); | 268 if (base::DirectoryExists(icon_dir)) |
271 if (empty_status == NON_EMPTY) | 269 dir_status = base::IsDirectoryEmpty(icon_dir) ? EMPTY : NON_EMPTY; |
272 return; | 270 |
273 } else if (!base::CreateDirectory(icon_dir)) { | 271 if (dir_status == NON_EXIST && base::CreateDirectory(icon_dir)) |
274 return; | 272 dir_status = EMPTY; |
| 273 |
| 274 UMA_HISTOGRAM_ENUMERATION("WinJumplist.DirectoryStatusJumpListIcons", |
| 275 dir_status, DIRECTORY_STATUS_END); |
| 276 |
| 277 if (dir_status == EMPTY) { |
| 278 // Create icon files for shortcuts in the "Most Visited" category. |
| 279 CreateIconFiles(icon_dir, local_most_visited_pages); |
| 280 |
| 281 // Create icon files for shortcuts in the "Recently Closed" |
| 282 // category. |
| 283 CreateIconFiles(icon_dir, local_recently_closed_pages); |
275 } | 284 } |
276 | 285 |
277 // Create temporary icon files for shortcuts in the "Most Visited" category. | 286 // Create a new JumpList and replace the current JumpList with it. The |
278 CreateIconFiles(icon_dir, local_most_visited_pages); | 287 // jumplist links are updated anyway, while the jumplist icons may not as |
279 | 288 // mentioned above. |
280 // Create temporary icon files for shortcuts in the "Recently Closed" | |
281 // category. | |
282 CreateIconFiles(icon_dir, local_recently_closed_pages); | |
283 | |
284 // We finished collecting all resources needed for updating an application | |
285 // JumpList. So, create a new JumpList and replace the current JumpList | |
286 // with it. | |
287 UpdateJumpList(app_id.c_str(), local_most_visited_pages, | 289 UpdateJumpList(app_id.c_str(), local_most_visited_pages, |
288 local_recently_closed_pages, incognito_availability); | 290 local_recently_closed_pages, incognito_availability); |
289 | 291 |
290 // Post a background task to delete JumpListIconsOld folder if it exists and | 292 // Post a background task to delete JumpListIconsOld folder if it exists and |
291 // log the delete results to UMA. | 293 // log the delete results to UMA. |
292 base::FilePath icon_dir_old = icon_dir.DirName().Append( | 294 base::FilePath icon_dir_old = icon_dir.DirName().Append( |
293 icon_dir.BaseName().value() + FILE_PATH_LITERAL("Old")); | 295 icon_dir.BaseName().value() + FILE_PATH_LITERAL("Old")); |
294 | 296 |
295 if (base::DirectoryExists(icon_dir_old)) { | 297 if (base::DirectoryExists(icon_dir_old)) { |
296 sequenced_task_runner->PostTask( | 298 sequenced_task_runner->PostTask( |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { | 625 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { |
624 } | 626 } |
625 | 627 |
626 void JumpList::TopSitesChanged(history::TopSites* top_sites, | 628 void JumpList::TopSitesChanged(history::TopSites* top_sites, |
627 ChangeReason change_reason) { | 629 ChangeReason change_reason) { |
628 top_sites->GetMostVisitedURLs( | 630 top_sites->GetMostVisitedURLs( |
629 base::Bind(&JumpList::OnMostVisitedURLsAvailable, | 631 base::Bind(&JumpList::OnMostVisitedURLsAvailable, |
630 weak_ptr_factory_.GetWeakPtr()), | 632 weak_ptr_factory_.GetWeakPtr()), |
631 false); | 633 false); |
632 } | 634 } |
OLD | NEW |