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

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

Issue 2911133002: Replace deprecated base::NonThreadSafe in chrome/browser/win in favor of SequenceChecker. (Closed)
Patch Set: Created 3 years, 6 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
« no previous file with comments | « chrome/browser/win/jumplist.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/base_paths.h" 7 #include "base/base_paths.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 } 237 }
238 tab_restore_service->AddObserver(this); 238 tab_restore_service->AddObserver(this);
239 pref_change_registrar_.reset(new PrefChangeRegistrar); 239 pref_change_registrar_.reset(new PrefChangeRegistrar);
240 pref_change_registrar_->Init(profile_->GetPrefs()); 240 pref_change_registrar_->Init(profile_->GetPrefs());
241 pref_change_registrar_->Add( 241 pref_change_registrar_->Add(
242 prefs::kIncognitoModeAvailability, 242 prefs::kIncognitoModeAvailability,
243 base::Bind(&JumpList::OnIncognitoAvailabilityChanged, this)); 243 base::Bind(&JumpList::OnIncognitoAvailabilityChanged, this));
244 } 244 }
245 245
246 JumpList::~JumpList() { 246 JumpList::~JumpList() {
247 DCHECK(CalledOnValidThread()); 247 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
248 Terminate(); 248 Terminate();
249 } 249 }
250 250
251 // static 251 // static
252 bool JumpList::Enabled() { 252 bool JumpList::Enabled() {
253 return JumpListUpdater::IsEnabled(); 253 return JumpListUpdater::IsEnabled();
254 } 254 }
255 255
256 void JumpList::CancelPendingUpdate() { 256 void JumpList::CancelPendingUpdate() {
257 DCHECK(CalledOnValidThread()); 257 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
258 if (task_id_ != base::CancelableTaskTracker::kBadTaskId) { 258 if (task_id_ != base::CancelableTaskTracker::kBadTaskId) {
259 cancelable_task_tracker_.TryCancel(task_id_); 259 cancelable_task_tracker_.TryCancel(task_id_);
260 task_id_ = base::CancelableTaskTracker::kBadTaskId; 260 task_id_ = base::CancelableTaskTracker::kBadTaskId;
261 } 261 }
262 } 262 }
263 263
264 void JumpList::Terminate() { 264 void JumpList::Terminate() {
265 DCHECK(CalledOnValidThread()); 265 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
266 timer_most_visited_.Stop(); 266 timer_most_visited_.Stop();
267 timer_recently_closed_.Stop(); 267 timer_recently_closed_.Stop();
268 CancelPendingUpdate(); 268 CancelPendingUpdate();
269 if (profile_) { 269 if (profile_) {
270 sessions::TabRestoreService* tab_restore_service = 270 sessions::TabRestoreService* tab_restore_service =
271 TabRestoreServiceFactory::GetForProfile(profile_); 271 TabRestoreServiceFactory::GetForProfile(profile_);
272 if (tab_restore_service) 272 if (tab_restore_service)
273 tab_restore_service->RemoveObserver(this); 273 tab_restore_service->RemoveObserver(this);
274 scoped_refptr<history::TopSites> top_sites = 274 scoped_refptr<history::TopSites> top_sites =
275 TopSitesFactory::GetForProfile(profile_); 275 TopSitesFactory::GetForProfile(profile_);
276 if (top_sites) 276 if (top_sites)
277 top_sites->RemoveObserver(this); 277 top_sites->RemoveObserver(this);
278 pref_change_registrar_.reset(); 278 pref_change_registrar_.reset();
279 } 279 }
280 profile_ = NULL; 280 profile_ = NULL;
281 } 281 }
282 282
283 void JumpList::ShutdownOnUIThread() { 283 void JumpList::ShutdownOnUIThread() {
284 DCHECK(CalledOnValidThread()); 284 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
285 Terminate(); 285 Terminate();
286 } 286 }
287 287
288 void JumpList::OnMostVisitedURLsAvailable( 288 void JumpList::OnMostVisitedURLsAvailable(
289 const history::MostVisitedURLList& urls) { 289 const history::MostVisitedURLList& urls) {
290 DCHECK(CalledOnValidThread()); 290 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
291 291
292 { 292 {
293 JumpListData* data = &jumplist_data_->data; 293 JumpListData* data = &jumplist_data_->data;
294 base::AutoLock auto_lock(data->list_lock_); 294 base::AutoLock auto_lock(data->list_lock_);
295 data->most_visited_pages_.clear(); 295 data->most_visited_pages_.clear();
296 296
297 for (size_t i = 0; i < urls.size() && i < kMostVisitedItems; i++) { 297 for (size_t i = 0; i < urls.size() && i < kMostVisitedItems; i++) {
298 const history::MostVisitedURL& url = urls[i]; 298 const history::MostVisitedURL& url = urls[i];
299 scoped_refptr<ShellLinkItem> link = CreateShellLink(); 299 scoped_refptr<ShellLinkItem> link = CreateShellLink();
300 std::string url_string = url.url.spec(); 300 std::string url_string = url.url.spec();
301 base::string16 url_string_wide = base::UTF8ToUTF16(url_string); 301 base::string16 url_string_wide = base::UTF8ToUTF16(url_string);
302 link->GetCommandLine()->AppendArgNative(url_string_wide); 302 link->GetCommandLine()->AppendArgNative(url_string_wide);
303 link->GetCommandLine()->AppendSwitchASCII( 303 link->GetCommandLine()->AppendSwitchASCII(
304 switches::kWinJumplistAction, jumplist::kMostVisitedCategory); 304 switches::kWinJumplistAction, jumplist::kMostVisitedCategory);
305 link->set_title(!url.title.empty() ? url.title : url_string_wide); 305 link->set_title(!url.title.empty() ? url.title : url_string_wide);
306 link->set_url(url_string); 306 link->set_url(url_string);
307 data->most_visited_pages_.push_back(link); 307 data->most_visited_pages_.push_back(link);
308 data->icon_urls_.push_back(std::make_pair(url_string, link)); 308 data->icon_urls_.push_back(std::make_pair(url_string, link));
309 } 309 }
310 data->most_visited_pages_have_updates_ = true; 310 data->most_visited_pages_have_updates_ = true;
311 } 311 }
312 312
313 // Send a query that retrieves the first favicon. 313 // Send a query that retrieves the first favicon.
314 StartLoadingFavicon(); 314 StartLoadingFavicon();
315 } 315 }
316 316
317 void JumpList::TabRestoreServiceChanged(sessions::TabRestoreService* service) { 317 void JumpList::TabRestoreServiceChanged(sessions::TabRestoreService* service) {
318 DCHECK(CalledOnValidThread()); 318 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
319 319
320 // if we have a pending favicon request, cancel it here (it is out of date). 320 // if we have a pending favicon request, cancel it here (it is out of date).
321 CancelPendingUpdate(); 321 CancelPendingUpdate();
322 322
323 // Initialize the one-shot timer to update the the "Recently Closed" category 323 // Initialize the one-shot timer to update the the "Recently Closed" category
324 // in a while. If there is already a request queued then cancel it and post 324 // in a while. If there is already a request queued then cancel it and post
325 // the new request. This ensures that JumpList update of the "Recently Closed" 325 // the new request. This ensures that JumpList update of the "Recently Closed"
326 // category won't happen until there has been a brief quiet period, thus 326 // category won't happen until there has been a brief quiet period, thus
327 // avoiding update storms. 327 // avoiding update storms.
328 if (timer_recently_closed_.IsRunning()) { 328 if (timer_recently_closed_.IsRunning()) {
329 timer_recently_closed_.Reset(); 329 timer_recently_closed_.Reset();
330 } else { 330 } else {
331 timer_recently_closed_.Start( 331 timer_recently_closed_.Start(
332 FROM_HERE, kDelayForJumplistUpdate, 332 FROM_HERE, kDelayForJumplistUpdate,
333 base::Bind(&JumpList::DeferredTabRestoreServiceChanged, 333 base::Bind(&JumpList::DeferredTabRestoreServiceChanged,
334 base::Unretained(this))); 334 base::Unretained(this)));
335 } 335 }
336 } 336 }
337 337
338 void JumpList::TabRestoreServiceDestroyed( 338 void JumpList::TabRestoreServiceDestroyed(
339 sessions::TabRestoreService* service) {} 339 sessions::TabRestoreService* service) {}
340 340
341 bool JumpList::AddTab(const sessions::TabRestoreService::Tab& tab, 341 bool JumpList::AddTab(const sessions::TabRestoreService::Tab& tab,
342 size_t max_items, 342 size_t max_items,
343 JumpListData* data) { 343 JumpListData* data) {
344 DCHECK(CalledOnValidThread()); 344 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
345 data->list_lock_.AssertAcquired(); 345 data->list_lock_.AssertAcquired();
346 346
347 // This code adds the URL and the title strings of the given tab to |data|. 347 // This code adds the URL and the title strings of the given tab to |data|.
348 if (data->recently_closed_pages_.size() >= max_items) 348 if (data->recently_closed_pages_.size() >= max_items)
349 return false; 349 return false;
350 350
351 scoped_refptr<ShellLinkItem> link = CreateShellLink(); 351 scoped_refptr<ShellLinkItem> link = CreateShellLink();
352 const sessions::SerializedNavigationEntry& current_navigation = 352 const sessions::SerializedNavigationEntry& current_navigation =
353 tab.navigations.at(tab.current_navigation_index); 353 tab.navigations.at(tab.current_navigation_index);
354 std::string url = current_navigation.virtual_url().spec(); 354 std::string url = current_navigation.virtual_url().spec();
355 link->GetCommandLine()->AppendArgNative(base::UTF8ToUTF16(url)); 355 link->GetCommandLine()->AppendArgNative(base::UTF8ToUTF16(url));
356 link->GetCommandLine()->AppendSwitchASCII(switches::kWinJumplistAction, 356 link->GetCommandLine()->AppendSwitchASCII(switches::kWinJumplistAction,
357 jumplist::kRecentlyClosedCategory); 357 jumplist::kRecentlyClosedCategory);
358 link->set_title(current_navigation.title()); 358 link->set_title(current_navigation.title());
359 link->set_url(url); 359 link->set_url(url);
360 data->recently_closed_pages_.push_back(link); 360 data->recently_closed_pages_.push_back(link);
361 data->icon_urls_.push_back(std::make_pair(std::move(url), std::move(link))); 361 data->icon_urls_.push_back(std::make_pair(std::move(url), std::move(link)));
362 362
363 return true; 363 return true;
364 } 364 }
365 365
366 void JumpList::AddWindow(const sessions::TabRestoreService::Window& window, 366 void JumpList::AddWindow(const sessions::TabRestoreService::Window& window,
367 size_t max_items, 367 size_t max_items,
368 JumpListData* data) { 368 JumpListData* data) {
369 DCHECK(CalledOnValidThread()); 369 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
370 data->list_lock_.AssertAcquired(); 370 data->list_lock_.AssertAcquired();
371 371
372 // This code enumerates all the tabs in the given window object and add their 372 // This code enumerates all the tabs in the given window object and add their
373 // URLs and titles to |data|. 373 // URLs and titles to |data|.
374 DCHECK(!window.tabs.empty()); 374 DCHECK(!window.tabs.empty());
375 375
376 for (const auto& tab : window.tabs) { 376 for (const auto& tab : window.tabs) {
377 if (!AddTab(*tab, max_items, data)) 377 if (!AddTab(*tab, max_items, data))
378 return; 378 return;
379 } 379 }
380 } 380 }
381 381
382 void JumpList::StartLoadingFavicon() { 382 void JumpList::StartLoadingFavicon() {
383 DCHECK(CalledOnValidThread()); 383 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
384 384
385 base::ElapsedTimer timer; 385 base::ElapsedTimer timer;
386 386
387 GURL url; 387 GURL url;
388 bool waiting_for_icons = true; 388 bool waiting_for_icons = true;
389 { 389 {
390 JumpListData* data = &jumplist_data_->data; 390 JumpListData* data = &jumplist_data_->data;
391 base::AutoLock auto_lock(data->list_lock_); 391 base::AutoLock auto_lock(data->list_lock_);
392 waiting_for_icons = !data->icon_urls_.empty(); 392 waiting_for_icons = !data->icon_urls_.empty();
393 if (waiting_for_icons) { 393 if (waiting_for_icons) {
(...skipping 18 matching lines...) Expand all
412 base::Bind(&JumpList::OnFaviconDataAvailable, base::Unretained(this)), 412 base::Bind(&JumpList::OnFaviconDataAvailable, base::Unretained(this)),
413 &cancelable_task_tracker_); 413 &cancelable_task_tracker_);
414 414
415 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/717236 415 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/717236
416 UMA_HISTOGRAM_TIMES("WinJumplist.StartLoadingFaviconDuration", 416 UMA_HISTOGRAM_TIMES("WinJumplist.StartLoadingFaviconDuration",
417 timer.Elapsed()); 417 timer.Elapsed());
418 } 418 }
419 419
420 void JumpList::OnFaviconDataAvailable( 420 void JumpList::OnFaviconDataAvailable(
421 const favicon_base::FaviconImageResult& image_result) { 421 const favicon_base::FaviconImageResult& image_result) {
422 DCHECK(CalledOnValidThread()); 422 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
423 423
424 base::ElapsedTimer timer; 424 base::ElapsedTimer timer;
425 425
426 // If there is currently a favicon request in progress, it is now outdated, 426 // If there is currently a favicon request in progress, it is now outdated,
427 // as we have received another, so nullify the handle from the old request. 427 // as we have received another, so nullify the handle from the old request.
428 task_id_ = base::CancelableTaskTracker::kBadTaskId; 428 task_id_ = base::CancelableTaskTracker::kBadTaskId;
429 // Lock the list to set icon data and pop the url. 429 // Lock the list to set icon data and pop the url.
430 { 430 {
431 JumpListData* data = &jumplist_data_->data; 431 JumpListData* data = &jumplist_data_->data;
432 base::AutoLock auto_lock(data->list_lock_); 432 base::AutoLock auto_lock(data->list_lock_);
(...skipping 14 matching lines...) Expand all
447 447
448 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/717236 448 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/717236
449 UMA_HISTOGRAM_TIMES("WinJumplist.OnFaviconDataAvailableDuration", 449 UMA_HISTOGRAM_TIMES("WinJumplist.OnFaviconDataAvailableDuration",
450 timer.Elapsed()); 450 timer.Elapsed());
451 451
452 // Check whether we need to load more favicons. 452 // Check whether we need to load more favicons.
453 StartLoadingFavicon(); 453 StartLoadingFavicon();
454 } 454 }
455 455
456 void JumpList::OnIncognitoAvailabilityChanged() { 456 void JumpList::OnIncognitoAvailabilityChanged() {
457 DCHECK(CalledOnValidThread()); 457 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
458 458
459 bool waiting_for_icons = true; 459 bool waiting_for_icons = true;
460 { 460 {
461 JumpListData* data = &jumplist_data_->data; 461 JumpListData* data = &jumplist_data_->data;
462 base::AutoLock auto_lock(data->list_lock_); 462 base::AutoLock auto_lock(data->list_lock_);
463 waiting_for_icons = !data->icon_urls_.empty(); 463 waiting_for_icons = !data->icon_urls_.empty();
464 } 464 }
465 465
466 // Since neither the "Most Visited" category nor the "Recently Closed" 466 // Since neither the "Most Visited" category nor the "Recently Closed"
467 // category changes, mark the flags so that icon files for those categories 467 // category changes, mark the flags so that icon files for those categories
468 // won't be updated later on. 468 // won't be updated later on.
469 if (!waiting_for_icons) 469 if (!waiting_for_icons)
470 PostRunUpdate(); 470 PostRunUpdate();
471 } 471 }
472 472
473 void JumpList::PostRunUpdate() { 473 void JumpList::PostRunUpdate() {
474 DCHECK(CalledOnValidThread()); 474 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
475 475
476 TRACE_EVENT0("browser", "JumpList::PostRunUpdate"); 476 TRACE_EVENT0("browser", "JumpList::PostRunUpdate");
477 if (!profile_) 477 if (!profile_)
478 return; 478 return;
479 479
480 base::FilePath profile_dir = profile_->GetPath(); 480 base::FilePath profile_dir = profile_->GetPath();
481 481
482 // Check if incognito windows (or normal windows) are disabled by policy. 482 // Check if incognito windows (or normal windows) are disabled by policy.
483 IncognitoModePrefs::Availability incognito_availability = 483 IncognitoModePrefs::Availability incognito_availability =
484 IncognitoModePrefs::GetAvailability(profile_->GetPrefs()); 484 IncognitoModePrefs::GetAvailability(profile_->GetPrefs());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 if (timer_most_visited_.IsRunning()) { 525 if (timer_most_visited_.IsRunning()) {
526 timer_most_visited_.Reset(); 526 timer_most_visited_.Reset();
527 } else { 527 } else {
528 timer_most_visited_.Start( 528 timer_most_visited_.Start(
529 FROM_HERE, kDelayForJumplistUpdate, 529 FROM_HERE, kDelayForJumplistUpdate,
530 base::Bind(&JumpList::DeferredTopSitesChanged, base::Unretained(this))); 530 base::Bind(&JumpList::DeferredTopSitesChanged, base::Unretained(this)));
531 } 531 }
532 } 532 }
533 533
534 void JumpList::DeferredTopSitesChanged() { 534 void JumpList::DeferredTopSitesChanged() {
535 DCHECK(CalledOnValidThread()); 535 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
536 536
537 if (updates_to_skip_ > 0) { 537 if (updates_to_skip_ > 0) {
538 --updates_to_skip_; 538 --updates_to_skip_;
539 return; 539 return;
540 } 540 }
541 541
542 // Opening the first tab in one session triggers a TopSite history sync. 542 // Opening the first tab in one session triggers a TopSite history sync.
543 // Delay this sync till the first tab is closed to allow the "recently closed" 543 // Delay this sync till the first tab is closed to allow the "recently closed"
544 // category from last session to stay longer. 544 // category from last session to stay longer.
545 if (!has_tab_closed_) 545 if (!has_tab_closed_)
546 return; 546 return;
547 547
548 scoped_refptr<history::TopSites> top_sites = 548 scoped_refptr<history::TopSites> top_sites =
549 TopSitesFactory::GetForProfile(profile_); 549 TopSitesFactory::GetForProfile(profile_);
550 if (top_sites) { 550 if (top_sites) {
551 top_sites->GetMostVisitedURLs( 551 top_sites->GetMostVisitedURLs(
552 base::Bind(&JumpList::OnMostVisitedURLsAvailable, 552 base::Bind(&JumpList::OnMostVisitedURLsAvailable,
553 weak_ptr_factory_.GetWeakPtr()), 553 weak_ptr_factory_.GetWeakPtr()),
554 false); 554 false);
555 } 555 }
556 } 556 }
557 557
558 void JumpList::DeferredTabRestoreServiceChanged() { 558 void JumpList::DeferredTabRestoreServiceChanged() {
559 DCHECK(CalledOnValidThread()); 559 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
560 560
561 if (updates_to_skip_ > 0) { 561 if (updates_to_skip_ > 0) {
562 --updates_to_skip_; 562 --updates_to_skip_;
563 return; 563 return;
564 } 564 }
565 565
566 // Force a TopSite history sync when closing a first tab in one session. 566 // Force a TopSite history sync when closing a first tab in one session.
567 if (!has_tab_closed_) { 567 if (!has_tab_closed_) {
568 has_tab_closed_ = true; 568 has_tab_closed_ = true;
569 scoped_refptr<history::TopSites> top_sites = 569 scoped_refptr<history::TopSites> top_sites =
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 app_id, profile_dir, local_most_visited_pages, 859 app_id, profile_dir, local_most_visited_pages,
860 local_recently_closed_pages, most_visited_pages_have_updates, 860 local_recently_closed_pages, most_visited_pages_have_updates,
861 recently_closed_pages_have_updates, incognito_availability)) { 861 recently_closed_pages_have_updates, incognito_availability)) {
862 base::AutoLock auto_lock(data->list_lock_); 862 base::AutoLock auto_lock(data->list_lock_);
863 if (most_visited_pages_have_updates) 863 if (most_visited_pages_have_updates)
864 data->most_visited_pages_have_updates_ = true; 864 data->most_visited_pages_have_updates_ = true;
865 if (recently_closed_pages_have_updates) 865 if (recently_closed_pages_have_updates)
866 data->recently_closed_pages_have_updates_ = true; 866 data->recently_closed_pages_have_updates_ = true;
867 } 867 }
868 } 868 }
OLDNEW
« no previous file with comments | « chrome/browser/win/jumplist.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698