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" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
| 16 #include "base/sequenced_task_runner.h" | 16 #include "base/sequenced_task_runner.h" |
| 17 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| 18 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 20 #include "base/task_scheduler/post_task.h" | 20 #include "base/task_scheduler/post_task.h" |
| 21 #include "base/threading/thread.h" | 21 #include "base/threading/thread.h" |
| 22 #include "base/threading/thread_restrictions.h" | 22 #include "base/threading/thread_restrictions.h" |
| 23 #include "base/timer/elapsed_timer.h" | |
| 23 #include "base/trace_event/trace_event.h" | 24 #include "base/trace_event/trace_event.h" |
| 24 #include "chrome/browser/chrome_notification_types.h" | 25 #include "chrome/browser/chrome_notification_types.h" |
| 25 #include "chrome/browser/favicon/favicon_service_factory.h" | 26 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 26 #include "chrome/browser/history/top_sites_factory.h" | 27 #include "chrome/browser/history/top_sites_factory.h" |
| 27 #include "chrome/browser/metrics/jumplist_metrics_win.h" | 28 #include "chrome/browser/metrics/jumplist_metrics_win.h" |
| 28 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
| 29 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 30 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
| 30 #include "chrome/browser/shell_integration_win.h" | 31 #include "chrome/browser/shell_integration_win.h" |
| 31 #include "chrome/browser/win/jumplist_file_util.h" | 32 #include "chrome/browser/win/jumplist_file_util.h" |
| 32 #include "chrome/common/chrome_constants.h" | 33 #include "chrome/common/chrome_constants.h" |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 59 #include "url/gurl.h" | 60 #include "url/gurl.h" |
| 60 | 61 |
| 61 using content::BrowserThread; | 62 using content::BrowserThread; |
| 62 using JumpListData = JumpList::JumpListData; | 63 using JumpListData = JumpList::JumpListData; |
| 63 | 64 |
| 64 namespace { | 65 namespace { |
| 65 | 66 |
| 66 // Delay jumplist updates to allow collapsing of redundant update requests. | 67 // Delay jumplist updates to allow collapsing of redundant update requests. |
| 67 const int kDelayForJumplistUpdateInMS = 3500; | 68 const int kDelayForJumplistUpdateInMS = 3500; |
| 68 | 69 |
| 70 // Timeout jumplist updates for users with extremely slow OS. | |
| 71 const int kTimeOutForJumplistUpdateInMS = 500; | |
|
grt (UTC plus 2)
2017/04/20 12:48:53
nit:
constexpr base::TimeDelta kTimeOutForJumplist
chengx
2017/04/20 21:01:36
Done.
| |
| 72 | |
| 69 // Append the common switches to each shell link. | 73 // Append the common switches to each shell link. |
| 70 void AppendCommonSwitches(ShellLinkItem* shell_link) { | 74 void AppendCommonSwitches(ShellLinkItem* shell_link) { |
| 71 const char* kSwitchNames[] = { switches::kUserDataDir }; | 75 const char* kSwitchNames[] = { switches::kUserDataDir }; |
| 72 const base::CommandLine& command_line = | 76 const base::CommandLine& command_line = |
| 73 *base::CommandLine::ForCurrentProcess(); | 77 *base::CommandLine::ForCurrentProcess(); |
| 74 shell_link->GetCommandLine()->CopySwitchesFrom(command_line, | 78 shell_link->GetCommandLine()->CopySwitchesFrom(command_line, |
| 75 kSwitchNames, | 79 kSwitchNames, |
| 76 arraysize(kSwitchNames)); | 80 arraysize(kSwitchNames)); |
| 77 } | 81 } |
| 78 | 82 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 const base::FilePath& icon_dir, | 185 const base::FilePath& icon_dir, |
| 182 const ShellLinkItemList& most_visited_pages, | 186 const ShellLinkItemList& most_visited_pages, |
| 183 const ShellLinkItemList& recently_closed_pages, | 187 const ShellLinkItemList& recently_closed_pages, |
| 184 IncognitoModePrefs::Availability incognito_availability) { | 188 IncognitoModePrefs::Availability incognito_availability) { |
| 185 // JumpList is implemented only on Windows 7 or later. | 189 // JumpList is implemented only on Windows 7 or later. |
| 186 // So, we should return now when this function is called on earlier versions | 190 // So, we should return now when this function is called on earlier versions |
| 187 // of Windows. | 191 // of Windows. |
| 188 if (!JumpListUpdater::IsEnabled()) | 192 if (!JumpListUpdater::IsEnabled()) |
| 189 return true; | 193 return true; |
| 190 | 194 |
| 195 // Records the time cost of starting a JumpListUpdater. | |
| 196 base::ElapsedTimer begin_update_timer; | |
| 197 | |
| 191 JumpListUpdater jumplist_updater(app_id); | 198 JumpListUpdater jumplist_updater(app_id); |
| 192 if (!jumplist_updater.BeginUpdate()) | 199 if (!jumplist_updater.BeginUpdate()) |
| 193 return false; | 200 return false; |
| 194 | 201 |
| 202 // Stops jumplist update if JumpListUpdater's start times out, as it's very | |
| 203 // likely the following update steps will also take a long time. | |
| 204 if (begin_update_timer.Elapsed().InMilliseconds() >= | |
|
grt (UTC plus 2)
2017/04/20 12:48:53
nit:
if (begin_update_timer.Elapsed() >= kTimeOu
chengx
2017/04/20 21:01:36
Done.
| |
| 205 kTimeOutForJumplistUpdateInMS) | |
| 206 return false; | |
| 207 | |
| 195 // We allocate 60% of the given JumpList slots to "most-visited" items | 208 // We allocate 60% of the given JumpList slots to "most-visited" items |
| 196 // and 40% to "recently-closed" items, respectively. | 209 // and 40% to "recently-closed" items, respectively. |
| 197 // Nevertheless, if there are not so many items in |recently_closed_pages|, | 210 // Nevertheless, if there are not so many items in |recently_closed_pages|, |
| 198 // we give the remaining slots to "most-visited" items. | 211 // we give the remaining slots to "most-visited" items. |
| 199 // The default maximum number of items to display in JumpList is 10. | 212 // The default maximum number of items to display in JumpList is 10. |
| 200 // https://msdn.microsoft.com/en-us/library/windows/desktop/dd378398(v=vs.85). aspx | 213 // https://msdn.microsoft.com/en-us/library/windows/desktop/dd378398(v=vs.85). aspx |
| 201 const int kMostVisited = 60; | 214 const int kMostVisited = 60; |
| 202 const int kRecentlyClosed = 40; | 215 const int kRecentlyClosed = 40; |
| 203 const int kTotal = kMostVisited + kRecentlyClosed; | 216 const int kTotal = kMostVisited + kRecentlyClosed; |
| 204 size_t most_visited_items = | 217 size_t most_visited_items = |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 227 // Create icon files for shortcuts in the "Most Visited" category. | 240 // Create icon files for shortcuts in the "Most Visited" category. |
| 228 CreateIconFiles(icon_dir, most_visited_pages, most_visited_items); | 241 CreateIconFiles(icon_dir, most_visited_pages, most_visited_items); |
| 229 | 242 |
| 230 // Create icon files for shortcuts in the "Recently Closed" category. | 243 // Create icon files for shortcuts in the "Recently Closed" category. |
| 231 CreateIconFiles(icon_dir, recently_closed_pages, recently_closed_items); | 244 CreateIconFiles(icon_dir, recently_closed_pages, recently_closed_items); |
| 232 } | 245 } |
| 233 | 246 |
| 234 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. | 247 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. |
| 235 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplist.UpdateJumpListDuration"); | 248 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplist.UpdateJumpListDuration"); |
| 236 | 249 |
| 250 // Records the time cost of AddCustomCategory in JumpListUpdater. | |
| 251 base::ElapsedTimer add_category_timer; | |
| 252 | |
| 237 // Update the "Most Visited" category of the JumpList if it exists. | 253 // Update the "Most Visited" category of the JumpList if it exists. |
| 238 // This update request is applied into the JumpList when we commit this | 254 // This update request is applied into the JumpList when we commit this |
| 239 // transaction. | 255 // transaction. |
| 240 if (!jumplist_updater.AddCustomCategory( | 256 if (!jumplist_updater.AddCustomCategory( |
| 241 l10n_util::GetStringUTF16(IDS_NEW_TAB_MOST_VISITED), | 257 l10n_util::GetStringUTF16(IDS_NEW_TAB_MOST_VISITED), |
| 242 most_visited_pages, most_visited_items)) { | 258 most_visited_pages, most_visited_items)) { |
| 243 return false; | 259 return false; |
|
grt (UTC plus 2)
2017/04/20 12:48:53
don't these early returns skew the data in WinJump
chengx
2017/04/20 21:01:36
Re: Since I am logging all its 4 steps' (BeginUpda
grt (UTC plus 2)
2017/04/21 10:11:25
Please leave a doc comment here near the first cal
| |
| 244 } | 260 } |
| 245 | 261 |
| 246 // Update the "Recently Closed" category of the JumpList. | 262 // Update the "Recently Closed" category of the JumpList. |
| 247 if (!jumplist_updater.AddCustomCategory( | 263 if (!jumplist_updater.AddCustomCategory( |
| 248 l10n_util::GetStringUTF16(IDS_RECENTLY_CLOSED), | 264 l10n_util::GetStringUTF16(IDS_RECENTLY_CLOSED), |
| 249 recently_closed_pages, recently_closed_items)) { | 265 recently_closed_pages, recently_closed_items)) { |
| 250 return false; | 266 return false; |
| 251 } | 267 } |
| 252 | 268 |
| 269 // Stops jumplist update if AddCustomCategory times out, as it's very likely | |
| 270 // the following CommitUpdate call will also take a long time. | |
| 271 if (add_category_timer.Elapsed().InMilliseconds() >= | |
|
grt (UTC plus 2)
2017/04/20 12:48:53
here, too
chengx
2017/04/20 21:01:36
I decided to only keep a timer for BeginUpdate for
| |
| 272 kTimeOutForJumplistUpdateInMS) | |
| 273 return false; | |
| 274 | |
| 253 // Update the "Tasks" category of the JumpList. | 275 // Update the "Tasks" category of the JumpList. |
| 254 if (!UpdateTaskCategory(&jumplist_updater, incognito_availability)) | 276 if (!UpdateTaskCategory(&jumplist_updater, incognito_availability)) |
| 255 return false; | 277 return false; |
| 256 | 278 |
| 257 // Commit this transaction and send the updated JumpList to Windows. | 279 // Commit this transaction and send the updated JumpList to Windows. |
| 258 if (!jumplist_updater.CommitUpdate()) | 280 if (!jumplist_updater.CommitUpdate()) |
| 259 return false; | 281 return false; |
| 260 | 282 |
| 261 return true; | 283 return true; |
| 262 } | 284 } |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 629 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { | 651 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { |
| 630 } | 652 } |
| 631 | 653 |
| 632 void JumpList::TopSitesChanged(history::TopSites* top_sites, | 654 void JumpList::TopSitesChanged(history::TopSites* top_sites, |
| 633 ChangeReason change_reason) { | 655 ChangeReason change_reason) { |
| 634 top_sites->GetMostVisitedURLs( | 656 top_sites->GetMostVisitedURLs( |
| 635 base::Bind(&JumpList::OnMostVisitedURLsAvailable, | 657 base::Bind(&JumpList::OnMostVisitedURLsAvailable, |
| 636 weak_ptr_factory_.GetWeakPtr()), | 658 weak_ptr_factory_.GetWeakPtr()), |
| 637 false); | 659 false); |
| 638 } | 660 } |
| OLD | NEW |