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/jumplist_win.h" | 5 #include "chrome/browser/jumplist_win.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" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "base/prefs/pref_change_registrar.h" | 12 #include "base/prefs/pref_change_registrar.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
| 16 #include "base/trace_event/trace_event.h" |
16 #include "chrome/browser/chrome_notification_types.h" | 17 #include "chrome/browser/chrome_notification_types.h" |
17 #include "chrome/browser/favicon/favicon_service_factory.h" | 18 #include "chrome/browser/favicon/favicon_service_factory.h" |
18 #include "chrome/browser/history/top_sites_factory.h" | 19 #include "chrome/browser/history/top_sites_factory.h" |
19 #include "chrome/browser/metrics/jumplist_metrics_win.h" | 20 #include "chrome/browser/metrics/jumplist_metrics_win.h" |
20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/browser/sessions/tab_restore_service.h" | 22 #include "chrome/browser/sessions/tab_restore_service.h" |
22 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 23 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
23 #include "chrome/browser/shell_integration.h" | 24 #include "chrome/browser/shell_integration.h" |
24 #include "chrome/common/chrome_constants.h" | 25 #include "chrome/common/chrome_constants.h" |
25 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
(...skipping 13 matching lines...) Expand all Loading... |
39 #include "ui/gfx/codec/png_codec.h" | 40 #include "ui/gfx/codec/png_codec.h" |
40 #include "ui/gfx/favicon_size.h" | 41 #include "ui/gfx/favicon_size.h" |
41 #include "ui/gfx/icon_util.h" | 42 #include "ui/gfx/icon_util.h" |
42 #include "ui/gfx/image/image_family.h" | 43 #include "ui/gfx/image/image_family.h" |
43 #include "url/gurl.h" | 44 #include "url/gurl.h" |
44 | 45 |
45 using content::BrowserThread; | 46 using content::BrowserThread; |
46 | 47 |
47 namespace { | 48 namespace { |
48 | 49 |
| 50 // Delay jumplist updates to allow collapsing of redundant update requests. |
| 51 const int kDelayForJumplistUpdateInMS = 3500; |
| 52 |
49 // Append the common switches to each shell link. | 53 // Append the common switches to each shell link. |
50 void AppendCommonSwitches(ShellLinkItem* shell_link) { | 54 void AppendCommonSwitches(ShellLinkItem* shell_link) { |
51 const char* kSwitchNames[] = { switches::kUserDataDir }; | 55 const char* kSwitchNames[] = { switches::kUserDataDir }; |
52 const base::CommandLine& command_line = | 56 const base::CommandLine& command_line = |
53 *base::CommandLine::ForCurrentProcess(); | 57 *base::CommandLine::ForCurrentProcess(); |
54 shell_link->GetCommandLine()->CopySwitchesFrom(command_line, | 58 shell_link->GetCommandLine()->CopySwitchesFrom(command_line, |
55 kSwitchNames, | 59 kSwitchNames, |
56 arraysize(kSwitchNames)); | 60 arraysize(kSwitchNames)); |
57 } | 61 } |
58 | 62 |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 base::AutoLock auto_lock(list_lock_); | 437 base::AutoLock auto_lock(list_lock_); |
434 waiting_for_icons = !icon_urls_.empty(); | 438 waiting_for_icons = !icon_urls_.empty(); |
435 } | 439 } |
436 if (!waiting_for_icons) | 440 if (!waiting_for_icons) |
437 PostRunUpdate(); | 441 PostRunUpdate(); |
438 // If |icon_urls_| isn't empty then OnFaviconDataAvailable will eventually | 442 // If |icon_urls_| isn't empty then OnFaviconDataAvailable will eventually |
439 // call PostRunUpdate(). | 443 // call PostRunUpdate(). |
440 } | 444 } |
441 | 445 |
442 void JumpList::PostRunUpdate() { | 446 void JumpList::PostRunUpdate() { |
| 447 TRACE_EVENT0("browser", "JumpList::PostRunUpdate"); |
| 448 // Initialize the one-shot timer to update the jumplists in a while. |
| 449 // If there is already a request queued then cancel it and post the new |
| 450 // request. This ensures that JumpListUpdates won't happen until there has |
| 451 // been a brief quiet period, thus avoiding update storms. |
| 452 if (timer_.IsRunning()) { |
| 453 timer_.Reset(); |
| 454 } else { |
| 455 timer_.Start(FROM_HERE, |
| 456 base::TimeDelta::FromMilliseconds(kDelayForJumplistUpdateInMS), |
| 457 this, |
| 458 &JumpList::DeferredRunUpdate); |
| 459 } |
| 460 } |
| 461 |
| 462 void JumpList::DeferredRunUpdate() { |
| 463 TRACE_EVENT0("browser", "JumpList::DeferredRunUpdate"); |
443 // Check if incognito windows (or normal windows) are disabled by policy. | 464 // Check if incognito windows (or normal windows) are disabled by policy. |
444 IncognitoModePrefs::Availability incognito_availability = | 465 IncognitoModePrefs::Availability incognito_availability = |
445 profile_ ? IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) | 466 profile_ ? IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) |
446 : IncognitoModePrefs::ENABLED; | 467 : IncognitoModePrefs::ENABLED; |
447 | 468 |
448 BrowserThread::PostTask( | 469 BrowserThread::PostTask( |
449 BrowserThread::FILE, FROM_HERE, | 470 BrowserThread::FILE, FROM_HERE, |
450 base::Bind(&JumpList::RunUpdateOnFileThread, | 471 base::Bind(&JumpList::RunUpdateOnFileThread, |
451 this, | 472 this, |
452 incognito_availability)); | 473 incognito_availability)); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 | 526 |
506 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { | 527 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { |
507 } | 528 } |
508 | 529 |
509 void JumpList::TopSitesChanged(history::TopSites* top_sites) { | 530 void JumpList::TopSitesChanged(history::TopSites* top_sites) { |
510 top_sites->GetMostVisitedURLs( | 531 top_sites->GetMostVisitedURLs( |
511 base::Bind(&JumpList::OnMostVisitedURLsAvailable, | 532 base::Bind(&JumpList::OnMostVisitedURLsAvailable, |
512 weak_ptr_factory_.GetWeakPtr()), | 533 weak_ptr_factory_.GetWeakPtr()), |
513 false); | 534 false); |
514 } | 535 } |
OLD | NEW |