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

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

Issue 2965973002: Remove delay for the first JumpList top site sync in one session (Closed)
Patch Set: Created 3 years, 5 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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 268
269 top_sites_has_pending_notification_ = true; 269 top_sites_has_pending_notification_ = true;
270 270
271 // Postpone handling this notification until a pending update completes. 271 // Postpone handling this notification until a pending update completes.
272 if (update_in_progress_) 272 if (update_in_progress_)
273 return; 273 return;
274 274
275 // If we have a pending favicon request, cancel it here as it's out of date. 275 // If we have a pending favicon request, cancel it here as it's out of date.
276 CancelPendingUpdate(); 276 CancelPendingUpdate();
277 277
278 // Initialize the one-shot timer to update the JumpList in a while. 278 // When the first tab is closed in one session, it doesn't trigger an update
279 InitializeTimerForUpdate(); 279 // but a TopSites sync. This sync will trigger an update for both mostly
280 // visited and recently closed categories. We don't delay this TopSites sync.
281 if (has_topsites_sync)
282 InitializeTimerForUpdate();
283 else
284 ProcessNotifications();
280 } 285 }
281 286
282 void JumpList::TabRestoreServiceChanged(sessions::TabRestoreService* service) { 287 void JumpList::TabRestoreServiceChanged(sessions::TabRestoreService* service) {
283 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); 288 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
284 289
285 tab_restore_has_pending_notification_ = true; 290 tab_restore_has_pending_notification_ = true;
286 291
287 // Postpone handling this notification until a pending update completes. 292 // Postpone handling this notification until a pending update completes.
288 if (update_in_progress_) 293 if (update_in_progress_)
289 return; 294 return;
(...skipping 15 matching lines...) Expand all
305 PostRunUpdate(); 310 PostRunUpdate();
306 } 311 }
307 312
308 void JumpList::InitializeTimerForUpdate() { 313 void JumpList::InitializeTimerForUpdate() {
309 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); 314 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
310 315
311 if (timer_.IsRunning()) { 316 if (timer_.IsRunning()) {
312 timer_.Reset(); 317 timer_.Reset();
313 } else { 318 } else {
314 // base::Unretained is safe since |this| is guaranteed to outlive timer_. 319 // base::Unretained is safe since |this| is guaranteed to outlive timer_.
315 timer_.Start(FROM_HERE, kDelayForJumplistUpdate, 320 timer_.Start(
316 base::Bind(&JumpList::OnDelayTimer, base::Unretained(this))); 321 FROM_HERE, kDelayForJumplistUpdate,
322 base::Bind(&JumpList::ProcessNotifications, base::Unretained(this)));
317 } 323 }
318 } 324 }
319 325
320 void JumpList::OnDelayTimer() { 326 void JumpList::ProcessNotifications() {
321 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); 327 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
322 DCHECK(!update_in_progress_); 328 DCHECK(!update_in_progress_);
323 329
324 if (updates_to_skip_ > 0) { 330 if (updates_to_skip_ > 0) {
325 --updates_to_skip_; 331 --updates_to_skip_;
326 return; 332 return;
327 } 333 }
328 334
329 // Retrieve the recently closed URLs synchronously. 335 // Retrieve the recently closed URLs synchronously.
330 if (tab_restore_has_pending_notification_) { 336 if (tab_restore_has_pending_notification_) {
331 tab_restore_has_pending_notification_ = false; 337 tab_restore_has_pending_notification_ = false;
332 ProcessTabRestoreServiceNotification(); 338 ProcessTabRestoreServiceNotification();
339
340 // Force a TopSite history sync when closing a first tab in one session.
341 if (!has_tab_closed_) {
342 has_tab_closed_ = true;
343 scoped_refptr<history::TopSites> top_sites =
344 TopSitesFactory::GetForProfile(profile_);
345 if (top_sites) {
346 top_sites->SyncWithHistory();
347 return;
348 }
349 }
333 } 350 }
334 351
335 // If TopSites has updates, retrieve the URLs asynchronously, and on its 352 // If TopSites has updates, retrieve the URLs asynchronously, and on its
336 // completion, trigger favicon loading. 353 // completion, trigger favicon loading.
337 // Otherwise, call StartLoadingFavicon directly to start favicon loading. 354 // Otherwise, call StartLoadingFavicon directly to start favicon loading.
338 if (top_sites_has_pending_notification_) 355 if (top_sites_has_pending_notification_)
339 ProcessTopSitesNotification(); 356 ProcessTopSitesNotification();
340 else 357 else
341 StartLoadingFavicon(); 358 StartLoadingFavicon();
342 } 359 }
343 360
344 void JumpList::ProcessTopSitesNotification() { 361 void JumpList::ProcessTopSitesNotification() {
345 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); 362 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
346 DCHECK(!update_in_progress_); 363 DCHECK(!update_in_progress_);
347 364
348 // Opening the first tab in one session triggers a TopSite history sync. 365 // Opening the first tab in one session triggers a TopSite history sync.
349 // Delay this sync till the first tab is closed to allow the "recently closed" 366 // Delay this sync till the first tab is closed to allow the "recently closed"
350 // category from last session to stay longer. All previous pending 367 // category from last session to stay longer. All previous pending
351 // notifications from TopSites are ignored. 368 // notifications from TopSites are ignored.
352 if (!has_tab_closed_) { 369 if (!has_tab_closed_) {
353 top_sites_has_pending_notification_ = false; 370 top_sites_has_pending_notification_ = false;
354 return; 371 return;
355 } 372 }
356 373
374 has_topsites_sync = true;
375
357 scoped_refptr<history::TopSites> top_sites = 376 scoped_refptr<history::TopSites> top_sites =
358 TopSitesFactory::GetForProfile(profile_); 377 TopSitesFactory::GetForProfile(profile_);
359 if (top_sites) { 378 if (top_sites) {
360 top_sites->GetMostVisitedURLs( 379 top_sites->GetMostVisitedURLs(
361 base::Bind(&JumpList::OnMostVisitedURLsAvailable, 380 base::Bind(&JumpList::OnMostVisitedURLsAvailable,
362 weak_ptr_factory_.GetWeakPtr()), 381 weak_ptr_factory_.GetWeakPtr()),
363 false); 382 false);
364 } 383 }
365 } 384 }
366 385
(...skipping 26 matching lines...) Expand all
393 break; 412 break;
394 case sessions::TabRestoreService::WINDOW: 413 case sessions::TabRestoreService::WINDOW:
395 AddWindow( 414 AddWindow(
396 static_cast<const sessions::TabRestoreService::Window&>(*entry), 415 static_cast<const sessions::TabRestoreService::Window&>(*entry),
397 kRecentlyClosedItems); 416 kRecentlyClosedItems);
398 break; 417 break;
399 } 418 }
400 } 419 }
401 420
402 recently_closed_should_update_ = true; 421 recently_closed_should_update_ = true;
403
404 // Force a TopSite history sync when closing a first tab in one session.
405 if (!has_tab_closed_) {
406 has_tab_closed_ = true;
407 scoped_refptr<history::TopSites> top_sites =
408 TopSitesFactory::GetForProfile(profile_);
409 if (top_sites)
410 top_sites->SyncWithHistory();
411 }
412 } 422 }
413 423
414 void JumpList::OnMostVisitedURLsAvailable( 424 void JumpList::OnMostVisitedURLsAvailable(
415 const history::MostVisitedURLList& urls) { 425 const history::MostVisitedURLList& urls) {
416 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); 426 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
417 427
418 top_sites_has_pending_notification_ = false; 428 top_sites_has_pending_notification_ = false;
419 429
420 // There is no need to update the JumpList if the top most visited sites in 430 // There is no need to update the JumpList if the top most visited sites in
421 // display have not changed. 431 // display have not changed.
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 const URLIconCache& icons_cache) { 873 const URLIconCache& icons_cache) {
864 // Put all cached icon file paths into a set. 874 // Put all cached icon file paths into a set.
865 base::flat_set<base::FilePath> cached_files; 875 base::flat_set<base::FilePath> cached_files;
866 cached_files.reserve(icons_cache.size()); 876 cached_files.reserve(icons_cache.size());
867 877
868 for (const auto& url_path_pair : icons_cache) 878 for (const auto& url_path_pair : icons_cache)
869 cached_files.insert(url_path_pair.second); 879 cached_files.insert(url_path_pair.second);
870 880
871 DeleteNonCachedFiles(icon_dir, cached_files); 881 DeleteNonCachedFiles(icon_dir, cached_files);
872 } 882 }
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