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 <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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 base::ReplaceSubstringsAfterOffset( | 190 base::ReplaceSubstringsAfterOffset( |
| 191 &incognito_title, 0, L"&", base::StringPiece16()); | 191 &incognito_title, 0, L"&", base::StringPiece16()); |
| 192 incognito->set_title(incognito_title); | 192 incognito->set_title(incognito_title); |
| 193 incognito->set_icon(chrome_path.value(), icon_resources::kIncognitoIndex); | 193 incognito->set_icon(chrome_path.value(), icon_resources::kIncognitoIndex); |
| 194 items.push_back(incognito); | 194 items.push_back(incognito); |
| 195 } | 195 } |
| 196 | 196 |
| 197 return jumplist_updater->AddTasks(items); | 197 return jumplist_updater->AddTasks(items); |
| 198 } | 198 } |
| 199 | 199 |
| 200 void GenerateJumplistIconDirName( | |
| 201 const base::FilePath& profile_dir, | |
| 202 const base::FilePath::StringType& dir_name_append, | |
|
grt (UTC plus 2)
2017/05/03 10:10:41
nit: dir_name_append -> suffix
grt (UTC plus 2)
2017/05/03 10:10:41
take this as a base::FilePath::StringPieceType to
chengx
2017/05/03 18:36:29
Done.
chengx
2017/05/03 18:36:29
Done.
| |
| 203 base::FilePath* out_dir) { | |
|
grt (UTC plus 2)
2017/05/03 10:10:41
we treat FilePath as a value type -- return this d
chengx
2017/05/03 18:36:30
Done. I thought we should avoid copying strings. T
grt (UTC plus 2)
2017/05/04 11:41:55
No strings are copied here. Between RVO (return va
chengx
2017/05/04 19:36:11
Thanks for the explanation!
| |
| 204 base::FilePath::StringType jumplisticon_base_dir( | |
|
grt (UTC plus 2)
2017/05/03 10:10:41
how about:
base::FilePath::StringType dir_name(c
chengx
2017/05/03 18:36:29
Accepted. Thanks!
| |
| 205 chrome::kJumpListIconDirname); | |
| 206 *out_dir = profile_dir.Append(jumplisticon_base_dir + dir_name_append); | |
| 207 } | |
| 208 | |
| 200 // Updates the application JumpList, which consists of 1) delete old icon files; | 209 // Updates the application JumpList, which consists of 1) delete old icon files; |
| 201 // 2) create new icon files; 3) notify the OS. | 210 // 2) create new icon files; 3) notify the OS. |
| 202 // Note that any timeout error along the way results in the old jumplist being | 211 // Note that any timeout error along the way results in the old jumplist being |
| 203 // left as-is, while any non-timeout error results in the old jumplist being | 212 // left as-is, while any non-timeout error results in the old jumplist being |
| 204 // left as-is, but without icon files. | 213 // left as-is, but without icon files. |
| 205 bool UpdateJumpList(const wchar_t* app_id, | 214 bool UpdateJumpList(const wchar_t* app_id, |
| 206 const base::FilePath& icon_dir, | 215 const base::FilePath& profile_dir, |
| 207 const ShellLinkItemList& most_visited_pages, | 216 const ShellLinkItemList& most_visited_pages, |
| 208 const ShellLinkItemList& recently_closed_pages, | 217 const ShellLinkItemList& recently_closed_pages, |
| 209 bool most_visited_pages_have_updates, | 218 bool most_visited_pages_have_updates, |
| 210 bool recently_closed_pages_have_updates, | 219 bool recently_closed_pages_have_updates, |
| 211 IncognitoModePrefs::Availability incognito_availability) { | 220 IncognitoModePrefs::Availability incognito_availability) { |
| 212 if (!JumpListUpdater::IsEnabled()) | 221 if (!JumpListUpdater::IsEnabled()) |
| 213 return true; | 222 return true; |
| 214 | 223 |
| 215 JumpListUpdater jumplist_updater(app_id); | 224 JumpListUpdater jumplist_updater(app_id); |
| 216 | 225 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 if (recently_closed_pages.size() < recently_closed_items) { | 263 if (recently_closed_pages.size() < recently_closed_items) { |
| 255 most_visited_items += recently_closed_items - recently_closed_pages.size(); | 264 most_visited_items += recently_closed_items - recently_closed_pages.size(); |
| 256 recently_closed_items = recently_closed_pages.size(); | 265 recently_closed_items = recently_closed_pages.size(); |
| 257 } | 266 } |
| 258 | 267 |
| 259 // Record the desired number of icons to create in this JumpList update. | 268 // Record the desired number of icons to create in this JumpList update. |
| 260 int icons_to_create = 0; | 269 int icons_to_create = 0; |
| 261 | 270 |
| 262 // Update the icons for "Most Visisted" category of the JumpList if needed. | 271 // Update the icons for "Most Visisted" category of the JumpList if needed. |
| 263 if (most_visited_pages_have_updates) { | 272 if (most_visited_pages_have_updates) { |
| 264 base::FilePath icon_dir_most_visited = icon_dir.DirName().Append( | 273 base::FilePath icon_dir_most_visited; |
| 265 icon_dir.BaseName().value() + FILE_PATH_LITERAL("MostVisited")); | 274 GenerateJumplistIconDirName(profile_dir, FILE_PATH_LITERAL("MostVisited"), |
| 275 &icon_dir_most_visited); | |
| 266 | 276 |
| 267 UpdateIconFiles(icon_dir_most_visited, most_visited_pages, | 277 UpdateIconFiles(icon_dir_most_visited, most_visited_pages, |
| 268 most_visited_items); | 278 most_visited_items); |
| 269 | 279 |
| 270 icons_to_create += std::min(most_visited_pages.size(), most_visited_items); | 280 icons_to_create += std::min(most_visited_pages.size(), most_visited_items); |
| 271 } | 281 } |
| 272 | 282 |
| 273 // Update the icons for "Recently Closed" category of the JumpList if needed. | 283 // Update the icons for "Recently Closed" category of the JumpList if needed. |
| 274 if (recently_closed_pages_have_updates) { | 284 if (recently_closed_pages_have_updates) { |
| 275 base::FilePath icon_dir_recent_closed = icon_dir.DirName().Append( | 285 base::FilePath icon_dir_recent_closed; |
| 276 icon_dir.BaseName().value() + FILE_PATH_LITERAL("RecentClosed")); | 286 GenerateJumplistIconDirName(profile_dir, FILE_PATH_LITERAL("RecentClosed"), |
| 287 &icon_dir_recent_closed); | |
| 277 | 288 |
| 278 UpdateIconFiles(icon_dir_recent_closed, recently_closed_pages, | 289 UpdateIconFiles(icon_dir_recent_closed, recently_closed_pages, |
| 279 recently_closed_items); | 290 recently_closed_items); |
| 280 | 291 |
| 281 icons_to_create += | 292 icons_to_create += |
| 282 std::min(recently_closed_pages.size(), recently_closed_items); | 293 std::min(recently_closed_pages.size(), recently_closed_items); |
| 283 } | 294 } |
| 284 | 295 |
| 285 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. | 296 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. |
| 286 UMA_HISTOGRAM_COUNTS_100("WinJumplist.CreateIconFilesCount", icons_to_create); | 297 UMA_HISTOGRAM_COUNTS_100("WinJumplist.CreateIconFilesCount", icons_to_create); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 308 if (!UpdateTaskCategory(&jumplist_updater, incognito_availability)) | 319 if (!UpdateTaskCategory(&jumplist_updater, incognito_availability)) |
| 309 return false; | 320 return false; |
| 310 | 321 |
| 311 // Commit this transaction and send the updated JumpList to Windows. | 322 // Commit this transaction and send the updated JumpList to Windows. |
| 312 return jumplist_updater.CommitUpdate(); | 323 return jumplist_updater.CommitUpdate(); |
| 313 } | 324 } |
| 314 | 325 |
| 315 // Updates the jumplist, once all the data has been fetched. | 326 // Updates the jumplist, once all the data has been fetched. |
| 316 void RunUpdateJumpList(IncognitoModePrefs::Availability incognito_availability, | 327 void RunUpdateJumpList(IncognitoModePrefs::Availability incognito_availability, |
| 317 const std::wstring& app_id, | 328 const std::wstring& app_id, |
| 318 const base::FilePath& icon_dir, | 329 const base::FilePath& profile_dir, |
| 319 base::RefCountedData<JumpListData>* ref_counted_data) { | 330 base::RefCountedData<JumpListData>* ref_counted_data) { |
| 320 JumpListData* data = &ref_counted_data->data; | 331 JumpListData* data = &ref_counted_data->data; |
| 321 ShellLinkItemList local_most_visited_pages; | 332 ShellLinkItemList local_most_visited_pages; |
| 322 ShellLinkItemList local_recently_closed_pages; | 333 ShellLinkItemList local_recently_closed_pages; |
| 323 bool most_visited_pages_have_updates; | 334 bool most_visited_pages_have_updates; |
| 324 bool recently_closed_pages_have_updates; | 335 bool recently_closed_pages_have_updates; |
| 325 | 336 |
| 326 { | 337 { |
| 327 base::AutoLock auto_lock(data->list_lock_); | 338 base::AutoLock auto_lock(data->list_lock_); |
| 328 // Make sure we are not out of date: if icon_urls_ is not empty, then | 339 // Make sure we are not out of date: if icon_urls_ is not empty, then |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 343 data->recently_closed_pages_have_updates_ = false; | 354 data->recently_closed_pages_have_updates_ = false; |
| 344 } | 355 } |
| 345 | 356 |
| 346 if (!most_visited_pages_have_updates && !recently_closed_pages_have_updates) | 357 if (!most_visited_pages_have_updates && !recently_closed_pages_have_updates) |
| 347 return; | 358 return; |
| 348 | 359 |
| 349 // Update the application JumpList. If it fails, reset the flags to true if | 360 // Update the application JumpList. If it fails, reset the flags to true if |
| 350 // they were so that the corresponding JumpList categories will be tried to | 361 // they were so that the corresponding JumpList categories will be tried to |
| 351 // update again in the next run. | 362 // update again in the next run. |
| 352 if (!UpdateJumpList( | 363 if (!UpdateJumpList( |
| 353 app_id.c_str(), icon_dir, local_most_visited_pages, | 364 app_id.c_str(), profile_dir, local_most_visited_pages, |
| 354 local_recently_closed_pages, most_visited_pages_have_updates, | 365 local_recently_closed_pages, most_visited_pages_have_updates, |
| 355 recently_closed_pages_have_updates, incognito_availability)) { | 366 recently_closed_pages_have_updates, incognito_availability)) { |
| 356 base::AutoLock auto_lock(data->list_lock_); | 367 base::AutoLock auto_lock(data->list_lock_); |
| 357 if (most_visited_pages_have_updates) | 368 if (most_visited_pages_have_updates) |
| 358 data->most_visited_pages_have_updates_ = true; | 369 data->most_visited_pages_have_updates_ = true; |
| 359 if (recently_closed_pages_have_updates) | 370 if (recently_closed_pages_have_updates) |
| 360 data->recently_closed_pages_have_updates_ = true; | 371 data->recently_closed_pages_have_updates_ = true; |
| 361 } | 372 } |
| 362 } | 373 } |
| 363 | 374 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 393 // When we add this object to the observer list, we save the pointer to this | 404 // When we add this object to the observer list, we save the pointer to this |
| 394 // TabRestoreService object. This pointer is used when we remove this object | 405 // TabRestoreService object. This pointer is used when we remove this object |
| 395 // from the observer list. | 406 // from the observer list. |
| 396 sessions::TabRestoreService* tab_restore_service = | 407 sessions::TabRestoreService* tab_restore_service = |
| 397 TabRestoreServiceFactory::GetForProfile(profile_); | 408 TabRestoreServiceFactory::GetForProfile(profile_); |
| 398 if (!tab_restore_service) | 409 if (!tab_restore_service) |
| 399 return; | 410 return; |
| 400 | 411 |
| 401 app_id_ = | 412 app_id_ = |
| 402 shell_integration::win::GetChromiumModelIdForProfile(profile_->GetPath()); | 413 shell_integration::win::GetChromiumModelIdForProfile(profile_->GetPath()); |
| 403 icon_dir_ = profile_->GetPath().Append(chrome::kJumpListIconDirname); | |
| 404 | 414 |
| 405 scoped_refptr<history::TopSites> top_sites = | 415 scoped_refptr<history::TopSites> top_sites = |
| 406 TopSitesFactory::GetForProfile(profile_); | 416 TopSitesFactory::GetForProfile(profile_); |
| 407 if (top_sites) { | 417 if (top_sites) { |
| 408 // TopSites updates itself after a delay. This is especially noticable when | 418 // TopSites updates itself after a delay. This is especially noticable when |
| 409 // your profile is empty. Ask TopSites to update itself when jumplist is | 419 // your profile is empty. Ask TopSites to update itself when jumplist is |
| 410 // initialized. | 420 // initialized. |
| 411 top_sites->SyncWithHistory(); | 421 top_sites->SyncWithHistory(); |
| 412 // Register as TopSitesObserver so that we can update ourselves when the | 422 // Register as TopSitesObserver so that we can update ourselves when the |
| 413 // TopSites changes. | 423 // TopSites changes. |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 435 DCHECK(CalledOnValidThread()); | 445 DCHECK(CalledOnValidThread()); |
| 436 if (task_id_ != base::CancelableTaskTracker::kBadTaskId) { | 446 if (task_id_ != base::CancelableTaskTracker::kBadTaskId) { |
| 437 cancelable_task_tracker_.TryCancel(task_id_); | 447 cancelable_task_tracker_.TryCancel(task_id_); |
| 438 task_id_ = base::CancelableTaskTracker::kBadTaskId; | 448 task_id_ = base::CancelableTaskTracker::kBadTaskId; |
| 439 } | 449 } |
| 440 } | 450 } |
| 441 | 451 |
| 442 void JumpList::Terminate() { | 452 void JumpList::Terminate() { |
| 443 DCHECK(CalledOnValidThread()); | 453 DCHECK(CalledOnValidThread()); |
| 444 CancelPendingUpdate(); | 454 CancelPendingUpdate(); |
| 445 if (profile_) { | 455 if (profile_) { |
|
grt (UTC plus 2)
2017/05/03 10:10:41
should this also stop the timer?
chengx
2017/05/03 18:36:30
It should. I'll fix this in the "delay and coalesc
| |
| 446 sessions::TabRestoreService* tab_restore_service = | 456 sessions::TabRestoreService* tab_restore_service = |
| 447 TabRestoreServiceFactory::GetForProfile(profile_); | 457 TabRestoreServiceFactory::GetForProfile(profile_); |
| 448 if (tab_restore_service) | 458 if (tab_restore_service) |
| 449 tab_restore_service->RemoveObserver(this); | 459 tab_restore_service->RemoveObserver(this); |
| 450 scoped_refptr<history::TopSites> top_sites = | 460 scoped_refptr<history::TopSites> top_sites = |
| 451 TopSitesFactory::GetForProfile(profile_); | 461 TopSitesFactory::GetForProfile(profile_); |
| 452 if (top_sites) | 462 if (top_sites) |
| 453 top_sites->RemoveObserver(this); | 463 top_sites->RemoveObserver(this); |
| 454 pref_change_registrar_.reset(); | 464 pref_change_registrar_.reset(); |
| 455 } | 465 } |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 673 | 683 |
| 674 void JumpList::DeferredRunUpdate() { | 684 void JumpList::DeferredRunUpdate() { |
| 675 DCHECK(CalledOnValidThread()); | 685 DCHECK(CalledOnValidThread()); |
| 676 | 686 |
| 677 TRACE_EVENT0("browser", "JumpList::DeferredRunUpdate"); | 687 TRACE_EVENT0("browser", "JumpList::DeferredRunUpdate"); |
| 678 // Check if incognito windows (or normal windows) are disabled by policy. | 688 // Check if incognito windows (or normal windows) are disabled by policy. |
| 679 IncognitoModePrefs::Availability incognito_availability = | 689 IncognitoModePrefs::Availability incognito_availability = |
| 680 profile_ ? IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) | 690 profile_ ? IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) |
| 681 : IncognitoModePrefs::ENABLED; | 691 : IncognitoModePrefs::ENABLED; |
| 682 | 692 |
| 693 base::FilePath profile_dir = profile_->GetPath(); | |
|
grt (UTC plus 2)
2017/05/03 10:10:41
null check on profile_ as above? i suppose that's
chengx
2017/05/03 18:36:29
Yes. A null check is needed here.
| |
| 694 | |
| 683 // Post a task to update the JumpList, which consists of 1) delete old icons, | 695 // Post a task to update the JumpList, which consists of 1) delete old icons, |
| 684 // 2) create new icons, 3) notify the OS. | 696 // 2) create new icons, 3) notify the OS. |
| 685 update_jumplist_task_runner_->PostTask( | 697 update_jumplist_task_runner_->PostTask( |
| 686 FROM_HERE, base::Bind(&RunUpdateJumpList, incognito_availability, app_id_, | 698 FROM_HERE, base::Bind(&RunUpdateJumpList, incognito_availability, app_id_, |
| 687 icon_dir_, base::RetainedRef(jumplist_data_))); | 699 profile_dir, base::RetainedRef(jumplist_data_))); |
| 688 | 700 |
| 689 // Post a task to delete JumpListIcons folder as it's no longer needed. | 701 // Post a task to delete JumpListIcons folder as it's no longer needed. |
| 690 // Now we have JumpListIconsMostVisited folder and JumpListIconsRecentClosed | 702 // Now we have JumpListIconsMostVisited folder and JumpListIconsRecentClosed |
| 691 // folder instead. | 703 // folder instead. |
| 692 delete_jumplisticons_task_runner_->PostTask( | 704 delete_jumplisticons_task_runner_->PostTask( |
| 693 FROM_HERE, base::Bind(&DeleteDirectory, icon_dir_, kFileDeleteLimit)); | 705 FROM_HERE, base::Bind(&DeleteDirectory, |
| 706 profile_dir.Append(chrome::kJumpListIconDirname), | |
| 707 kFileDeleteLimit)); | |
| 694 | 708 |
| 695 // Post a task to delete JumpListIconsOld folder as it's no longer needed. | 709 // Post a task to delete JumpListIconsOld folder as it's no longer needed. |
| 696 base::FilePath icon_dir_old = icon_dir_.DirName().Append( | 710 base::FilePath icon_dir_old; |
| 697 icon_dir_.BaseName().value() + FILE_PATH_LITERAL("Old")); | 711 GenerateJumplistIconDirName(profile_dir, FILE_PATH_LITERAL("Old"), |
| 698 | 712 &icon_dir_old); |
| 699 delete_jumplisticons_task_runner_->PostTask( | 713 delete_jumplisticons_task_runner_->PostTask( |
| 700 FROM_HERE, | 714 FROM_HERE, |
| 701 base::Bind(&DeleteDirectory, std::move(icon_dir_old), kFileDeleteLimit)); | 715 base::Bind(&DeleteDirectory, std::move(icon_dir_old), kFileDeleteLimit)); |
| 702 } | 716 } |
| 703 | 717 |
| 704 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { | 718 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { |
| 705 } | 719 } |
| 706 | 720 |
| 707 void JumpList::TopSitesChanged(history::TopSites* top_sites, | 721 void JumpList::TopSitesChanged(history::TopSites* top_sites, |
| 708 ChangeReason change_reason) { | 722 ChangeReason change_reason) { |
| 709 top_sites->GetMostVisitedURLs( | 723 top_sites->GetMostVisitedURLs( |
| 710 base::Bind(&JumpList::OnMostVisitedURLsAvailable, | 724 base::Bind(&JumpList::OnMostVisitedURLsAvailable, |
| 711 weak_ptr_factory_.GetWeakPtr()), | 725 weak_ptr_factory_.GetWeakPtr()), |
| 712 false); | 726 false); |
| 713 } | 727 } |
| OLD | NEW |