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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 void 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 should_update_most_visited, | |
| 195 bool should_update_recent_closed, | |
| 194 IncognitoModePrefs::Availability incognito_availability) { | 196 IncognitoModePrefs::Availability incognito_availability) { |
| 195 if (!JumpListUpdater::IsEnabled()) | 197 if (!JumpListUpdater::IsEnabled()) |
| 196 return; | 198 return; |
| 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; |
| 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; |
| 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 (should_update_most_visited) { |
| 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 (should_update_recent_closed) { |
| 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; |
| 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; |
| 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; |
| 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 jumplist_updater.CommitUpdate(); |
| 280 } | 307 } |
| 281 | 308 |
| 282 // Updates the jumplist, once all the data has been fetched. | 309 // Updates the jumplist, once all the data has been fetched. |
| 283 void RunUpdateJumpList(IncognitoModePrefs::Availability incognito_availability, | 310 void RunUpdateJumpList(IncognitoModePrefs::Availability incognito_availability, |
| 284 const std::wstring& app_id, | 311 const std::wstring& app_id, |
| 285 const base::FilePath& icon_dir, | 312 const base::FilePath& icon_dir, |
| 313 bool should_update_most_visited, | |
| 314 bool should_update_recent_closed, | |
| 286 base::RefCountedData<JumpListData>* ref_counted_data) { | 315 base::RefCountedData<JumpListData>* ref_counted_data) { |
| 287 JumpListData* data = &ref_counted_data->data; | 316 JumpListData* data = &ref_counted_data->data; |
| 288 ShellLinkItemList local_most_visited_pages; | 317 ShellLinkItemList local_most_visited_pages; |
| 289 ShellLinkItemList local_recently_closed_pages; | 318 ShellLinkItemList local_recently_closed_pages; |
| 290 | 319 |
| 291 { | 320 { |
| 292 base::AutoLock auto_lock(data->list_lock_); | 321 base::AutoLock auto_lock(data->list_lock_); |
| 293 // Make sure we are not out of date: if icon_urls_ is not empty, then | 322 // 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 | 323 // another notification has been received since we processed this one |
| 295 if (!data->icon_urls_.empty()) | 324 if (!data->icon_urls_.empty()) |
| 296 return; | 325 return; |
| 297 | 326 |
| 298 // Make local copies of lists so we can release the lock. | 327 // Make local copies of lists so we can release the lock. |
| 299 local_most_visited_pages = data->most_visited_pages_; | 328 local_most_visited_pages = data->most_visited_pages_; |
| 300 local_recently_closed_pages = data->recently_closed_pages_; | 329 local_recently_closed_pages = data->recently_closed_pages_; |
| 301 } | 330 } |
| 302 | 331 |
| 303 // Updates the application JumpList. | 332 // Updates the application JumpList. |
| 304 UpdateJumpList(app_id.c_str(), icon_dir, local_most_visited_pages, | 333 UpdateJumpList(app_id.c_str(), icon_dir, local_most_visited_pages, |
| 305 local_recently_closed_pages, incognito_availability); | 334 local_recently_closed_pages, should_update_most_visited, |
| 335 should_update_recent_closed, incognito_availability); | |
| 306 } | 336 } |
| 307 | 337 |
| 308 } // namespace | 338 } // namespace |
| 309 | 339 |
| 310 JumpList::JumpListData::JumpListData() {} | 340 JumpList::JumpListData::JumpListData() {} |
| 311 | 341 |
| 312 JumpList::JumpListData::~JumpListData() {} | 342 JumpList::JumpListData::~JumpListData() {} |
| 313 | 343 |
| 314 JumpList::JumpList(Profile* profile) | 344 JumpList::JumpList(Profile* profile) |
| 315 : RefcountedKeyedService(content::BrowserThread::GetTaskRunnerForThread( | 345 : RefcountedKeyedService(content::BrowserThread::GetTaskRunnerForThread( |
| 316 content::BrowserThread::UI)), | 346 content::BrowserThread::UI)), |
| 317 profile_(profile), | 347 profile_(profile), |
| 348 should_update_most_visited_(true), | |
| 349 should_update_recent_closed_(true), | |
| 318 jumplist_data_(new base::RefCountedData<JumpListData>), | 350 jumplist_data_(new base::RefCountedData<JumpListData>), |
| 319 task_id_(base::CancelableTaskTracker::kBadTaskId), | 351 task_id_(base::CancelableTaskTracker::kBadTaskId), |
| 320 update_jumplisticons_task_runner_(base::CreateCOMSTATaskRunnerWithTraits( | 352 update_jumplist_task_runner_(base::CreateCOMSTATaskRunnerWithTraits( |
| 321 base::TaskTraits() | 353 base::TaskTraits() |
| 322 .WithPriority(base::TaskPriority::USER_VISIBLE) | 354 .WithPriority(base::TaskPriority::USER_VISIBLE) |
| 323 .WithShutdownBehavior( | 355 .WithShutdownBehavior( |
| 324 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) | 356 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) |
| 325 .MayBlock())), | 357 .MayBlock())), |
| 326 delete_jumplisticonsold_task_runner_( | 358 delete_jumplisticons_task_runner_( |
| 327 base::CreateSequencedTaskRunnerWithTraits( | 359 base::CreateSequencedTaskRunnerWithTraits( |
| 328 base::TaskTraits() | 360 base::TaskTraits() |
| 329 .WithPriority(base::TaskPriority::BACKGROUND) | 361 .WithPriority(base::TaskPriority::BACKGROUND) |
| 330 .WithShutdownBehavior( | 362 .WithShutdownBehavior( |
| 331 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) | 363 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) |
| 332 .MayBlock())), | 364 .MayBlock())), |
| 333 weak_ptr_factory_(this) { | 365 weak_ptr_factory_(this) { |
| 334 DCHECK(Enabled()); | 366 DCHECK(Enabled()); |
| 335 // To update JumpList when a tab is added or removed, we add this object to | 367 // To update JumpList when a tab is added or removed, we add this object to |
| 336 // the observer list of the TabRestoreService class. | 368 // 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++) { | 450 for (size_t i = 0; i < urls.size(); i++) { |
| 419 const history::MostVisitedURL& url = urls[i]; | 451 const history::MostVisitedURL& url = urls[i]; |
| 420 scoped_refptr<ShellLinkItem> link = CreateShellLink(); | 452 scoped_refptr<ShellLinkItem> link = CreateShellLink(); |
| 421 std::string url_string = url.url.spec(); | 453 std::string url_string = url.url.spec(); |
| 422 std::wstring url_string_wide = base::UTF8ToWide(url_string); | 454 std::wstring url_string_wide = base::UTF8ToWide(url_string); |
| 423 link->GetCommandLine()->AppendArgNative(url_string_wide); | 455 link->GetCommandLine()->AppendArgNative(url_string_wide); |
| 424 link->GetCommandLine()->AppendSwitchASCII( | 456 link->GetCommandLine()->AppendSwitchASCII( |
| 425 switches::kWinJumplistAction, jumplist::kMostVisitedCategory); | 457 switches::kWinJumplistAction, jumplist::kMostVisitedCategory); |
| 426 link->set_title(!url.title.empty() ? url.title : url_string_wide); | 458 link->set_title(!url.title.empty() ? url.title : url_string_wide); |
| 427 data->most_visited_pages_.push_back(link); | 459 data->most_visited_pages_.push_back(link); |
| 428 data->icon_urls_.push_back(make_pair(url_string, link)); | 460 data->icon_urls_.push_back(std::make_pair(url_string, link)); |
| 429 } | 461 } |
| 430 } | 462 } |
| 431 | 463 |
| 464 // Since only the "Most Visited" category changes, mark the flags so that icon | |
| 465 // files only for this category are updated later on. | |
| 466 should_update_most_visited_ = true; | |
| 467 should_update_recent_closed_ = false; | |
| 468 | |
| 432 // Send a query that retrieves the first favicon. | 469 // Send a query that retrieves the first favicon. |
| 433 StartLoadingFavicon(); | 470 StartLoadingFavicon(); |
| 434 } | 471 } |
| 435 | 472 |
| 436 void JumpList::TabRestoreServiceChanged(sessions::TabRestoreService* service) { | 473 void JumpList::TabRestoreServiceChanged(sessions::TabRestoreService* service) { |
| 437 DCHECK(CalledOnValidThread()); | 474 DCHECK(CalledOnValidThread()); |
| 438 // if we have a pending handle request, cancel it here (it is out of date). | 475 // if we have a pending favicon request, cancel it here (it is out of date). |
| 439 CancelPendingUpdate(); | 476 CancelPendingUpdate(); |
| 440 | 477 |
| 441 // local list to pass to methods | |
| 442 ShellLinkItemList temp_list; | |
| 443 | |
| 444 // Create a list of ShellLinkItems from the "Recently Closed" pages. | 478 // Create a list of ShellLinkItems from the "Recently Closed" pages. |
| 445 // As noted above, we create a ShellLinkItem objects with the following | 479 // As noted above, we create a ShellLinkItem objects with the following |
| 446 // parameters. | 480 // parameters. |
| 447 // * arguments | 481 // * arguments |
| 448 // The last URL of the tab object. | 482 // The last URL of the tab object. |
| 449 // * title | 483 // * title |
| 450 // The title of the last URL. | 484 // The title of the last URL. |
| 451 // * icon | 485 // * icon |
| 452 // An empty string. This value is to be updated in OnFaviconDataAvailable(). | 486 // An empty string. This value is to be updated in OnFaviconDataAvailable(). |
| 453 // This code is copied from | 487 // This code is copied from |
| 454 // RecentlyClosedTabsHandler::TabRestoreServiceChanged() to emulate it. | 488 // RecentlyClosedTabsHandler::TabRestoreServiceChanged() to emulate it. |
| 455 const int kRecentlyClosedCount = 3; | 489 const int kRecentlyClosedCount = 3; |
| 456 sessions::TabRestoreService* tab_restore_service = | 490 sessions::TabRestoreService* tab_restore_service = |
| 457 TabRestoreServiceFactory::GetForProfile(profile_); | 491 TabRestoreServiceFactory::GetForProfile(profile_); |
| 458 for (const auto& entry : tab_restore_service->entries()) { | |
| 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 { | 492 { |
| 473 JumpListData* data = &jumplist_data_->data; | 493 JumpListData* data = &jumplist_data_->data; |
| 474 base::AutoLock auto_lock(data->list_lock_); | 494 base::AutoLock auto_lock(data->list_lock_); |
| 475 data->recently_closed_pages_ = temp_list; | 495 data->recently_closed_pages_.clear(); |
| 496 | |
| 497 for (const auto& entry : tab_restore_service->entries()) { | |
| 498 switch (entry->type) { | |
| 499 case sessions::TabRestoreService::TAB: | |
| 500 AddTab(static_cast<const sessions::TabRestoreService::Tab&>(*entry), | |
| 501 data, kRecentlyClosedCount); | |
| 502 break; | |
| 503 case sessions::TabRestoreService::WINDOW: | |
| 504 AddWindow( | |
| 505 static_cast<const sessions::TabRestoreService::Window&>(*entry), | |
| 506 data, kRecentlyClosedCount); | |
| 507 break; | |
| 508 } | |
| 509 } | |
| 476 } | 510 } |
| 477 | 511 |
| 512 // Since only the "Recently Closed" category changes, mark the flags so that | |
| 513 // icon files only for this category are updated later on. | |
| 514 should_update_most_visited_ = false; | |
|
grt (UTC plus 2)
2017/04/26 09:14:33
do i understand correctly that the point of these
chengx
2017/04/27 01:18:47
Awesome idea! I've updated the code accordingly. T
| |
| 515 should_update_recent_closed_ = true; | |
| 516 | |
| 478 // Send a query that retrieves the first favicon. | 517 // Send a query that retrieves the first favicon. |
| 479 StartLoadingFavicon(); | 518 StartLoadingFavicon(); |
| 480 } | 519 } |
| 481 | 520 |
| 482 void JumpList::TabRestoreServiceDestroyed( | 521 void JumpList::TabRestoreServiceDestroyed( |
| 483 sessions::TabRestoreService* service) {} | 522 sessions::TabRestoreService* service) {} |
| 484 | 523 |
| 485 bool JumpList::AddTab(const sessions::TabRestoreService::Tab& tab, | 524 bool JumpList::AddTab(const sessions::TabRestoreService::Tab& tab, |
| 486 ShellLinkItemList* list, | 525 JumpListData* data, |
| 487 size_t max_items) { | 526 size_t max_items) { |
| 488 DCHECK(CalledOnValidThread()); | 527 DCHECK(CalledOnValidThread()); |
| 489 | 528 |
|
grt (UTC plus 2)
2017/04/26 09:14:33
data->list_lock_.AssertAcquired();
chengx
2017/04/27 01:18:47
Done.
| |
| 490 // This code adds the URL and the title strings of the given tab to the | 529 // This code adds the URL and the title strings of the given tab to |data|. |
| 491 // specified list. | 530 if (data->recently_closed_pages_.size() >= max_items) |
| 492 if (list->size() >= max_items) | |
| 493 return false; | 531 return false; |
| 494 | 532 |
| 495 scoped_refptr<ShellLinkItem> link = CreateShellLink(); | 533 scoped_refptr<ShellLinkItem> link = CreateShellLink(); |
| 496 const sessions::SerializedNavigationEntry& current_navigation = | 534 const sessions::SerializedNavigationEntry& current_navigation = |
| 497 tab.navigations.at(tab.current_navigation_index); | 535 tab.navigations.at(tab.current_navigation_index); |
| 498 std::string url = current_navigation.virtual_url().spec(); | 536 std::string url = current_navigation.virtual_url().spec(); |
| 499 link->GetCommandLine()->AppendArgNative(base::UTF8ToWide(url)); | 537 link->GetCommandLine()->AppendArgNative(base::UTF8ToWide(url)); |
| 500 link->GetCommandLine()->AppendSwitchASCII( | 538 link->GetCommandLine()->AppendSwitchASCII(switches::kWinJumplistAction, |
| 501 switches::kWinJumplistAction, jumplist::kRecentlyClosedCategory); | 539 jumplist::kRecentlyClosedCategory); |
| 502 link->set_title(current_navigation.title()); | 540 link->set_title(current_navigation.title()); |
| 503 list->push_back(link); | 541 data->recently_closed_pages_.push_back(link); |
| 504 { | 542 data->icon_urls_.push_back(std::make_pair(std::move(url), std::move(link))); |
| 505 JumpListData* data = &jumplist_data_->data; | 543 |
| 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; | 544 return true; |
| 510 } | 545 } |
| 511 | 546 |
| 512 void JumpList::AddWindow(const sessions::TabRestoreService::Window& window, | 547 void JumpList::AddWindow(const sessions::TabRestoreService::Window& window, |
| 513 ShellLinkItemList* list, | 548 JumpListData* data, |
| 514 size_t max_items) { | 549 size_t max_items) { |
| 515 DCHECK(CalledOnValidThread()); | 550 DCHECK(CalledOnValidThread()); |
| 516 | 551 |
|
grt (UTC plus 2)
2017/04/26 09:14:33
data->list_lock_.AssertAcquired();
chengx
2017/04/27 01:18:47
Done.
| |
| 517 // This code enumerates al the tabs in the given window object and add their | 552 // This code enumerates all the tabs in the given window object and add their |
| 518 // URLs and titles to the list. | 553 // URLs and titles to |data|. |
| 519 DCHECK(!window.tabs.empty()); | 554 DCHECK(!window.tabs.empty()); |
| 520 | 555 |
| 521 for (const auto& tab : window.tabs) { | 556 for (const auto& tab : window.tabs) { |
| 522 if (!AddTab(*tab, list, max_items)) | 557 if (!AddTab(*tab, data, max_items)) |
| 523 return; | 558 return; |
| 524 } | 559 } |
| 525 } | 560 } |
| 526 | 561 |
| 527 void JumpList::StartLoadingFavicon() { | 562 void JumpList::StartLoadingFavicon() { |
| 528 DCHECK(CalledOnValidThread()); | 563 DCHECK(CalledOnValidThread()); |
| 529 | 564 |
| 530 GURL url; | 565 GURL url; |
| 531 bool waiting_for_icons = true; | 566 bool waiting_for_icons = true; |
| 532 { | 567 { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 587 | 622 |
| 588 void JumpList::OnIncognitoAvailabilityChanged() { | 623 void JumpList::OnIncognitoAvailabilityChanged() { |
| 589 DCHECK(CalledOnValidThread()); | 624 DCHECK(CalledOnValidThread()); |
| 590 | 625 |
| 591 bool waiting_for_icons = true; | 626 bool waiting_for_icons = true; |
| 592 { | 627 { |
| 593 JumpListData* data = &jumplist_data_->data; | 628 JumpListData* data = &jumplist_data_->data; |
| 594 base::AutoLock auto_lock(data->list_lock_); | 629 base::AutoLock auto_lock(data->list_lock_); |
| 595 waiting_for_icons = !data->icon_urls_.empty(); | 630 waiting_for_icons = !data->icon_urls_.empty(); |
| 596 } | 631 } |
| 597 if (!waiting_for_icons) | 632 |
| 633 // Since neither the "Most Visited" category nor the "Recently Closed" | |
| 634 // category changes, mark the flags so that icon files for those categories | |
| 635 // won't be updated later on. | |
| 636 if (!waiting_for_icons) { | |
| 637 should_update_most_visited_ = false; | |
| 638 should_update_recent_closed_ = false; | |
| 598 PostRunUpdate(); | 639 PostRunUpdate(); |
| 599 // If |icon_urls_| isn't empty then OnFaviconDataAvailable will eventually | 640 } |
| 600 // call PostRunUpdate(). | |
| 601 } | 641 } |
| 602 | 642 |
| 603 void JumpList::PostRunUpdate() { | 643 void JumpList::PostRunUpdate() { |
| 604 DCHECK(CalledOnValidThread()); | 644 DCHECK(CalledOnValidThread()); |
| 605 | 645 |
| 606 TRACE_EVENT0("browser", "JumpList::PostRunUpdate"); | 646 TRACE_EVENT0("browser", "JumpList::PostRunUpdate"); |
| 607 // Initialize the one-shot timer to update the jumplists in a while. | 647 // 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 | 648 // 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 | 649 // request. This ensures that JumpListUpdates won't happen until there has |
| 610 // been a brief quiet period, thus avoiding update storms. | 650 // been a brief quiet period, thus avoiding update storms. |
| 611 if (timer_.IsRunning()) { | 651 if (timer_.IsRunning()) { |
| 612 timer_.Reset(); | 652 timer_.Reset(); |
| 613 } else { | 653 } else { |
| 614 timer_.Start(FROM_HERE, kDelayForJumplistUpdate, this, | 654 timer_.Start(FROM_HERE, kDelayForJumplistUpdate, this, |
| 615 &JumpList::DeferredRunUpdate); | 655 &JumpList::DeferredRunUpdate); |
| 616 } | 656 } |
| 617 } | 657 } |
| 618 | 658 |
| 619 void JumpList::DeferredRunUpdate() { | 659 void JumpList::DeferredRunUpdate() { |
| 620 DCHECK(CalledOnValidThread()); | 660 DCHECK(CalledOnValidThread()); |
| 621 | 661 |
| 622 TRACE_EVENT0("browser", "JumpList::DeferredRunUpdate"); | 662 TRACE_EVENT0("browser", "JumpList::DeferredRunUpdate"); |
| 623 // Check if incognito windows (or normal windows) are disabled by policy. | 663 // Check if incognito windows (or normal windows) are disabled by policy. |
| 624 IncognitoModePrefs::Availability incognito_availability = | 664 IncognitoModePrefs::Availability incognito_availability = |
| 625 profile_ ? IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) | 665 profile_ ? IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) |
| 626 : IncognitoModePrefs::ENABLED; | 666 : IncognitoModePrefs::ENABLED; |
| 627 | 667 |
| 628 // Post a task to update the jumplist in JumpListIcons folder, which consists | 668 // 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. | 669 // 2) create new icons, 3) notify the OS. |
| 630 update_jumplisticons_task_runner_->PostTask( | 670 update_jumplist_task_runner_->PostTask( |
| 631 FROM_HERE, base::Bind(&RunUpdateJumpList, incognito_availability, app_id_, | 671 FROM_HERE, |
| 632 icon_dir_, base::RetainedRef(jumplist_data_))); | 672 base::Bind(&RunUpdateJumpList, incognito_availability, app_id_, icon_dir_, |
| 673 should_update_most_visited_, should_update_recent_closed_, | |
| 674 base::RetainedRef(jumplist_data_))); | |
| 633 | 675 |
| 634 // Post a task to delete JumpListIconsOld folder and log the results to UMA. | 676 // Post a task to delete JumpListIcons folder as it't no longer needed. |
| 677 // Now we have JumpListIconsMostVisited folder and JumpListIconsRecentClosed | |
| 678 // folder instead. | |
| 679 delete_jumplisticons_task_runner_->PostTask( | |
| 680 FROM_HERE, | |
| 681 base::Bind(&DeleteDirectoryAndLogResults, icon_dir_, kFileDeleteLimit)); | |
| 682 | |
| 683 // Post a task to delete JumpListIconsOld folder as it't no longer needed. | |
| 635 base::FilePath icon_dir_old = icon_dir_.DirName().Append( | 684 base::FilePath icon_dir_old = icon_dir_.DirName().Append( |
| 636 icon_dir_.BaseName().value() + FILE_PATH_LITERAL("Old")); | 685 icon_dir_.BaseName().value() + FILE_PATH_LITERAL("Old")); |
| 637 | 686 |
| 638 delete_jumplisticonsold_task_runner_->PostTask( | 687 delete_jumplisticons_task_runner_->PostTask( |
| 639 FROM_HERE, base::Bind(&DeleteDirectoryAndLogResults, | 688 FROM_HERE, base::Bind(&DeleteDirectoryAndLogResults, |
| 640 std::move(icon_dir_old), kFileDeleteLimit)); | 689 std::move(icon_dir_old), kFileDeleteLimit)); |
| 641 } | 690 } |
| 642 | 691 |
| 643 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { | 692 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { |
| 644 } | 693 } |
| 645 | 694 |
| 646 void JumpList::TopSitesChanged(history::TopSites* top_sites, | 695 void JumpList::TopSitesChanged(history::TopSites* top_sites, |
| 647 ChangeReason change_reason) { | 696 ChangeReason change_reason) { |
| 648 top_sites->GetMostVisitedURLs( | 697 top_sites->GetMostVisitedURLs( |
| 649 base::Bind(&JumpList::OnMostVisitedURLsAvailable, | 698 base::Bind(&JumpList::OnMostVisitedURLsAvailable, |
| 650 weak_ptr_factory_.GetWeakPtr()), | 699 weak_ptr_factory_.GetWeakPtr()), |
| 651 false); | 700 false); |
| 652 } | 701 } |
| OLD | NEW |