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" |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 } | 180 } |
| 181 | 181 |
| 182 return jumplist_updater->AddTasks(items); | 182 return jumplist_updater->AddTasks(items); |
| 183 } | 183 } |
| 184 | 184 |
| 185 // Updates the application JumpList, which consists of 1) delete old icon files; | 185 // Updates the application JumpList, which consists of 1) delete old icon files; |
| 186 // 2) create new icon files; 3) notify the OS. | 186 // 2) create new icon files; 3) notify the OS. |
| 187 // Note that any timeout error along the way results in the old jumplist being | 187 // Note that any timeout error along the way results in the old jumplist being |
| 188 // left as-is, while any non-timeout error results in the old jumplist being | 188 // left as-is, while any non-timeout error results in the old jumplist being |
| 189 // left as-is, but without icon files. | 189 // left as-is, but without icon files. |
| 190 void UpdateJumpList(const wchar_t* app_id, | 190 bool UpdateJumpList(const wchar_t* app_id, |
| 191 const base::FilePath& icon_dir, | 191 const base::FilePath& icon_dir, |
| 192 const ShellLinkItemList& most_visited_pages, | 192 const ShellLinkItemList& most_visited_pages, |
| 193 const ShellLinkItemList& recently_closed_pages, | 193 const ShellLinkItemList& recently_closed_pages, |
| 194 bool most_visited_pages_have_updates, | |
| 195 bool recently_closed_pages_have_updates, | |
| 194 IncognitoModePrefs::Availability incognito_availability) { | 196 IncognitoModePrefs::Availability incognito_availability) { |
| 195 if (!JumpListUpdater::IsEnabled()) | 197 if (!JumpListUpdater::IsEnabled()) |
| 196 return; | 198 return true; |
| 197 | 199 |
| 198 // Records the time cost of starting a JumpListUpdater. | 200 // Records the time cost of starting a JumpListUpdater. |
| 199 base::ElapsedTimer begin_update_timer; | 201 base::ElapsedTimer begin_update_timer; |
| 200 | 202 |
| 201 JumpListUpdater jumplist_updater(app_id); | 203 JumpListUpdater jumplist_updater(app_id); |
| 202 if (!jumplist_updater.BeginUpdate()) | 204 if (!jumplist_updater.BeginUpdate()) |
| 203 return; | 205 return false; |
| 204 | 206 |
| 205 // Stops jumplist update if JumpListUpdater's start times out, as it's very | 207 // Stops jumplist update if JumpListUpdater's start times out, as it's very |
| 206 // likely the following update steps will also take a long time. | 208 // likely the following update steps will also take a long time. |
| 207 if (begin_update_timer.Elapsed() >= kTimeOutForJumplistUpdate) | 209 if (begin_update_timer.Elapsed() >= kTimeOutForJumplistUpdate) |
| 208 return; | 210 return false; |
| 209 | 211 |
| 210 // 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. |
| 211 // https://msdn.microsoft.com/library/windows/desktop/dd378398.aspx | 213 // https://msdn.microsoft.com/library/windows/desktop/dd378398.aspx |
| 212 // The "Most visited" category title always takes 1 of the JumpList slots if | 214 // The "Most visited" category title always takes 1 of the JumpList slots if |
| 213 // |most_visited_pages| isn't empty. | 215 // |most_visited_pages| isn't empty. |
| 214 // The "Recently closed" category title will also take 1 if | 216 // The "Recently closed" category title will also take 1 if |
| 215 // |recently_closed_pages| isn't empty. | 217 // |recently_closed_pages| isn't empty. |
| 216 // For the remaining slots, we allocate 5/8 (i.e., 5 slots if both categories | 218 // For the remaining slots, we allocate 5/8 (i.e., 5 slots if both categories |
| 217 // present) to "most-visited" items and 3/8 (i.e., 3 slots if both categories | 219 // present) to "most-visited" items and 3/8 (i.e., 3 slots if both categories |
| 218 // present) to "recently-closed" items, respectively. | 220 // present) to "recently-closed" items, respectively. |
| 221 // Nevertheless, if there are not so many items in |recently_closed_pages|, | |
| 222 // we give the remaining slots to "most-visited" items. | |
| 219 | 223 |
| 220 const int kMostVisited = 50; | 224 const int kMostVisited = 50; |
| 221 const int kRecentlyClosed = 30; | 225 const int kRecentlyClosed = 30; |
| 222 const int kTotal = kMostVisited + kRecentlyClosed; | 226 const int kTotal = kMostVisited + kRecentlyClosed; |
| 223 | 227 |
| 224 // Adjust the available jumplist slots to account for the category titles. | 228 // Adjust the available jumplist slots to account for the category titles. |
| 225 size_t user_max_items_adjusted = jumplist_updater.user_max_items(); | 229 size_t user_max_items_adjusted = jumplist_updater.user_max_items(); |
| 226 if (!most_visited_pages.empty()) | 230 if (!most_visited_pages.empty()) |
| 227 --user_max_items_adjusted; | 231 --user_max_items_adjusted; |
| 228 if (!recently_closed_pages.empty()) | 232 if (!recently_closed_pages.empty()) |
| 229 --user_max_items_adjusted; | 233 --user_max_items_adjusted; |
| 230 | 234 |
| 231 size_t most_visited_items = | 235 size_t most_visited_items = |
| 232 MulDiv(user_max_items_adjusted, kMostVisited, kTotal); | 236 MulDiv(user_max_items_adjusted, kMostVisited, kTotal); |
| 233 size_t recently_closed_items = user_max_items_adjusted - most_visited_items; | 237 size_t recently_closed_items = user_max_items_adjusted - most_visited_items; |
| 234 if (recently_closed_pages.size() < recently_closed_items) { | 238 if (recently_closed_pages.size() < recently_closed_items) { |
| 235 most_visited_items += recently_closed_items - recently_closed_pages.size(); | 239 most_visited_items += recently_closed_items - recently_closed_pages.size(); |
| 236 recently_closed_items = recently_closed_pages.size(); | 240 recently_closed_items = recently_closed_pages.size(); |
| 237 } | 241 } |
| 238 | 242 |
| 239 // Delete the content in JumpListIcons folder and log the results to UMA. | 243 if (most_visited_pages_have_updates) { |
| 240 DeleteDirectoryContentAndLogResults(icon_dir, kFileDeleteLimit); | 244 // Delete the content in JumpListIconsMostVisited folder and log the results |
| 245 // to UMA. | |
| 246 base::FilePath icon_dir_most_visited = icon_dir.DirName().Append( | |
| 247 icon_dir.BaseName().value() + FILE_PATH_LITERAL("MostVisited")); | |
| 241 | 248 |
| 242 // If JumpListIcons directory doesn't exist (we have tried to create it | 249 DeleteDirectoryContentAndLogResults(icon_dir_most_visited, |
| 243 // already) or is not empty, skip updating the jumplist icons. The jumplist | 250 kFileDeleteLimit); |
| 244 // links should be updated anyway, as it doesn't involve disk IO. In this | |
| 245 // case, Chrome's icon will be used for the new links. | |
| 246 | 251 |
| 247 bool should_create_icons = | 252 // If the directory doesn't exist (we have tried to create it in |
| 248 base::DirectoryExists(icon_dir) && base::IsDirectoryEmpty(icon_dir); | 253 // DeleteDirectoryContentAndLogResults) or is not empty, skip updating the |
| 254 // jumplist icons. The jumplist links should be updated anyway, as it | |
| 255 // doesn't involve disk IO. In this case, Chrome's icon will be used for the | |
| 256 // new links. | |
| 257 if (base::DirectoryExists(icon_dir_most_visited) && | |
| 258 base::IsDirectoryEmpty(icon_dir_most_visited)) { | |
| 259 // Create icon files for shortcuts in the "Most Visited" category. | |
| 260 CreateIconFiles(icon_dir_most_visited, most_visited_pages, | |
| 261 most_visited_items); | |
| 262 } | |
| 263 } | |
| 249 | 264 |
| 250 // Create icon files for shortcuts in the "Most Visited" category. | 265 if (recently_closed_pages_have_updates) { |
| 251 if (should_create_icons) | 266 // Delete the content in JumpListIconsRecentClosed folder and log the |
| 252 CreateIconFiles(icon_dir, most_visited_pages, most_visited_items); | 267 // results to UMA. |
| 268 base::FilePath icon_dir_recent_closed = icon_dir.DirName().Append( | |
| 269 icon_dir.BaseName().value() + FILE_PATH_LITERAL("RecentClosed")); | |
| 270 | |
| 271 DeleteDirectoryContentAndLogResults(icon_dir_recent_closed, | |
| 272 kFileDeleteLimit); | |
| 273 | |
| 274 if (base::DirectoryExists(icon_dir_recent_closed) && | |
| 275 base::IsDirectoryEmpty(icon_dir_recent_closed)) { | |
| 276 // Create icon files for shortcuts in the "Recently Closed" category. | |
| 277 CreateIconFiles(icon_dir_recent_closed, recently_closed_pages, | |
| 278 recently_closed_items); | |
| 279 } | |
| 280 } | |
| 281 | |
| 282 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. | |
| 283 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplist.UpdateJumpListDuration"); | |
| 253 | 284 |
| 254 // Update the "Most Visited" category of the JumpList if it exists. | 285 // Update the "Most Visited" category of the JumpList if it exists. |
| 255 // This update request is applied into the JumpList when we commit this | 286 // This update request is applied into the JumpList when we commit this |
| 256 // transaction. | 287 // transaction. |
| 257 if (!jumplist_updater.AddCustomCategory( | 288 if (!jumplist_updater.AddCustomCategory( |
| 258 l10n_util::GetStringUTF16(IDS_NEW_TAB_MOST_VISITED), | 289 l10n_util::GetStringUTF16(IDS_NEW_TAB_MOST_VISITED), |
| 259 most_visited_pages, most_visited_items)) { | 290 most_visited_pages, most_visited_items)) { |
| 260 return; | 291 return false; |
| 261 } | 292 } |
| 262 | 293 |
| 263 // Create icon files for shortcuts in the "Recently Closed" category. | |
| 264 if (should_create_icons) | |
| 265 CreateIconFiles(icon_dir, recently_closed_pages, recently_closed_items); | |
| 266 | |
| 267 // Update the "Recently Closed" category of the JumpList. | 294 // Update the "Recently Closed" category of the JumpList. |
| 268 if (!jumplist_updater.AddCustomCategory( | 295 if (!jumplist_updater.AddCustomCategory( |
| 269 l10n_util::GetStringUTF16(IDS_RECENTLY_CLOSED), | 296 l10n_util::GetStringUTF16(IDS_RECENTLY_CLOSED), |
| 270 recently_closed_pages, recently_closed_items)) { | 297 recently_closed_pages, recently_closed_items)) { |
| 271 return; | 298 return false; |
| 272 } | 299 } |
| 273 | 300 |
| 274 // Update the "Tasks" category of the JumpList. | 301 // Update the "Tasks" category of the JumpList. |
| 275 if (!UpdateTaskCategory(&jumplist_updater, incognito_availability)) | 302 if (!UpdateTaskCategory(&jumplist_updater, incognito_availability)) |
| 276 return; | 303 return false; |
| 277 | 304 |
| 278 // Commit this transaction and send the updated JumpList to Windows. | 305 // Commit this transaction and send the updated JumpList to Windows. |
| 279 jumplist_updater.CommitUpdate(); | 306 if (!jumplist_updater.CommitUpdate()) { |
|
grt (UTC plus 2)
2017/04/27 09:05:25
nit:
return jumplist_updater.CommitUpdate();
chengx
2017/04/27 17:21:11
Done.
| |
| 307 return false; | |
| 308 } | |
| 309 | |
| 310 return true; | |
| 280 } | 311 } |
| 281 | 312 |
| 282 // Updates the jumplist, once all the data has been fetched. | 313 // Updates the jumplist, once all the data has been fetched. |
| 283 void RunUpdateJumpList(IncognitoModePrefs::Availability incognito_availability, | 314 void RunUpdateJumpList(IncognitoModePrefs::Availability incognito_availability, |
| 284 const std::wstring& app_id, | 315 const std::wstring& app_id, |
| 285 const base::FilePath& icon_dir, | 316 const base::FilePath& icon_dir, |
| 286 base::RefCountedData<JumpListData>* ref_counted_data) { | 317 base::RefCountedData<JumpListData>* ref_counted_data) { |
| 287 JumpListData* data = &ref_counted_data->data; | 318 JumpListData* data = &ref_counted_data->data; |
| 288 ShellLinkItemList local_most_visited_pages; | 319 ShellLinkItemList local_most_visited_pages; |
| 289 ShellLinkItemList local_recently_closed_pages; | 320 ShellLinkItemList local_recently_closed_pages; |
| 321 bool most_visited_pages_have_updates; | |
| 322 bool recently_closed_pages_have_updates; | |
| 290 | 323 |
| 291 { | 324 { |
| 292 base::AutoLock auto_lock(data->list_lock_); | 325 base::AutoLock auto_lock(data->list_lock_); |
| 293 // Make sure we are not out of date: if icon_urls_ is not empty, then | 326 // Make sure we are not out of date: if icon_urls_ is not empty, then |
| 294 // another notification has been received since we processed this one | 327 // another notification has been received since we processed this one |
| 295 if (!data->icon_urls_.empty()) | 328 if (!data->icon_urls_.empty()) |
| 296 return; | 329 return; |
| 297 | 330 |
| 298 // Make local copies of lists so we can release the lock. | 331 // Make local copies of lists and flags so we can release the lock. |
| 299 local_most_visited_pages = data->most_visited_pages_; | 332 local_most_visited_pages = data->most_visited_pages_; |
| 300 local_recently_closed_pages = data->recently_closed_pages_; | 333 local_recently_closed_pages = data->recently_closed_pages_; |
| 334 | |
| 335 most_visited_pages_have_updates = data->most_visited_pages_have_updates_; | |
| 336 recently_closed_pages_have_updates = | |
| 337 data->recently_closed_pages_have_updates_; | |
| 338 | |
| 339 // Clear the flags to reflect that we'll take actions on these updates. | |
| 340 data->most_visited_pages_have_updates_ = false; | |
| 341 data->recently_closed_pages_have_updates_ = false; | |
| 301 } | 342 } |
| 302 | 343 |
| 303 // Updates the application JumpList. | 344 if (!most_visited_pages_have_updates && !recently_closed_pages_have_updates) |
| 304 UpdateJumpList(app_id.c_str(), icon_dir, local_most_visited_pages, | 345 return; |
| 305 local_recently_closed_pages, incognito_availability); | 346 |
| 347 // Updates the application JumpList. If it fails, reset the flags to true if | |
| 348 // they were so that the corresponding JumpList categories will be tried to | |
| 349 // update again in the next run. | |
| 350 if (!UpdateJumpList( | |
| 351 app_id.c_str(), icon_dir, local_most_visited_pages, | |
| 352 local_recently_closed_pages, most_visited_pages_have_updates, | |
| 353 recently_closed_pages_have_updates, incognito_availability)) { | |
| 354 base::AutoLock auto_lock(data->list_lock_); | |
| 355 if (most_visited_pages_have_updates) | |
| 356 data->most_visited_pages_have_updates_ = true; | |
| 357 if (recently_closed_pages_have_updates) | |
| 358 data->recently_closed_pages_have_updates_ = true; | |
| 359 } | |
| 306 } | 360 } |
| 307 | 361 |
| 308 } // namespace | 362 } // namespace |
| 309 | 363 |
| 310 JumpList::JumpListData::JumpListData() {} | 364 JumpList::JumpListData::JumpListData() |
| 365 : most_visited_pages_have_updates_(true), | |
|
grt (UTC plus 2)
2017/04/27 09:05:24
nit: prefer member initialization in the class def
chengx
2017/04/27 17:21:11
Done. Now both of them are set to false by fault.
| |
| 366 recently_closed_pages_have_updates_(false) {} | |
| 311 | 367 |
| 312 JumpList::JumpListData::~JumpListData() {} | 368 JumpList::JumpListData::~JumpListData() {} |
| 313 | 369 |
| 314 JumpList::JumpList(Profile* profile) | 370 JumpList::JumpList(Profile* profile) |
| 315 : RefcountedKeyedService(content::BrowserThread::GetTaskRunnerForThread( | 371 : RefcountedKeyedService(content::BrowserThread::GetTaskRunnerForThread( |
| 316 content::BrowserThread::UI)), | 372 content::BrowserThread::UI)), |
| 317 profile_(profile), | 373 profile_(profile), |
| 318 jumplist_data_(new base::RefCountedData<JumpListData>), | 374 jumplist_data_(new base::RefCountedData<JumpListData>), |
| 319 task_id_(base::CancelableTaskTracker::kBadTaskId), | 375 task_id_(base::CancelableTaskTracker::kBadTaskId), |
| 320 update_jumplisticons_task_runner_(base::CreateCOMSTATaskRunnerWithTraits( | 376 update_jumplist_task_runner_(base::CreateCOMSTATaskRunnerWithTraits( |
| 321 base::TaskTraits() | 377 base::TaskTraits() |
| 322 .WithPriority(base::TaskPriority::USER_VISIBLE) | 378 .WithPriority(base::TaskPriority::USER_VISIBLE) |
| 323 .WithShutdownBehavior( | 379 .WithShutdownBehavior( |
| 324 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) | 380 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) |
| 325 .MayBlock())), | 381 .MayBlock())), |
| 326 delete_jumplisticonsold_task_runner_( | 382 delete_jumplisticons_task_runner_( |
| 327 base::CreateSequencedTaskRunnerWithTraits( | 383 base::CreateSequencedTaskRunnerWithTraits( |
| 328 base::TaskTraits() | 384 base::TaskTraits() |
| 329 .WithPriority(base::TaskPriority::BACKGROUND) | 385 .WithPriority(base::TaskPriority::BACKGROUND) |
| 330 .WithShutdownBehavior( | 386 .WithShutdownBehavior( |
| 331 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) | 387 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) |
| 332 .MayBlock())), | 388 .MayBlock())), |
| 333 weak_ptr_factory_(this) { | 389 weak_ptr_factory_(this) { |
| 334 DCHECK(Enabled()); | 390 DCHECK(Enabled()); |
| 335 // To update JumpList when a tab is added or removed, we add this object to | 391 // To update JumpList when a tab is added or removed, we add this object to |
| 336 // the observer list of the TabRestoreService class. | 392 // the observer list of the TabRestoreService class. |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 418 for (size_t i = 0; i < urls.size(); i++) { | 474 for (size_t i = 0; i < urls.size(); i++) { |
| 419 const history::MostVisitedURL& url = urls[i]; | 475 const history::MostVisitedURL& url = urls[i]; |
| 420 scoped_refptr<ShellLinkItem> link = CreateShellLink(); | 476 scoped_refptr<ShellLinkItem> link = CreateShellLink(); |
| 421 std::string url_string = url.url.spec(); | 477 std::string url_string = url.url.spec(); |
| 422 std::wstring url_string_wide = base::UTF8ToWide(url_string); | 478 std::wstring url_string_wide = base::UTF8ToWide(url_string); |
| 423 link->GetCommandLine()->AppendArgNative(url_string_wide); | 479 link->GetCommandLine()->AppendArgNative(url_string_wide); |
| 424 link->GetCommandLine()->AppendSwitchASCII( | 480 link->GetCommandLine()->AppendSwitchASCII( |
| 425 switches::kWinJumplistAction, jumplist::kMostVisitedCategory); | 481 switches::kWinJumplistAction, jumplist::kMostVisitedCategory); |
| 426 link->set_title(!url.title.empty() ? url.title : url_string_wide); | 482 link->set_title(!url.title.empty() ? url.title : url_string_wide); |
| 427 data->most_visited_pages_.push_back(link); | 483 data->most_visited_pages_.push_back(link); |
| 428 data->icon_urls_.push_back(make_pair(url_string, link)); | 484 data->icon_urls_.push_back(std::make_pair(url_string, link)); |
| 429 } | 485 } |
| 486 data->most_visited_pages_have_updates_ = true; | |
| 430 } | 487 } |
| 431 | 488 |
| 432 // Send a query that retrieves the first favicon. | 489 // Send a query that retrieves the first favicon. |
| 433 StartLoadingFavicon(); | 490 StartLoadingFavicon(); |
| 434 } | 491 } |
| 435 | 492 |
| 436 void JumpList::TabRestoreServiceChanged(sessions::TabRestoreService* service) { | 493 void JumpList::TabRestoreServiceChanged(sessions::TabRestoreService* service) { |
| 437 DCHECK(CalledOnValidThread()); | 494 DCHECK(CalledOnValidThread()); |
| 438 // if we have a pending handle request, cancel it here (it is out of date). | 495 // if we have a pending favicon request, cancel it here (it is out of date). |
| 439 CancelPendingUpdate(); | 496 CancelPendingUpdate(); |
| 440 | 497 |
| 441 // local list to pass to methods | |
| 442 ShellLinkItemList temp_list; | |
| 443 | |
| 444 // Create a list of ShellLinkItems from the "Recently Closed" pages. | 498 // Create a list of ShellLinkItems from the "Recently Closed" pages. |
| 445 // As noted above, we create a ShellLinkItem objects with the following | 499 // As noted above, we create a ShellLinkItem objects with the following |
| 446 // parameters. | 500 // parameters. |
| 447 // * arguments | 501 // * arguments |
| 448 // The last URL of the tab object. | 502 // The last URL of the tab object. |
| 449 // * title | 503 // * title |
| 450 // The title of the last URL. | 504 // The title of the last URL. |
| 451 // * icon | 505 // * icon |
| 452 // An empty string. This value is to be updated in OnFaviconDataAvailable(). | 506 // An empty string. This value is to be updated in OnFaviconDataAvailable(). |
| 453 // This code is copied from | 507 // This code is copied from |
| 454 // RecentlyClosedTabsHandler::TabRestoreServiceChanged() to emulate it. | 508 // RecentlyClosedTabsHandler::TabRestoreServiceChanged() to emulate it. |
| 455 const int kRecentlyClosedCount = 3; | 509 const int kRecentlyClosedCount = 3; |
| 456 sessions::TabRestoreService* tab_restore_service = | 510 sessions::TabRestoreService* tab_restore_service = |
| 457 TabRestoreServiceFactory::GetForProfile(profile_); | 511 TabRestoreServiceFactory::GetForProfile(profile_); |
| 458 for (const auto& entry : tab_restore_service->entries()) { | 512 |
| 459 switch (entry->type) { | |
| 460 case sessions::TabRestoreService::TAB: | |
| 461 AddTab(static_cast<const sessions::TabRestoreService::Tab&>(*entry), | |
| 462 &temp_list, kRecentlyClosedCount); | |
| 463 break; | |
| 464 case sessions::TabRestoreService::WINDOW: | |
| 465 AddWindow( | |
| 466 static_cast<const sessions::TabRestoreService::Window&>(*entry), | |
| 467 &temp_list, kRecentlyClosedCount); | |
| 468 break; | |
| 469 } | |
| 470 } | |
| 471 // Lock recently_closed_pages and copy temp_list into it. | |
| 472 { | 513 { |
| 473 JumpListData* data = &jumplist_data_->data; | 514 JumpListData* data = &jumplist_data_->data; |
| 474 base::AutoLock auto_lock(data->list_lock_); | 515 base::AutoLock auto_lock(data->list_lock_); |
| 475 data->recently_closed_pages_ = temp_list; | 516 data->recently_closed_pages_.clear(); |
| 517 | |
| 518 for (const auto& entry : tab_restore_service->entries()) { | |
| 519 switch (entry->type) { | |
| 520 case sessions::TabRestoreService::TAB: | |
| 521 AddTab(static_cast<const sessions::TabRestoreService::Tab&>(*entry), | |
| 522 data, kRecentlyClosedCount); | |
| 523 break; | |
| 524 case sessions::TabRestoreService::WINDOW: | |
| 525 AddWindow( | |
| 526 static_cast<const sessions::TabRestoreService::Window&>(*entry), | |
| 527 data, kRecentlyClosedCount); | |
| 528 break; | |
| 529 } | |
| 530 } | |
| 531 | |
| 532 data->recently_closed_pages_have_updates_ = true; | |
| 476 } | 533 } |
| 477 | 534 |
| 478 // Send a query that retrieves the first favicon. | 535 // Send a query that retrieves the first favicon. |
| 479 StartLoadingFavicon(); | 536 StartLoadingFavicon(); |
| 480 } | 537 } |
| 481 | 538 |
| 482 void JumpList::TabRestoreServiceDestroyed( | 539 void JumpList::TabRestoreServiceDestroyed( |
| 483 sessions::TabRestoreService* service) {} | 540 sessions::TabRestoreService* service) {} |
| 484 | 541 |
| 485 bool JumpList::AddTab(const sessions::TabRestoreService::Tab& tab, | 542 bool JumpList::AddTab(const sessions::TabRestoreService::Tab& tab, |
| 486 ShellLinkItemList* list, | 543 JumpListData* data, |
| 487 size_t max_items) { | 544 size_t max_items) { |
| 488 DCHECK(CalledOnValidThread()); | 545 DCHECK(CalledOnValidThread()); |
| 489 | 546 |
|
grt (UTC plus 2)
2017/04/27 09:05:24
nit: omit blank line so that asserts are grouped t
chengx
2017/04/27 17:21:11
Done.
| |
| 490 // This code adds the URL and the title strings of the given tab to the | 547 data->list_lock_.AssertAcquired(); |
| 491 // specified list. | 548 |
| 492 if (list->size() >= max_items) | 549 // This code adds the URL and the title strings of the given tab to |data|. |
| 550 if (data->recently_closed_pages_.size() >= max_items) | |
| 493 return false; | 551 return false; |
| 494 | 552 |
| 495 scoped_refptr<ShellLinkItem> link = CreateShellLink(); | 553 scoped_refptr<ShellLinkItem> link = CreateShellLink(); |
| 496 const sessions::SerializedNavigationEntry& current_navigation = | 554 const sessions::SerializedNavigationEntry& current_navigation = |
| 497 tab.navigations.at(tab.current_navigation_index); | 555 tab.navigations.at(tab.current_navigation_index); |
| 498 std::string url = current_navigation.virtual_url().spec(); | 556 std::string url = current_navigation.virtual_url().spec(); |
| 499 link->GetCommandLine()->AppendArgNative(base::UTF8ToWide(url)); | 557 link->GetCommandLine()->AppendArgNative(base::UTF8ToWide(url)); |
| 500 link->GetCommandLine()->AppendSwitchASCII( | 558 link->GetCommandLine()->AppendSwitchASCII(switches::kWinJumplistAction, |
| 501 switches::kWinJumplistAction, jumplist::kRecentlyClosedCategory); | 559 jumplist::kRecentlyClosedCategory); |
| 502 link->set_title(current_navigation.title()); | 560 link->set_title(current_navigation.title()); |
| 503 list->push_back(link); | 561 data->recently_closed_pages_.push_back(link); |
| 504 { | 562 data->icon_urls_.push_back(std::make_pair(std::move(url), std::move(link))); |
| 505 JumpListData* data = &jumplist_data_->data; | 563 |
| 506 base::AutoLock auto_lock(data->list_lock_); | |
| 507 data->icon_urls_.push_back(std::make_pair(std::move(url), std::move(link))); | |
| 508 } | |
| 509 return true; | 564 return true; |
| 510 } | 565 } |
| 511 | 566 |
| 512 void JumpList::AddWindow(const sessions::TabRestoreService::Window& window, | 567 void JumpList::AddWindow(const sessions::TabRestoreService::Window& window, |
| 513 ShellLinkItemList* list, | 568 JumpListData* data, |
| 514 size_t max_items) { | 569 size_t max_items) { |
| 515 DCHECK(CalledOnValidThread()); | 570 DCHECK(CalledOnValidThread()); |
| 516 | 571 |
| 517 // This code enumerates al the tabs in the given window object and add their | 572 data->list_lock_.AssertAcquired(); |
| 518 // URLs and titles to the list. | 573 |
| 574 // This code enumerates all the tabs in the given window object and add their | |
| 575 // URLs and titles to |data|. | |
| 519 DCHECK(!window.tabs.empty()); | 576 DCHECK(!window.tabs.empty()); |
| 520 | 577 |
| 521 for (const auto& tab : window.tabs) { | 578 for (const auto& tab : window.tabs) { |
| 522 if (!AddTab(*tab, list, max_items)) | 579 if (!AddTab(*tab, data, max_items)) |
| 523 return; | 580 return; |
| 524 } | 581 } |
| 525 } | 582 } |
| 526 | 583 |
| 527 void JumpList::StartLoadingFavicon() { | 584 void JumpList::StartLoadingFavicon() { |
| 528 DCHECK(CalledOnValidThread()); | 585 DCHECK(CalledOnValidThread()); |
| 529 | 586 |
| 530 GURL url; | 587 GURL url; |
| 531 bool waiting_for_icons = true; | 588 bool waiting_for_icons = true; |
| 532 { | 589 { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 587 | 644 |
| 588 void JumpList::OnIncognitoAvailabilityChanged() { | 645 void JumpList::OnIncognitoAvailabilityChanged() { |
| 589 DCHECK(CalledOnValidThread()); | 646 DCHECK(CalledOnValidThread()); |
| 590 | 647 |
| 591 bool waiting_for_icons = true; | 648 bool waiting_for_icons = true; |
| 592 { | 649 { |
| 593 JumpListData* data = &jumplist_data_->data; | 650 JumpListData* data = &jumplist_data_->data; |
| 594 base::AutoLock auto_lock(data->list_lock_); | 651 base::AutoLock auto_lock(data->list_lock_); |
| 595 waiting_for_icons = !data->icon_urls_.empty(); | 652 waiting_for_icons = !data->icon_urls_.empty(); |
| 596 } | 653 } |
| 597 if (!waiting_for_icons) | 654 |
| 655 // Since neither the "Most Visited" category nor the "Recently Closed" | |
| 656 // category changes, mark the flags so that icon files for those categories | |
| 657 // won't be updated later on. | |
| 658 if (!waiting_for_icons) { | |
|
grt (UTC plus 2)
2017/04/27 09:05:25
nit: omit braces
chengx
2017/04/27 17:21:11
Done.
| |
| 598 PostRunUpdate(); | 659 PostRunUpdate(); |
| 599 // If |icon_urls_| isn't empty then OnFaviconDataAvailable will eventually | 660 } |
| 600 // call PostRunUpdate(). | |
| 601 } | 661 } |
| 602 | 662 |
| 603 void JumpList::PostRunUpdate() { | 663 void JumpList::PostRunUpdate() { |
| 604 DCHECK(CalledOnValidThread()); | 664 DCHECK(CalledOnValidThread()); |
| 605 | 665 |
| 606 TRACE_EVENT0("browser", "JumpList::PostRunUpdate"); | 666 TRACE_EVENT0("browser", "JumpList::PostRunUpdate"); |
| 607 // Initialize the one-shot timer to update the jumplists in a while. | 667 // Initialize the one-shot timer to update the jumplists in a while. |
| 608 // If there is already a request queued then cancel it and post the new | 668 // If there is already a request queued then cancel it and post the new |
| 609 // request. This ensures that JumpListUpdates won't happen until there has | 669 // request. This ensures that JumpListUpdates won't happen until there has |
| 610 // been a brief quiet period, thus avoiding update storms. | 670 // been a brief quiet period, thus avoiding update storms. |
| 611 if (timer_.IsRunning()) { | 671 if (timer_.IsRunning()) { |
| 612 timer_.Reset(); | 672 timer_.Reset(); |
| 613 } else { | 673 } else { |
| 614 timer_.Start(FROM_HERE, kDelayForJumplistUpdate, this, | 674 timer_.Start(FROM_HERE, kDelayForJumplistUpdate, this, |
| 615 &JumpList::DeferredRunUpdate); | 675 &JumpList::DeferredRunUpdate); |
| 616 } | 676 } |
| 617 } | 677 } |
| 618 | 678 |
| 619 void JumpList::DeferredRunUpdate() { | 679 void JumpList::DeferredRunUpdate() { |
| 620 DCHECK(CalledOnValidThread()); | 680 DCHECK(CalledOnValidThread()); |
| 621 | 681 |
| 622 TRACE_EVENT0("browser", "JumpList::DeferredRunUpdate"); | 682 TRACE_EVENT0("browser", "JumpList::DeferredRunUpdate"); |
| 623 // Check if incognito windows (or normal windows) are disabled by policy. | 683 // Check if incognito windows (or normal windows) are disabled by policy. |
| 624 IncognitoModePrefs::Availability incognito_availability = | 684 IncognitoModePrefs::Availability incognito_availability = |
| 625 profile_ ? IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) | 685 profile_ ? IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) |
| 626 : IncognitoModePrefs::ENABLED; | 686 : IncognitoModePrefs::ENABLED; |
| 627 | 687 |
| 628 // Post a task to update the jumplist in JumpListIcons folder, which consists | 688 // Post a task to update the JumpList, which consists of 1) delete old icons, |
| 629 // of 1) delete old icons, 2) create new icons, 3) notify the OS. | 689 // 2) create new icons, 3) notify the OS. |
| 630 update_jumplisticons_task_runner_->PostTask( | 690 update_jumplist_task_runner_->PostTask( |
| 631 FROM_HERE, base::Bind(&RunUpdateJumpList, incognito_availability, app_id_, | 691 FROM_HERE, base::Bind(&RunUpdateJumpList, incognito_availability, app_id_, |
| 632 icon_dir_, base::RetainedRef(jumplist_data_))); | 692 icon_dir_, base::RetainedRef(jumplist_data_))); |
| 633 | 693 |
| 634 // Post a task to delete JumpListIconsOld folder and log the results to UMA. | 694 // Post a task to delete JumpListIcons folder as it't no longer needed. |
|
grt (UTC plus 2)
2017/04/27 09:05:24
it't -> it's
chengx
2017/04/27 17:21:11
Done.
| |
| 695 // Now we have JumpListIconsMostVisited folder and JumpListIconsRecentClosed | |
| 696 // folder instead. | |
| 697 delete_jumplisticons_task_runner_->PostTask( | |
| 698 FROM_HERE, | |
| 699 base::Bind(&DeleteDirectoryAndLogResults, icon_dir_, kFileDeleteLimit)); | |
| 700 | |
| 701 // Post a task to delete JumpListIconsOld folder as it't no longer needed. | |
| 635 base::FilePath icon_dir_old = icon_dir_.DirName().Append( | 702 base::FilePath icon_dir_old = icon_dir_.DirName().Append( |
| 636 icon_dir_.BaseName().value() + FILE_PATH_LITERAL("Old")); | 703 icon_dir_.BaseName().value() + FILE_PATH_LITERAL("Old")); |
| 637 | 704 |
| 638 delete_jumplisticonsold_task_runner_->PostTask( | 705 delete_jumplisticons_task_runner_->PostTask( |
| 639 FROM_HERE, base::Bind(&DeleteDirectoryAndLogResults, | 706 FROM_HERE, base::Bind(&DeleteDirectoryAndLogResults, |
| 640 std::move(icon_dir_old), kFileDeleteLimit)); | 707 std::move(icon_dir_old), kFileDeleteLimit)); |
| 641 } | 708 } |
| 642 | 709 |
| 643 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { | 710 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { |
| 644 } | 711 } |
| 645 | 712 |
| 646 void JumpList::TopSitesChanged(history::TopSites* top_sites, | 713 void JumpList::TopSitesChanged(history::TopSites* top_sites, |
| 647 ChangeReason change_reason) { | 714 ChangeReason change_reason) { |
| 648 top_sites->GetMostVisitedURLs( | 715 top_sites->GetMostVisitedURLs( |
| 649 base::Bind(&JumpList::OnMostVisitedURLsAvailable, | 716 base::Bind(&JumpList::OnMostVisitedURLsAvailable, |
| 650 weak_ptr_factory_.GetWeakPtr()), | 717 weak_ptr_factory_.GetWeakPtr()), |
| 651 false); | 718 false); |
| 652 } | 719 } |
| OLD | NEW |