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/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback_helpers.h" |
9 #include "base/command_line.h" | 10 #include "base/command_line.h" |
10 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
13 #include "base/path_service.h" | 14 #include "base/path_service.h" |
14 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
16 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
17 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" |
18 #include "chrome/browser/chrome_notification_types.h" | 19 #include "chrome/browser/chrome_notification_types.h" |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 DELETE_SRC_FAILED = 1 << 2, | 259 DELETE_SRC_FAILED = 1 << 2, |
259 CREATE_SRC_FAILED = 1 << 3, | 260 CREATE_SRC_FAILED = 1 << 3, |
260 // This value is beyond the sum of all bit fields above and | 261 // This value is beyond the sum of all bit fields above and |
261 // should remain last (shifted by one more than the last value) | 262 // should remain last (shifted by one more than the last value) |
262 END = 1 << 4 | 263 END = 1 << 4 |
263 }; | 264 }; |
264 | 265 |
265 // This variable records the status of three folder operations. | 266 // This variable records the status of three folder operations. |
266 uint32_t folder_operation_status = FolderOperationResult::SUCCESS; | 267 uint32_t folder_operation_status = FolderOperationResult::SUCCESS; |
267 | 268 |
| 269 base::ScopedClosureRunner log_operation_status_when_done(base::Bind( |
| 270 [](uint32_t* folder_operation_status_ptr) { |
| 271 UMA_HISTOGRAM_ENUMERATION("WinJumplist.DetailedFolderResults", |
| 272 *folder_operation_status_ptr, |
| 273 FolderOperationResult::END); |
| 274 }, |
| 275 base::Unretained(&folder_operation_status))); |
| 276 |
| 277 // If deletion of |icon_dir_old| fails, do not move |icon_dir| to |
| 278 // |icon_dir_old|, instead, delete |icon_dir| directly to avoid bloating |
| 279 // |icon_dir_old| by moving more things to it. |
268 if (!base::DeleteFile(icon_dir_old, true)) { | 280 if (!base::DeleteFile(icon_dir_old, true)) { |
269 folder_operation_status |= FolderOperationResult::DELETE_DEST_FAILED; | 281 folder_operation_status |= FolderOperationResult::DELETE_DEST_FAILED; |
270 // If deletion of |icon_dir_old| fails, do not move |icon_dir| to | 282 // If deletion of |icon_dir| fails, exit early. This skips creating the same |
271 // |icon_dir_old|, instead, delete |icon_dir| directly to avoid bloating | 283 // directory and updating jumplist icons to avoid bloating the JumplistIcons |
272 // |icon_dir_old| by moving more things to it. | 284 // folder. |
273 if (!base::DeleteFile(icon_dir, true)) | 285 if (!base::DeleteFile(icon_dir, true)) { |
274 folder_operation_status |= FolderOperationResult::DELETE_SRC_FAILED; | 286 folder_operation_status |= FolderOperationResult::DELETE_SRC_FAILED; |
| 287 return; |
| 288 } |
275 } else if (!base::Move(icon_dir, icon_dir_old)) { | 289 } else if (!base::Move(icon_dir, icon_dir_old)) { |
276 folder_operation_status |= FolderOperationResult::MOVE_FAILED; | 290 folder_operation_status |= FolderOperationResult::MOVE_FAILED; |
277 // If Move() fails, delete |icon_dir| to avoid file accumulation in this | 291 // If Move() fails, delete |icon_dir| to avoid file accumulation in this |
278 // directory, which can eventually lead the folder to be huge. | 292 // directory, which can eventually lead the folder to be huge. |
279 if (!base::DeleteFile(icon_dir, true)) | 293 if (!base::DeleteFile(icon_dir, true)) { |
280 folder_operation_status |= FolderOperationResult::DELETE_SRC_FAILED; | 294 folder_operation_status |= FolderOperationResult::DELETE_SRC_FAILED; |
| 295 return; |
| 296 } |
281 } | 297 } |
| 298 |
282 if (!base::CreateDirectory(icon_dir)) | 299 if (!base::CreateDirectory(icon_dir)) |
283 folder_operation_status |= FolderOperationResult::CREATE_SRC_FAILED; | 300 folder_operation_status |= FolderOperationResult::CREATE_SRC_FAILED; |
284 | 301 |
285 UMA_HISTOGRAM_ENUMERATION("WinJumplist.DetailedFolderResults", | |
286 folder_operation_status, | |
287 FolderOperationResult::END); | |
288 | |
289 // Create temporary icon files for shortcuts in the "Most Visited" category. | 302 // Create temporary icon files for shortcuts in the "Most Visited" category. |
290 CreateIconFiles(icon_dir, local_most_visited_pages); | 303 CreateIconFiles(icon_dir, local_most_visited_pages); |
291 | 304 |
292 // Create temporary icon files for shortcuts in the "Recently Closed" | 305 // Create temporary icon files for shortcuts in the "Recently Closed" |
293 // category. | 306 // category. |
294 CreateIconFiles(icon_dir, local_recently_closed_pages); | 307 CreateIconFiles(icon_dir, local_recently_closed_pages); |
295 | 308 |
296 // We finished collecting all resources needed for updating an application | 309 // We finished collecting all resources needed for updating an application |
297 // JumpList. So, create a new JumpList and replace the current JumpList | 310 // JumpList. So, create a new JumpList and replace the current JumpList |
298 // with it. | 311 // with it. |
299 UpdateJumpList(app_id.c_str(), | 312 UpdateJumpList(app_id.c_str(), local_most_visited_pages, |
300 local_most_visited_pages, | 313 local_recently_closed_pages, incognito_availability); |
301 local_recently_closed_pages, | |
302 incognito_availability); | |
303 } | 314 } |
304 | 315 |
305 } // namespace | 316 } // namespace |
306 | 317 |
307 JumpList::JumpListData::JumpListData() {} | 318 JumpList::JumpListData::JumpListData() {} |
308 | 319 |
309 JumpList::JumpListData::~JumpListData() {} | 320 JumpList::JumpListData::~JumpListData() {} |
310 | 321 |
311 JumpList::JumpList(Profile* profile) | 322 JumpList::JumpList(Profile* profile) |
312 : RefcountedKeyedService(content::BrowserThread::GetTaskRunnerForThread( | 323 : RefcountedKeyedService(content::BrowserThread::GetTaskRunnerForThread( |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { | 633 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { |
623 } | 634 } |
624 | 635 |
625 void JumpList::TopSitesChanged(history::TopSites* top_sites, | 636 void JumpList::TopSitesChanged(history::TopSites* top_sites, |
626 ChangeReason change_reason) { | 637 ChangeReason change_reason) { |
627 top_sites->GetMostVisitedURLs( | 638 top_sites->GetMostVisitedURLs( |
628 base::Bind(&JumpList::OnMostVisitedURLsAvailable, | 639 base::Bind(&JumpList::OnMostVisitedURLsAvailable, |
629 weak_ptr_factory_.GetWeakPtr()), | 640 weak_ptr_factory_.GetWeakPtr()), |
630 false); | 641 false); |
631 } | 642 } |
OLD | NEW |