Chromium Code Reviews| 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/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 258 DELETE_SRC_FAILED = 1 << 2, | 258 DELETE_SRC_FAILED = 1 << 2, |
| 259 CREATE_SRC_FAILED = 1 << 3, | 259 CREATE_SRC_FAILED = 1 << 3, |
| 260 // This value is beyond the sum of all bit fields above and | 260 // This value is beyond the sum of all bit fields above and |
| 261 // should remain last (shifted by one more than the last value) | 261 // should remain last (shifted by one more than the last value) |
| 262 END = 1 << 4 | 262 END = 1 << 4 |
| 263 }; | 263 }; |
| 264 | 264 |
| 265 // This variable records the status of three folder operations. | 265 // This variable records the status of three folder operations. |
| 266 uint32_t folder_operation_status = FolderOperationResult::SUCCESS; | 266 uint32_t folder_operation_status = FolderOperationResult::SUCCESS; |
| 267 | 267 |
| 268 // This variable records the status of |icon_dir| deletion. | |
| 269 bool icon_dir_delete_success = true; | |
| 270 | |
| 268 if (!base::DeleteFile(icon_dir_old, true)) { | 271 if (!base::DeleteFile(icon_dir_old, true)) { |
| 269 folder_operation_status |= FolderOperationResult::DELETE_DEST_FAILED; | 272 folder_operation_status |= FolderOperationResult::DELETE_DEST_FAILED; |
| 270 // If deletion of |icon_dir_old| fails, do not move |icon_dir| to | 273 // If deletion of |icon_dir_old| fails, do not move |icon_dir| to |
| 271 // |icon_dir_old|, instead, delete |icon_dir| directly to avoid bloating | 274 // |icon_dir_old|, instead, delete |icon_dir| directly to avoid bloating |
| 272 // |icon_dir_old| by moving more things to it. | 275 // |icon_dir_old| by moving more things to it. |
| 273 if (!base::DeleteFile(icon_dir, true)) | 276 if (!base::DeleteFile(icon_dir, true)) { |
| 274 folder_operation_status |= FolderOperationResult::DELETE_SRC_FAILED; | 277 folder_operation_status |= FolderOperationResult::DELETE_SRC_FAILED; |
| 278 icon_dir_delete_success = false; | |
| 279 } | |
| 275 } else if (!base::Move(icon_dir, icon_dir_old)) { | 280 } else if (!base::Move(icon_dir, icon_dir_old)) { |
| 276 folder_operation_status |= FolderOperationResult::MOVE_FAILED; | 281 folder_operation_status |= FolderOperationResult::MOVE_FAILED; |
| 277 // If Move() fails, delete |icon_dir| to avoid file accumulation in this | 282 // If Move() fails, delete |icon_dir| to avoid file accumulation in this |
| 278 // directory, which can eventually lead the folder to be huge. | 283 // directory, which can eventually lead the folder to be huge. |
| 279 if (!base::DeleteFile(icon_dir, true)) | 284 if (!base::DeleteFile(icon_dir, true)) { |
| 280 folder_operation_status |= FolderOperationResult::DELETE_SRC_FAILED; | 285 folder_operation_status |= FolderOperationResult::DELETE_SRC_FAILED; |
| 286 icon_dir_delete_success = false; | |
| 287 } | |
| 281 } | 288 } |
| 282 if (!base::CreateDirectory(icon_dir)) | 289 |
|
gab
2017/03/03 07:35:01
Prefer an early exit (return;) above instead of ca
chengx
2017/03/03 21:07:34
Sounds good. I have updated accordingly.
Btw, I t
| |
| 290 // If deletion of |icon_dir| fails, no need to create the same directory. | |
| 291 if (icon_dir_delete_success && !base::CreateDirectory(icon_dir)) | |
| 283 folder_operation_status |= FolderOperationResult::CREATE_SRC_FAILED; | 292 folder_operation_status |= FolderOperationResult::CREATE_SRC_FAILED; |
| 284 | 293 |
| 285 UMA_HISTOGRAM_ENUMERATION("WinJumplist.DetailedFolderResults", | 294 UMA_HISTOGRAM_ENUMERATION("WinJumplist.DetailedFolderResults", |
| 286 folder_operation_status, | 295 folder_operation_status, |
| 287 FolderOperationResult::END); | 296 FolderOperationResult::END); |
| 288 | 297 |
| 289 // Create temporary icon files for shortcuts in the "Most Visited" category. | 298 // If deletion of |icon_dir| fails, skip updating jumplist icons to avoid |
| 290 CreateIconFiles(icon_dir, local_most_visited_pages); | 299 // bloating the JumplistIcons folder. |
| 300 if (icon_dir_delete_success) { | |
| 301 // Create temporary icon files for shortcuts in the "Most Visited" category. | |
| 302 CreateIconFiles(icon_dir, local_most_visited_pages); | |
| 291 | 303 |
| 292 // Create temporary icon files for shortcuts in the "Recently Closed" | 304 // Create temporary icon files for shortcuts in the "Recently Closed" |
| 293 // category. | 305 // category. |
| 294 CreateIconFiles(icon_dir, local_recently_closed_pages); | 306 CreateIconFiles(icon_dir, local_recently_closed_pages); |
| 295 | 307 |
| 296 // We finished collecting all resources needed for updating an application | 308 // We finished collecting all resources needed for updating an application |
| 297 // JumpList. So, create a new JumpList and replace the current JumpList | 309 // JumpList. So, create a new JumpList and replace the current JumpList |
| 298 // with it. | 310 // with it. |
| 299 UpdateJumpList(app_id.c_str(), | 311 UpdateJumpList(app_id.c_str(), local_most_visited_pages, |
| 300 local_most_visited_pages, | 312 local_recently_closed_pages, incognito_availability); |
| 301 local_recently_closed_pages, | 313 } |
| 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 |