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" |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 } | 174 } |
175 | 175 |
176 return jumplist_updater->AddTasks(items); | 176 return jumplist_updater->AddTasks(items); |
177 } | 177 } |
178 | 178 |
179 // Updates the application JumpList. | 179 // Updates the application JumpList. |
180 bool UpdateJumpList(const wchar_t* app_id, | 180 bool UpdateJumpList(const wchar_t* app_id, |
181 const base::FilePath& icon_dir, | 181 const base::FilePath& icon_dir, |
182 const ShellLinkItemList& most_visited_pages, | 182 const ShellLinkItemList& most_visited_pages, |
183 const ShellLinkItemList& recently_closed_pages, | 183 const ShellLinkItemList& recently_closed_pages, |
184 bool should_update_most_visited, | |
185 bool should_update_recent_closed, | |
184 IncognitoModePrefs::Availability incognito_availability) { | 186 IncognitoModePrefs::Availability incognito_availability) { |
185 // JumpList is implemented only on Windows 7 or later. | 187 // JumpList is implemented only on Windows 7 or later. |
186 // So, we should return now when this function is called on earlier versions | 188 // So, we should return now when this function is called on earlier versions |
187 // of Windows. | 189 // of Windows. |
188 if (!JumpListUpdater::IsEnabled()) | 190 if (!JumpListUpdater::IsEnabled()) |
189 return true; | 191 return true; |
190 | 192 |
191 JumpListUpdater jumplist_updater(app_id); | 193 JumpListUpdater jumplist_updater(app_id); |
192 if (!jumplist_updater.BeginUpdate()) | 194 if (!jumplist_updater.BeginUpdate()) |
193 return false; | 195 return false; |
194 | 196 |
195 // We allocate 60% of the given JumpList slots to "most-visited" items | 197 // The default maximum number of items to display in JumpList is 10. |
196 // and 40% to "recently-closed" items, respectively. | 198 // https://msdn.microsoft.com/en-us/library/windows/desktop/dd378398(v=vs.85). aspx |
grt (UTC plus 2)
2017/04/25 08:29:39
hot tip: this can be reduced to https://msdn.micro
chengx
2017/04/25 23:00:24
Thanks! I've moved the change of this section to a
| |
199 // The "Most visited" category title always takes 1 of the JumpList slots if | |
200 // |most_visited_pages| isn't empty. | |
201 // The "Recently closed" category title will also take 1 if | |
202 // |recently_closed_pages| isn't empty. | |
203 // For the remaining slots, we allocate 5/8 (i.e., 5 slots if both categories | |
204 // present) to "most-visited" items and 3/8 (i.e., 3 slots if both categories | |
205 // present) to "recently-closed" items, respectively. | |
197 // Nevertheless, if there are not so many items in |recently_closed_pages|, | 206 // Nevertheless, if there are not so many items in |recently_closed_pages|, |
198 // we give the remaining slots to "most-visited" items. | 207 // we give the remaining slots to "most-visited" items. |
199 // The default maximum number of items to display in JumpList is 10. | 208 |
200 // https://msdn.microsoft.com/en-us/library/windows/desktop/dd378398(v=vs.85). aspx | 209 const int kMostVisited = 50; |
201 const int kMostVisited = 60; | 210 const int kRecentlyClosed = 30; |
202 const int kRecentlyClosed = 40; | |
203 const int kTotal = kMostVisited + kRecentlyClosed; | 211 const int kTotal = kMostVisited + kRecentlyClosed; |
212 | |
213 // Adjust the available jumplist slots accordingly. | |
214 size_t user_max_items_adjusted = jumplist_updater.user_max_items(); | |
215 if (!most_visited_pages.empty()) | |
216 user_max_items_adjusted--; | |
217 if (!recently_closed_pages.empty()) | |
218 user_max_items_adjusted--; | |
219 | |
204 size_t most_visited_items = | 220 size_t most_visited_items = |
205 MulDiv(jumplist_updater.user_max_items(), kMostVisited, kTotal); | 221 MulDiv(user_max_items_adjusted, kMostVisited, kTotal); |
206 size_t recently_closed_items = | 222 size_t recently_closed_items = user_max_items_adjusted - most_visited_items; |
207 jumplist_updater.user_max_items() - most_visited_items; | |
208 if (recently_closed_pages.size() < recently_closed_items) { | 223 if (recently_closed_pages.size() < recently_closed_items) { |
209 most_visited_items += recently_closed_items - recently_closed_pages.size(); | 224 most_visited_items += recently_closed_items - recently_closed_pages.size(); |
210 recently_closed_items = recently_closed_pages.size(); | 225 recently_closed_items = recently_closed_pages.size(); |
211 } | 226 } |
212 | 227 |
213 // Delete the content in JumpListIcons folder and log the results to UMA. | 228 if (should_update_most_visited) { |
214 DeleteDirectoryContentAndLogResults(icon_dir, kFileDeleteLimit); | 229 // Delete the content in JumpListIconsMostVisited folder and log the results |
230 // to UMA. | |
231 base::FilePath icon_dir_most_visited = icon_dir.DirName().Append( | |
232 icon_dir.BaseName().value() + FILE_PATH_LITERAL("MostVisited")); | |
215 | 233 |
216 // If JumpListIcons directory doesn't exist (we have tried to create it | 234 DeleteDirectoryContentAndLogResults(icon_dir_most_visited, |
217 // already) or is not empty, skip updating the jumplist icons. The jumplist | 235 kFileDeleteLimit); |
218 // links should be updated anyway, as it doesn't involve disk IO. In this | |
219 // case, Chrome's icon will be used for the new links. | |
220 | 236 |
221 if (base::DirectoryExists(icon_dir) && base::IsDirectoryEmpty(icon_dir)) { | 237 // If the directory doesn't exist (we have tried to create it in |
222 // TODO(chengx): Remove this UMA metric after fixing http://crbug.com/40407. | 238 // DeleteDirectoryContentAndLogResults) or is not empty, skip updating the |
223 UMA_HISTOGRAM_COUNTS_100( | 239 // jumplist icons. The jumplist links should be updated anyway, as it |
224 "WinJumplist.CreateIconFilesCount", | 240 // doesn't involve disk IO. In this case, Chrome's icon will be used for the |
225 most_visited_pages.size() + recently_closed_pages.size()); | 241 // new links. |
242 if (base::DirectoryExists(icon_dir_most_visited) && | |
243 base::IsDirectoryEmpty(icon_dir_most_visited)) { | |
244 // Create icon files for shortcuts in the "Most Visited" category. | |
245 CreateIconFiles(icon_dir_most_visited, most_visited_pages, | |
246 most_visited_items); | |
247 } | |
248 } | |
226 | 249 |
227 // Create icon files for shortcuts in the "Most Visited" category. | 250 if (should_update_recent_closed) { |
228 CreateIconFiles(icon_dir, most_visited_pages, most_visited_items); | 251 // Delete the content in JumpListIconsRecentClosed folder and log the |
252 // results to UMA. | |
253 base::FilePath icon_dir_recent_closed = icon_dir.DirName().Append( | |
254 icon_dir.BaseName().value() + FILE_PATH_LITERAL("RecentClosed")); | |
229 | 255 |
230 // Create icon files for shortcuts in the "Recently Closed" category. | 256 DeleteDirectoryContentAndLogResults(icon_dir_recent_closed, |
231 CreateIconFiles(icon_dir, recently_closed_pages, recently_closed_items); | 257 kFileDeleteLimit); |
258 | |
259 if (base::DirectoryExists(icon_dir_recent_closed) && | |
260 base::IsDirectoryEmpty(icon_dir_recent_closed)) { | |
261 // Create icon files for shortcuts in the "Recently Closed" category. | |
262 CreateIconFiles(icon_dir_recent_closed, recently_closed_pages, | |
263 recently_closed_items); | |
264 } | |
232 } | 265 } |
233 | 266 |
234 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. | 267 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. |
235 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplist.UpdateJumpListDuration"); | 268 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplist.UpdateJumpListDuration"); |
236 | 269 |
237 // Update the "Most Visited" category of the JumpList if it exists. | 270 // Update the "Most Visited" category of the JumpList if it exists. |
238 // This update request is applied into the JumpList when we commit this | 271 // This update request is applied into the JumpList when we commit this |
239 // transaction. | 272 // transaction. |
240 if (!jumplist_updater.AddCustomCategory( | 273 if (!jumplist_updater.AddCustomCategory( |
241 l10n_util::GetStringUTF16(IDS_NEW_TAB_MOST_VISITED), | 274 l10n_util::GetStringUTF16(IDS_NEW_TAB_MOST_VISITED), |
(...skipping 16 matching lines...) Expand all Loading... | |
258 if (!jumplist_updater.CommitUpdate()) | 291 if (!jumplist_updater.CommitUpdate()) |
259 return false; | 292 return false; |
260 | 293 |
261 return true; | 294 return true; |
262 } | 295 } |
263 | 296 |
264 // Updates the jumplist, once all the data has been fetched. | 297 // Updates the jumplist, once all the data has been fetched. |
265 void RunUpdateJumpList(IncognitoModePrefs::Availability incognito_availability, | 298 void RunUpdateJumpList(IncognitoModePrefs::Availability incognito_availability, |
266 const std::wstring& app_id, | 299 const std::wstring& app_id, |
267 const base::FilePath& icon_dir, | 300 const base::FilePath& icon_dir, |
301 bool should_update_most_visited, | |
302 bool should_update_recent_closed, | |
268 base::RefCountedData<JumpListData>* ref_counted_data) { | 303 base::RefCountedData<JumpListData>* ref_counted_data) { |
269 JumpListData* data = &ref_counted_data->data; | 304 JumpListData* data = &ref_counted_data->data; |
270 ShellLinkItemList local_most_visited_pages; | 305 ShellLinkItemList local_most_visited_pages; |
271 ShellLinkItemList local_recently_closed_pages; | 306 ShellLinkItemList local_recently_closed_pages; |
272 | 307 |
273 { | 308 { |
274 base::AutoLock auto_lock(data->list_lock_); | 309 base::AutoLock auto_lock(data->list_lock_); |
275 // Make sure we are not out of date: if icon_urls_ is not empty, then | 310 // Make sure we are not out of date: if icon_urls_ is not empty, then |
276 // another notification has been received since we processed this one | 311 // another notification has been received since we processed this one |
277 if (!data->icon_urls_.empty()) | 312 if (!data->icon_urls_.empty()) |
278 return; | 313 return; |
279 | 314 |
280 // Make local copies of lists so we can release the lock. | 315 // Make local copies of lists so we can release the lock. |
281 local_most_visited_pages = data->most_visited_pages_; | 316 local_most_visited_pages = data->most_visited_pages_; |
282 local_recently_closed_pages = data->recently_closed_pages_; | 317 local_recently_closed_pages = data->recently_closed_pages_; |
283 } | 318 } |
284 | 319 |
285 // Create a new JumpList and replace the current JumpList with it. The | 320 // Create a new JumpList and replace the current JumpList with it. The |
286 // jumplist links are updated anyway, while the jumplist icons may not as | 321 // jumplist links are updated anyway, while the jumplist icons may not as |
287 // mentioned above. | 322 // mentioned above. |
288 UpdateJumpList(app_id.c_str(), icon_dir, local_most_visited_pages, | 323 UpdateJumpList(app_id.c_str(), icon_dir, local_most_visited_pages, |
289 local_recently_closed_pages, incognito_availability); | 324 local_recently_closed_pages, should_update_most_visited, |
325 should_update_recent_closed, incognito_availability); | |
290 } | 326 } |
291 | 327 |
292 } // namespace | 328 } // namespace |
293 | 329 |
294 JumpList::JumpListData::JumpListData() {} | 330 JumpList::JumpListData::JumpListData() {} |
295 | 331 |
296 JumpList::JumpListData::~JumpListData() {} | 332 JumpList::JumpListData::~JumpListData() {} |
297 | 333 |
298 JumpList::JumpList(Profile* profile) | 334 JumpList::JumpList(Profile* profile) |
299 : RefcountedKeyedService(content::BrowserThread::GetTaskRunnerForThread( | 335 : RefcountedKeyedService(content::BrowserThread::GetTaskRunnerForThread( |
300 content::BrowserThread::UI)), | 336 content::BrowserThread::UI)), |
301 profile_(profile), | 337 profile_(profile), |
338 should_update_most_visited_(true), | |
339 should_update_recent_closed_(true), | |
302 jumplist_data_(new base::RefCountedData<JumpListData>), | 340 jumplist_data_(new base::RefCountedData<JumpListData>), |
303 task_id_(base::CancelableTaskTracker::kBadTaskId), | 341 task_id_(base::CancelableTaskTracker::kBadTaskId), |
304 update_jumplisticons_task_runner_(base::CreateCOMSTATaskRunnerWithTraits( | 342 update_jumplist_task_runner_(base::CreateCOMSTATaskRunnerWithTraits( |
305 base::TaskTraits() | 343 base::TaskTraits() |
306 .WithPriority(base::TaskPriority::USER_VISIBLE) | 344 .WithPriority(base::TaskPriority::USER_VISIBLE) |
307 .WithShutdownBehavior( | 345 .WithShutdownBehavior( |
308 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) | 346 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) |
309 .MayBlock())), | 347 .MayBlock())), |
310 delete_jumplisticonsold_task_runner_( | 348 delete_jumplisticons_task_runner_( |
311 base::CreateSequencedTaskRunnerWithTraits( | 349 base::CreateSequencedTaskRunnerWithTraits( |
312 base::TaskTraits() | 350 base::TaskTraits() |
313 .WithPriority(base::TaskPriority::BACKGROUND) | 351 .WithPriority(base::TaskPriority::BACKGROUND) |
314 .WithShutdownBehavior( | 352 .WithShutdownBehavior( |
315 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) | 353 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) |
316 .MayBlock())), | 354 .MayBlock())), |
317 weak_ptr_factory_(this) { | 355 weak_ptr_factory_(this) { |
318 DCHECK(Enabled()); | 356 DCHECK(Enabled()); |
319 // To update JumpList when a tab is added or removed, we add this object to | 357 // To update JumpList when a tab is added or removed, we add this object to |
320 // the observer list of the TabRestoreService class. | 358 // the observer list of the TabRestoreService class. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
382 pref_change_registrar_.reset(); | 420 pref_change_registrar_.reset(); |
383 } | 421 } |
384 profile_ = NULL; | 422 profile_ = NULL; |
385 } | 423 } |
386 | 424 |
387 void JumpList::ShutdownOnUIThread() { | 425 void JumpList::ShutdownOnUIThread() { |
388 DCHECK(CalledOnValidThread()); | 426 DCHECK(CalledOnValidThread()); |
389 Terminate(); | 427 Terminate(); |
390 } | 428 } |
391 | 429 |
392 void JumpList::OnMostVisitedURLsAvailable( | 430 void JumpList::OnMostVisitedURLsAvailable( |
grt (UTC plus 2)
2017/04/25 08:29:39
It seems that while the set of most visited sites
chengx
2017/04/25 23:00:24
I agree with the idea. I'll use another CL for thi
grt (UTC plus 2)
2017/04/26 09:14:33
Agreed, this isn't the right CL for it. Thanks.
| |
393 const history::MostVisitedURLList& urls) { | 431 const history::MostVisitedURLList& urls) { |
394 DCHECK(CalledOnValidThread()); | 432 DCHECK(CalledOnValidThread()); |
395 // If we have a pending favicon request, cancel it here (it is out of date). | 433 // If we have a pending favicon request, cancel it here (it is out of date). |
396 CancelPendingUpdate(); | 434 CancelPendingUpdate(); |
397 | 435 |
398 { | 436 { |
399 JumpListData* data = &jumplist_data_->data; | 437 JumpListData* data = &jumplist_data_->data; |
400 base::AutoLock auto_lock(data->list_lock_); | 438 base::AutoLock auto_lock(data->list_lock_); |
401 data->most_visited_pages_.clear(); | 439 data->most_visited_pages_.clear(); |
402 for (size_t i = 0; i < urls.size(); i++) { | 440 for (size_t i = 0; i < urls.size(); i++) { |
403 const history::MostVisitedURL& url = urls[i]; | 441 const history::MostVisitedURL& url = urls[i]; |
404 scoped_refptr<ShellLinkItem> link = CreateShellLink(); | 442 scoped_refptr<ShellLinkItem> link = CreateShellLink(); |
405 std::string url_string = url.url.spec(); | 443 std::string url_string = url.url.spec(); |
406 std::wstring url_string_wide = base::UTF8ToWide(url_string); | 444 std::wstring url_string_wide = base::UTF8ToWide(url_string); |
407 link->GetCommandLine()->AppendArgNative(url_string_wide); | 445 link->GetCommandLine()->AppendArgNative(url_string_wide); |
408 link->GetCommandLine()->AppendSwitchASCII( | 446 link->GetCommandLine()->AppendSwitchASCII( |
409 switches::kWinJumplistAction, jumplist::kMostVisitedCategory); | 447 switches::kWinJumplistAction, jumplist::kMostVisitedCategory); |
410 link->set_title(!url.title.empty() ? url.title : url_string_wide); | 448 link->set_title(!url.title.empty() ? url.title : url_string_wide); |
411 data->most_visited_pages_.push_back(link); | 449 data->most_visited_pages_.push_back(link); |
412 data->icon_urls_.push_back(make_pair(url_string, link)); | 450 data->icon_urls_.push_back(make_pair(url_string, link)); |
grt (UTC plus 2)
2017/04/25 08:29:38
nit: std::make_pair
chengx
2017/04/25 23:00:24
Done.
| |
413 } | 451 } |
414 } | 452 } |
415 | 453 |
454 // Since only the "Most Visited" category changes, mark the flags so that icon | |
455 // files only for this category are updated later on. | |
456 should_update_most_visited_ = true; | |
457 should_update_recent_closed_ = false; | |
grt (UTC plus 2)
2017/04/25 08:29:39
what if visited URLs arrive immediately after gett
chengx
2017/04/25 23:00:24
You're right. The "TopSites Service" and the "TabR
| |
458 | |
416 // Send a query that retrieves the first favicon. | 459 // Send a query that retrieves the first favicon. |
417 StartLoadingFavicon(); | 460 StartLoadingFavicon(); |
418 } | 461 } |
419 | 462 |
420 void JumpList::TabRestoreServiceChanged(sessions::TabRestoreService* service) { | 463 void JumpList::TabRestoreServiceChanged(sessions::TabRestoreService* service) { |
421 DCHECK(CalledOnValidThread()); | 464 DCHECK(CalledOnValidThread()); |
422 // if we have a pending handle request, cancel it here (it is out of date). | 465 // if we have a pending handle request, cancel it here (it is out of date). |
grt (UTC plus 2)
2017/04/25 08:29:38
nit: "handle" -> "favicon"
chengx
2017/04/25 23:00:24
Done.
| |
423 CancelPendingUpdate(); | 466 CancelPendingUpdate(); |
424 | 467 |
425 // local list to pass to methods | 468 // local list to pass to methods |
426 ShellLinkItemList temp_list; | 469 ShellLinkItemList temp_list; |
427 | 470 |
428 // Create a list of ShellLinkItems from the "Recently Closed" pages. | 471 // Create a list of ShellLinkItems from the "Recently Closed" pages. |
429 // As noted above, we create a ShellLinkItem objects with the following | 472 // As noted above, we create a ShellLinkItem objects with the following |
430 // parameters. | 473 // parameters. |
431 // * arguments | 474 // * arguments |
432 // The last URL of the tab object. | 475 // The last URL of the tab object. |
433 // * title | 476 // * title |
434 // The title of the last URL. | 477 // The title of the last URL. |
435 // * icon | 478 // * icon |
436 // An empty string. This value is to be updated in OnFaviconDataAvailable(). | 479 // An empty string. This value is to be updated in OnFaviconDataAvailable(). |
437 // This code is copied from | 480 // This code is copied from |
438 // RecentlyClosedTabsHandler::TabRestoreServiceChanged() to emulate it. | 481 // RecentlyClosedTabsHandler::TabRestoreServiceChanged() to emulate it. |
439 const int kRecentlyClosedCount = 4; | 482 const int kRecentlyClosedCount = 3; |
440 sessions::TabRestoreService* tab_restore_service = | 483 sessions::TabRestoreService* tab_restore_service = |
441 TabRestoreServiceFactory::GetForProfile(profile_); | 484 TabRestoreServiceFactory::GetForProfile(profile_); |
442 for (const auto& entry : tab_restore_service->entries()) { | 485 for (const auto& entry : tab_restore_service->entries()) { |
443 switch (entry->type) { | 486 switch (entry->type) { |
444 case sessions::TabRestoreService::TAB: | 487 case sessions::TabRestoreService::TAB: |
445 AddTab(static_cast<const sessions::TabRestoreService::Tab&>(*entry), | 488 AddTab(static_cast<const sessions::TabRestoreService::Tab&>(*entry), |
grt (UTC plus 2)
2017/04/25 08:29:39
this looks pretty messed up: AddTab puts ShellLink
chengx
2017/04/25 23:00:24
Done. Now JumpListData->data is updated entirely a
| |
446 &temp_list, kRecentlyClosedCount); | 489 &temp_list, kRecentlyClosedCount); |
447 break; | 490 break; |
448 case sessions::TabRestoreService::WINDOW: | 491 case sessions::TabRestoreService::WINDOW: |
449 AddWindow( | 492 AddWindow( |
450 static_cast<const sessions::TabRestoreService::Window&>(*entry), | 493 static_cast<const sessions::TabRestoreService::Window&>(*entry), |
451 &temp_list, kRecentlyClosedCount); | 494 &temp_list, kRecentlyClosedCount); |
452 break; | 495 break; |
453 } | 496 } |
454 } | 497 } |
455 // Lock recently_closed_pages and copy temp_list into it. | 498 // Lock recently_closed_pages and copy temp_list into it. |
456 { | 499 { |
457 JumpListData* data = &jumplist_data_->data; | 500 JumpListData* data = &jumplist_data_->data; |
458 base::AutoLock auto_lock(data->list_lock_); | 501 base::AutoLock auto_lock(data->list_lock_); |
459 data->recently_closed_pages_ = temp_list; | 502 data->recently_closed_pages_ = temp_list; |
grt (UTC plus 2)
2017/04/25 08:29:39
swap would be more efficient here so that no copie
chengx
2017/04/25 23:00:24
This piece of code is gone after making JumpListDa
| |
460 } | 503 } |
461 | 504 |
505 // Since only the "Recently Closed" category changes, mark the flags so that | |
506 // icon files only for this category are updated later on. | |
507 should_update_most_visited_ = false; | |
508 should_update_recent_closed_ = true; | |
509 | |
462 // Send a query that retrieves the first favicon. | 510 // Send a query that retrieves the first favicon. |
463 StartLoadingFavicon(); | 511 StartLoadingFavicon(); |
464 } | 512 } |
465 | 513 |
466 void JumpList::TabRestoreServiceDestroyed( | 514 void JumpList::TabRestoreServiceDestroyed( |
467 sessions::TabRestoreService* service) {} | 515 sessions::TabRestoreService* service) {} |
468 | 516 |
469 bool JumpList::AddTab(const sessions::TabRestoreService::Tab& tab, | 517 bool JumpList::AddTab(const sessions::TabRestoreService::Tab& tab, |
470 ShellLinkItemList* list, | 518 ShellLinkItemList* list, |
471 size_t max_items) { | 519 size_t max_items) { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
571 | 619 |
572 void JumpList::OnIncognitoAvailabilityChanged() { | 620 void JumpList::OnIncognitoAvailabilityChanged() { |
573 DCHECK(CalledOnValidThread()); | 621 DCHECK(CalledOnValidThread()); |
574 | 622 |
575 bool waiting_for_icons = true; | 623 bool waiting_for_icons = true; |
576 { | 624 { |
577 JumpListData* data = &jumplist_data_->data; | 625 JumpListData* data = &jumplist_data_->data; |
578 base::AutoLock auto_lock(data->list_lock_); | 626 base::AutoLock auto_lock(data->list_lock_); |
579 waiting_for_icons = !data->icon_urls_.empty(); | 627 waiting_for_icons = !data->icon_urls_.empty(); |
580 } | 628 } |
581 if (!waiting_for_icons) | 629 |
630 // Since neither the "Most Visited" category nor the "Recently Closed" | |
631 // category changes, mark the flags so that icon files for those categories | |
632 // won't be updated later on. | |
633 if (!waiting_for_icons) { | |
634 should_update_most_visited_ = false; | |
635 should_update_recent_closed_ = false; | |
582 PostRunUpdate(); | 636 PostRunUpdate(); |
583 // If |icon_urls_| isn't empty then OnFaviconDataAvailable will eventually | 637 } |
584 // call PostRunUpdate(). | |
585 } | 638 } |
586 | 639 |
587 void JumpList::PostRunUpdate() { | 640 void JumpList::PostRunUpdate() { |
588 DCHECK(CalledOnValidThread()); | 641 DCHECK(CalledOnValidThread()); |
589 | 642 |
590 TRACE_EVENT0("browser", "JumpList::PostRunUpdate"); | 643 TRACE_EVENT0("browser", "JumpList::PostRunUpdate"); |
591 // Initialize the one-shot timer to update the jumplists in a while. | 644 // Initialize the one-shot timer to update the jumplists in a while. |
592 // If there is already a request queued then cancel it and post the new | 645 // If there is already a request queued then cancel it and post the new |
593 // request. This ensures that JumpListUpdates won't happen until there has | 646 // request. This ensures that JumpListUpdates won't happen until there has |
594 // been a brief quiet period, thus avoiding update storms. | 647 // been a brief quiet period, thus avoiding update storms. |
595 if (timer_.IsRunning()) { | 648 if (timer_.IsRunning()) { |
596 timer_.Reset(); | 649 timer_.Reset(); |
597 } else { | 650 } else { |
598 timer_.Start(FROM_HERE, | 651 timer_.Start(FROM_HERE, |
599 base::TimeDelta::FromMilliseconds(kDelayForJumplistUpdateInMS), | 652 base::TimeDelta::FromMilliseconds(kDelayForJumplistUpdateInMS), |
grt (UTC plus 2)
2017/04/25 08:29:39
It seems that favicons are fetched as the most vis
chengx
2017/04/25 23:00:24
Yes, those favicons will be thrown away if another
| |
600 this, | 653 this, |
601 &JumpList::DeferredRunUpdate); | 654 &JumpList::DeferredRunUpdate); |
602 } | 655 } |
603 } | 656 } |
604 | 657 |
605 void JumpList::DeferredRunUpdate() { | 658 void JumpList::DeferredRunUpdate() { |
606 DCHECK(CalledOnValidThread()); | 659 DCHECK(CalledOnValidThread()); |
607 | 660 |
608 TRACE_EVENT0("browser", "JumpList::DeferredRunUpdate"); | 661 TRACE_EVENT0("browser", "JumpList::DeferredRunUpdate"); |
609 // Check if incognito windows (or normal windows) are disabled by policy. | 662 // Check if incognito windows (or normal windows) are disabled by policy. |
610 IncognitoModePrefs::Availability incognito_availability = | 663 IncognitoModePrefs::Availability incognito_availability = |
611 profile_ ? IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) | 664 profile_ ? IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) |
612 : IncognitoModePrefs::ENABLED; | 665 : IncognitoModePrefs::ENABLED; |
613 | 666 |
614 // Post a task to update the jumplist in JumpListIcons folder, which consists | 667 // Post a task to update the JumpList, which consists of 1) delete old icons, |
615 // of 1) delete old icons, 2) create new icons, 3) notify the OS. | 668 // 2) create new icons, 3) notify the OS. |
616 update_jumplisticons_task_runner_->PostTask( | 669 update_jumplist_task_runner_->PostTask( |
617 FROM_HERE, base::Bind(&RunUpdateJumpList, incognito_availability, app_id_, | 670 FROM_HERE, |
618 icon_dir_, base::RetainedRef(jumplist_data_))); | 671 base::Bind(&RunUpdateJumpList, incognito_availability, app_id_, icon_dir_, |
672 should_update_most_visited_, should_update_recent_closed_, | |
673 base::RetainedRef(jumplist_data_))); | |
619 | 674 |
620 // Post a task to delete JumpListIconsOld folder and log the results to UMA. | 675 // Post a task to delete JumpListIcons folder as it't no longer needed. |
676 // Now we have JumpListIconsMostVisited folder and JumpListIconsRecentClosed | |
677 // folder instead. | |
678 delete_jumplisticons_task_runner_->PostTask( | |
679 FROM_HERE, | |
680 base::Bind(&DeleteDirectoryAndLogResults, icon_dir_, kFileDeleteLimit)); | |
681 | |
682 // Post a task to delete JumpListIconsOld folder as it't no longer needed. | |
621 base::FilePath icon_dir_old = icon_dir_.DirName().Append( | 683 base::FilePath icon_dir_old = icon_dir_.DirName().Append( |
622 icon_dir_.BaseName().value() + FILE_PATH_LITERAL("Old")); | 684 icon_dir_.BaseName().value() + FILE_PATH_LITERAL("Old")); |
623 | 685 |
624 delete_jumplisticonsold_task_runner_->PostTask( | 686 delete_jumplisticons_task_runner_->PostTask( |
625 FROM_HERE, base::Bind(&DeleteDirectoryAndLogResults, | 687 FROM_HERE, base::Bind(&DeleteDirectoryAndLogResults, |
626 std::move(icon_dir_old), kFileDeleteLimit)); | 688 std::move(icon_dir_old), kFileDeleteLimit)); |
627 } | 689 } |
628 | 690 |
629 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { | 691 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { |
630 } | 692 } |
631 | 693 |
632 void JumpList::TopSitesChanged(history::TopSites* top_sites, | 694 void JumpList::TopSitesChanged(history::TopSites* top_sites, |
633 ChangeReason change_reason) { | 695 ChangeReason change_reason) { |
634 top_sites->GetMostVisitedURLs( | 696 top_sites->GetMostVisitedURLs( |
635 base::Bind(&JumpList::OnMostVisitedURLsAvailable, | 697 base::Bind(&JumpList::OnMostVisitedURLsAvailable, |
636 weak_ptr_factory_.GetWeakPtr()), | 698 weak_ptr_factory_.GetWeakPtr()), |
637 false); | 699 false); |
638 } | 700 } |
OLD | NEW |