Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Side by Side Diff: chrome/browser/win/jumplist.cc

Issue 2200993004: Make TabRestoreService::Entry noncopyable and fix up surrounding code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@tab-test-cleanup
Patch Set: Eliminate a use-after-free, Windows build fix Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 // The last URL of the tab object. 392 // The last URL of the tab object.
393 // * title 393 // * title
394 // The title of the last URL. 394 // The title of the last URL.
395 // * icon 395 // * icon
396 // An empty string. This value is to be updated in OnFaviconDataAvailable(). 396 // An empty string. This value is to be updated in OnFaviconDataAvailable().
397 // This code is copied from 397 // This code is copied from
398 // RecentlyClosedTabsHandler::TabRestoreServiceChanged() to emulate it. 398 // RecentlyClosedTabsHandler::TabRestoreServiceChanged() to emulate it.
399 const int kRecentlyClosedCount = 4; 399 const int kRecentlyClosedCount = 4;
400 sessions::TabRestoreService* tab_restore_service = 400 sessions::TabRestoreService* tab_restore_service =
401 TabRestoreServiceFactory::GetForProfile(profile_); 401 TabRestoreServiceFactory::GetForProfile(profile_);
402 const sessions::TabRestoreService::Entries& entries = 402 for (const auto& entry : tab_restore_service->entries()) {
403 tab_restore_service->entries(); 403 switch (entry->type) {
404 for (sessions::TabRestoreService::Entries::const_iterator it = 404 case sessions::TabRestoreService::TAB:
405 entries.begin(); 405 AddTab(static_cast<const sessions::TabRestoreService::Tab&>(*entry),
406 it != entries.end(); ++it) { 406 &temp_list, kRecentlyClosedCount);
407 const sessions::TabRestoreService::Entry* entry = *it; 407 break;
408 if (entry->type == sessions::TabRestoreService::TAB) { 408 case sessions::TabRestoreService::WINDOW:
409 AddTab(static_cast<const sessions::TabRestoreService::Tab*>(entry), 409 AddWindow(
410 &temp_list, kRecentlyClosedCount); 410 static_cast<const sessions::TabRestoreService::Window&>(*entry),
411 } else if (entry->type == sessions::TabRestoreService::WINDOW) { 411 &temp_list, kRecentlyClosedCount);
412 AddWindow(static_cast<const sessions::TabRestoreService::Window*>(entry), 412 break;
413 &temp_list, kRecentlyClosedCount);
414 } 413 }
415 } 414 }
416 // Lock recently_closed_pages and copy temp_list into it. 415 // Lock recently_closed_pages and copy temp_list into it.
417 { 416 {
418 JumpListData* data = &jumplist_data_->data; 417 JumpListData* data = &jumplist_data_->data;
419 base::AutoLock auto_lock(data->list_lock_); 418 base::AutoLock auto_lock(data->list_lock_);
420 data->recently_closed_pages_ = temp_list; 419 data->recently_closed_pages_ = temp_list;
421 } 420 }
422 421
423 // Send a query that retrieves the first favicon. 422 // Send a query that retrieves the first favicon.
424 StartLoadingFavicon(); 423 StartLoadingFavicon();
425 } 424 }
426 425
427 void JumpList::TabRestoreServiceDestroyed( 426 void JumpList::TabRestoreServiceDestroyed(
428 sessions::TabRestoreService* service) {} 427 sessions::TabRestoreService* service) {}
429 428
430 bool JumpList::AddTab(const sessions::TabRestoreService::Tab* tab, 429 bool JumpList::AddTab(const sessions::TabRestoreService::Tab& tab,
431 ShellLinkItemList* list, 430 ShellLinkItemList* list,
432 size_t max_items) { 431 size_t max_items) {
433 DCHECK(CalledOnValidThread()); 432 DCHECK(CalledOnValidThread());
434 433
435 // This code adds the URL and the title strings of the given tab to the 434 // This code adds the URL and the title strings of the given tab to the
436 // specified list. 435 // specified list.
437 if (list->size() >= max_items) 436 if (list->size() >= max_items)
438 return false; 437 return false;
439 438
440 scoped_refptr<ShellLinkItem> link = CreateShellLink(); 439 scoped_refptr<ShellLinkItem> link = CreateShellLink();
441 const sessions::SerializedNavigationEntry& current_navigation = 440 const sessions::SerializedNavigationEntry& current_navigation =
442 tab->navigations.at(tab->current_navigation_index); 441 tab.navigations.at(tab.current_navigation_index);
443 std::string url = current_navigation.virtual_url().spec(); 442 std::string url = current_navigation.virtual_url().spec();
444 link->GetCommandLine()->AppendArgNative(base::UTF8ToWide(url)); 443 link->GetCommandLine()->AppendArgNative(base::UTF8ToWide(url));
445 link->GetCommandLine()->AppendSwitchASCII( 444 link->GetCommandLine()->AppendSwitchASCII(
446 switches::kWinJumplistAction, jumplist::kRecentlyClosedCategory); 445 switches::kWinJumplistAction, jumplist::kRecentlyClosedCategory);
447 link->set_title(current_navigation.title()); 446 link->set_title(current_navigation.title());
448 list->push_back(link); 447 list->push_back(link);
449 { 448 {
450 JumpListData* data = &jumplist_data_->data; 449 JumpListData* data = &jumplist_data_->data;
451 base::AutoLock auto_lock(data->list_lock_); 450 base::AutoLock auto_lock(data->list_lock_);
452 data->icon_urls_.push_back(std::make_pair(std::move(url), std::move(link))); 451 data->icon_urls_.push_back(std::make_pair(std::move(url), std::move(link)));
453 } 452 }
454 return true; 453 return true;
455 } 454 }
456 455
457 void JumpList::AddWindow(const sessions::TabRestoreService::Window* window, 456 void JumpList::AddWindow(const sessions::TabRestoreService::Window& window,
458 ShellLinkItemList* list, 457 ShellLinkItemList* list,
459 size_t max_items) { 458 size_t max_items) {
460 DCHECK(CalledOnValidThread()); 459 DCHECK(CalledOnValidThread());
461 460
462 // This code enumerates al the tabs in the given window object and add their 461 // This code enumerates al the tabs in the given window object and add their
463 // URLs and titles to the list. 462 // URLs and titles to the list.
464 DCHECK(!window->tabs.empty()); 463 DCHECK(!window.tabs.empty());
465 464
466 for (size_t i = 0; i < window->tabs.size(); ++i) { 465 for (const auto& tab : window.tabs) {
467 if (!AddTab(&window->tabs[i], list, max_items)) 466 if (!AddTab(*tab, list, max_items))
468 return; 467 return;
469 } 468 }
470 } 469 }
471 470
472 void JumpList::StartLoadingFavicon() { 471 void JumpList::StartLoadingFavicon() {
473 DCHECK(CalledOnValidThread()); 472 DCHECK(CalledOnValidThread());
474 473
475 GURL url; 474 GURL url;
476 bool waiting_for_icons = true; 475 bool waiting_for_icons = true;
477 { 476 {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { 580 void JumpList::TopSitesLoaded(history::TopSites* top_sites) {
582 } 581 }
583 582
584 void JumpList::TopSitesChanged(history::TopSites* top_sites, 583 void JumpList::TopSitesChanged(history::TopSites* top_sites,
585 ChangeReason change_reason) { 584 ChangeReason change_reason) {
586 top_sites->GetMostVisitedURLs( 585 top_sites->GetMostVisitedURLs(
587 base::Bind(&JumpList::OnMostVisitedURLsAvailable, 586 base::Bind(&JumpList::OnMostVisitedURLsAvailable,
588 weak_ptr_factory_.GetWeakPtr()), 587 weak_ptr_factory_.GetWeakPtr()),
589 false); 588 false);
590 } 589 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698