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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 bool UpdateJumpList(const wchar_t* app_id, | 190 bool UpdateJumpList(const wchar_t* app_id, |
191 const base::FilePath& icon_dir, | 191 const Profile* profile, |
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, | 194 bool most_visited_pages_have_updates, |
195 bool recently_closed_pages_have_updates, | 195 bool recently_closed_pages_have_updates, |
196 IncognitoModePrefs::Availability incognito_availability) { | 196 IncognitoModePrefs::Availability incognito_availability) { |
197 if (!JumpListUpdater::IsEnabled()) | 197 if (!JumpListUpdater::IsEnabled()) |
198 return true; | 198 return true; |
199 | 199 |
200 // Records the time cost of starting a JumpListUpdater. | 200 // Records the time cost of starting a JumpListUpdater. |
201 base::ElapsedTimer begin_update_timer; | 201 base::ElapsedTimer begin_update_timer; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
236 MulDiv(user_max_items_adjusted, kMostVisited, kTotal); | 236 MulDiv(user_max_items_adjusted, kMostVisited, kTotal); |
237 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; |
238 if (recently_closed_pages.size() < recently_closed_items) { | 238 if (recently_closed_pages.size() < recently_closed_items) { |
239 most_visited_items += recently_closed_items - recently_closed_pages.size(); | 239 most_visited_items += recently_closed_items - recently_closed_pages.size(); |
240 recently_closed_items = recently_closed_pages.size(); | 240 recently_closed_items = recently_closed_pages.size(); |
241 } | 241 } |
242 | 242 |
243 if (most_visited_pages_have_updates) { | 243 if (most_visited_pages_have_updates) { |
244 // Delete the content in JumpListIconsMostVisited folder and log the results | 244 // Delete the content in JumpListIconsMostVisited folder and log the results |
245 // to UMA. | 245 // to UMA. |
246 base::FilePath icon_dir_most_visited = icon_dir.DirName().Append( | 246 base::FilePath icon_dir_most_visited = profile->GetPath().Append( |
grt (UTC plus 2)
2017/05/01 09:22:56
a Profile* may only be used on the UI thread. you
chengx
2017/05/03 05:47:01
Done. I've updated to pass the profile path.
| |
247 icon_dir.BaseName().value() + FILE_PATH_LITERAL("MostVisited")); | 247 chrome::kJumpListIconDirname + FILE_PATH_LITERAL("MostVisited")); |
248 | 248 |
249 DeleteDirectoryContentAndLogResults(icon_dir_most_visited, | 249 DeleteDirectoryContentAndLogResults(icon_dir_most_visited, |
250 kFileDeleteLimit); | 250 kFileDeleteLimit); |
251 | 251 |
252 // If the directory doesn't exist (we have tried to create it in | 252 // If the directory doesn't exist (we have tried to create it in |
253 // DeleteDirectoryContentAndLogResults) or is not empty, skip updating the | 253 // DeleteDirectoryContentAndLogResults) or is not empty, skip updating the |
254 // jumplist icons. The jumplist links should be updated anyway, as it | 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 | 255 // doesn't involve disk IO. In this case, Chrome's icon will be used for the |
256 // new links. | 256 // new links. |
257 if (base::DirectoryExists(icon_dir_most_visited) && | 257 if (base::DirectoryExists(icon_dir_most_visited) && |
258 base::IsDirectoryEmpty(icon_dir_most_visited)) { | 258 base::IsDirectoryEmpty(icon_dir_most_visited)) { |
259 // Create icon files for shortcuts in the "Most Visited" category. | 259 // Create icon files for shortcuts in the "Most Visited" category. |
260 CreateIconFiles(icon_dir_most_visited, most_visited_pages, | 260 CreateIconFiles(icon_dir_most_visited, most_visited_pages, |
261 most_visited_items); | 261 most_visited_items); |
262 } | 262 } |
263 } | 263 } |
264 | 264 |
265 if (recently_closed_pages_have_updates) { | 265 if (recently_closed_pages_have_updates) { |
266 // Delete the content in JumpListIconsRecentClosed folder and log the | 266 // Delete the content in JumpListIconsRecentClosed folder and log the |
267 // results to UMA. | 267 // results to UMA. |
268 base::FilePath icon_dir_recent_closed = icon_dir.DirName().Append( | 268 base::FilePath icon_dir_recent_closed = profile->GetPath().Append( |
269 icon_dir.BaseName().value() + FILE_PATH_LITERAL("RecentClosed")); | 269 chrome::kJumpListIconDirname + FILE_PATH_LITERAL("RecentClosed")); |
270 | 270 |
271 DeleteDirectoryContentAndLogResults(icon_dir_recent_closed, | 271 DeleteDirectoryContentAndLogResults(icon_dir_recent_closed, |
272 kFileDeleteLimit); | 272 kFileDeleteLimit); |
273 | 273 |
274 if (base::DirectoryExists(icon_dir_recent_closed) && | 274 if (base::DirectoryExists(icon_dir_recent_closed) && |
275 base::IsDirectoryEmpty(icon_dir_recent_closed)) { | 275 base::IsDirectoryEmpty(icon_dir_recent_closed)) { |
276 // Create icon files for shortcuts in the "Recently Closed" category. | 276 // Create icon files for shortcuts in the "Recently Closed" category. |
277 CreateIconFiles(icon_dir_recent_closed, recently_closed_pages, | 277 CreateIconFiles(icon_dir_recent_closed, recently_closed_pages, |
278 recently_closed_items); | 278 recently_closed_items); |
279 } | 279 } |
(...skipping 22 matching lines...) Expand all Loading... | |
302 if (!UpdateTaskCategory(&jumplist_updater, incognito_availability)) | 302 if (!UpdateTaskCategory(&jumplist_updater, incognito_availability)) |
303 return false; | 303 return false; |
304 | 304 |
305 // Commit this transaction and send the updated JumpList to Windows. | 305 // Commit this transaction and send the updated JumpList to Windows. |
306 return jumplist_updater.CommitUpdate(); | 306 return jumplist_updater.CommitUpdate(); |
307 } | 307 } |
308 | 308 |
309 // Updates the jumplist, once all the data has been fetched. | 309 // Updates the jumplist, once all the data has been fetched. |
310 void RunUpdateJumpList(IncognitoModePrefs::Availability incognito_availability, | 310 void RunUpdateJumpList(IncognitoModePrefs::Availability incognito_availability, |
311 const std::wstring& app_id, | 311 const std::wstring& app_id, |
312 const base::FilePath& icon_dir, | 312 const Profile* profile, |
313 base::RefCountedData<JumpListData>* ref_counted_data) { | 313 base::RefCountedData<JumpListData>* ref_counted_data) { |
314 JumpListData* data = &ref_counted_data->data; | 314 JumpListData* data = &ref_counted_data->data; |
315 ShellLinkItemList local_most_visited_pages; | 315 ShellLinkItemList local_most_visited_pages; |
316 ShellLinkItemList local_recently_closed_pages; | 316 ShellLinkItemList local_recently_closed_pages; |
317 bool most_visited_pages_have_updates; | 317 bool most_visited_pages_have_updates; |
318 bool recently_closed_pages_have_updates; | 318 bool recently_closed_pages_have_updates; |
319 | 319 |
320 { | 320 { |
321 base::AutoLock auto_lock(data->list_lock_); | 321 base::AutoLock auto_lock(data->list_lock_); |
322 // 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 |
(...skipping 14 matching lines...) Expand all Loading... | |
337 data->recently_closed_pages_have_updates_ = false; | 337 data->recently_closed_pages_have_updates_ = false; |
338 } | 338 } |
339 | 339 |
340 if (!most_visited_pages_have_updates && !recently_closed_pages_have_updates) | 340 if (!most_visited_pages_have_updates && !recently_closed_pages_have_updates) |
341 return; | 341 return; |
342 | 342 |
343 // Updates the application JumpList. If it fails, reset the flags to true if | 343 // Updates the application JumpList. If it fails, reset the flags to true if |
344 // they were so that the corresponding JumpList categories will be tried to | 344 // they were so that the corresponding JumpList categories will be tried to |
345 // update again in the next run. | 345 // update again in the next run. |
346 if (!UpdateJumpList( | 346 if (!UpdateJumpList( |
347 app_id.c_str(), icon_dir, local_most_visited_pages, | 347 app_id.c_str(), profile, local_most_visited_pages, |
348 local_recently_closed_pages, most_visited_pages_have_updates, | 348 local_recently_closed_pages, most_visited_pages_have_updates, |
349 recently_closed_pages_have_updates, incognito_availability)) { | 349 recently_closed_pages_have_updates, incognito_availability)) { |
350 base::AutoLock auto_lock(data->list_lock_); | 350 base::AutoLock auto_lock(data->list_lock_); |
351 if (most_visited_pages_have_updates) | 351 if (most_visited_pages_have_updates) |
352 data->most_visited_pages_have_updates_ = true; | 352 data->most_visited_pages_have_updates_ = true; |
353 if (recently_closed_pages_have_updates) | 353 if (recently_closed_pages_have_updates) |
354 data->recently_closed_pages_have_updates_ = true; | 354 data->recently_closed_pages_have_updates_ = true; |
355 } | 355 } |
356 } | 356 } |
357 | 357 |
(...skipping 29 matching lines...) Expand all Loading... | |
387 // When we add this object to the observer list, we save the pointer to this | 387 // When we add this object to the observer list, we save the pointer to this |
388 // TabRestoreService object. This pointer is used when we remove this object | 388 // TabRestoreService object. This pointer is used when we remove this object |
389 // from the observer list. | 389 // from the observer list. |
390 sessions::TabRestoreService* tab_restore_service = | 390 sessions::TabRestoreService* tab_restore_service = |
391 TabRestoreServiceFactory::GetForProfile(profile_); | 391 TabRestoreServiceFactory::GetForProfile(profile_); |
392 if (!tab_restore_service) | 392 if (!tab_restore_service) |
393 return; | 393 return; |
394 | 394 |
395 app_id_ = | 395 app_id_ = |
396 shell_integration::win::GetChromiumModelIdForProfile(profile_->GetPath()); | 396 shell_integration::win::GetChromiumModelIdForProfile(profile_->GetPath()); |
397 icon_dir_ = profile_->GetPath().Append(chrome::kJumpListIconDirname); | |
398 | 397 |
399 scoped_refptr<history::TopSites> top_sites = | 398 scoped_refptr<history::TopSites> top_sites = |
400 TopSitesFactory::GetForProfile(profile_); | 399 TopSitesFactory::GetForProfile(profile_); |
401 if (top_sites) { | 400 if (top_sites) { |
402 // TopSites updates itself after a delay. This is especially noticable when | 401 // TopSites updates itself after a delay. This is especially noticable when |
403 // your profile is empty. Ask TopSites to update itself when jumplist is | 402 // your profile is empty. Ask TopSites to update itself when jumplist is |
404 // initialized. | 403 // initialized. |
405 top_sites->SyncWithHistory(); | 404 top_sites->SyncWithHistory(); |
406 // Register as TopSitesObserver so that we can update ourselves when the | 405 // Register as TopSitesObserver so that we can update ourselves when the |
407 // TopSites changes. | 406 // TopSites changes. |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
673 TRACE_EVENT0("browser", "JumpList::DeferredRunUpdate"); | 672 TRACE_EVENT0("browser", "JumpList::DeferredRunUpdate"); |
674 // Check if incognito windows (or normal windows) are disabled by policy. | 673 // Check if incognito windows (or normal windows) are disabled by policy. |
675 IncognitoModePrefs::Availability incognito_availability = | 674 IncognitoModePrefs::Availability incognito_availability = |
676 profile_ ? IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) | 675 profile_ ? IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) |
677 : IncognitoModePrefs::ENABLED; | 676 : IncognitoModePrefs::ENABLED; |
678 | 677 |
679 // Post a task to update the JumpList, which consists of 1) delete old icons, | 678 // Post a task to update the JumpList, which consists of 1) delete old icons, |
680 // 2) create new icons, 3) notify the OS. | 679 // 2) create new icons, 3) notify the OS. |
681 update_jumplist_task_runner_->PostTask( | 680 update_jumplist_task_runner_->PostTask( |
682 FROM_HERE, base::Bind(&RunUpdateJumpList, incognito_availability, app_id_, | 681 FROM_HERE, base::Bind(&RunUpdateJumpList, incognito_availability, app_id_, |
683 icon_dir_, base::RetainedRef(jumplist_data_))); | 682 profile_, base::RetainedRef(jumplist_data_))); |
684 | 683 |
685 // Post a task to delete JumpListIcons folder as it's no longer needed. | 684 // Post a task to delete JumpListIcons folder as it's no longer needed. |
686 // Now we have JumpListIconsMostVisited folder and JumpListIconsRecentClosed | 685 // Now we have JumpListIconsMostVisited folder and JumpListIconsRecentClosed |
687 // folder instead. | 686 // folder instead. |
687 base::FilePath icon_dir = | |
688 profile_->GetPath().Append(chrome::kJumpListIconDirname); | |
689 | |
688 delete_jumplisticons_task_runner_->PostTask( | 690 delete_jumplisticons_task_runner_->PostTask( |
689 FROM_HERE, | 691 FROM_HERE, |
690 base::Bind(&DeleteDirectoryAndLogResults, icon_dir_, kFileDeleteLimit)); | 692 base::Bind(&DeleteDirectoryAndLogResults, icon_dir, kFileDeleteLimit)); |
691 | 693 |
692 // Post a task to delete JumpListIconsOld folder as it's no longer needed. | 694 // Post a task to delete JumpListIconsOld folder as it's no longer needed. |
693 base::FilePath icon_dir_old = icon_dir_.DirName().Append( | 695 base::FilePath icon_dir_old = profile_->GetPath().Append( |
694 icon_dir_.BaseName().value() + FILE_PATH_LITERAL("Old")); | 696 chrome::kJumpListIconDirname + FILE_PATH_LITERAL("Old")); |
695 | 697 |
696 delete_jumplisticons_task_runner_->PostTask( | 698 delete_jumplisticons_task_runner_->PostTask( |
697 FROM_HERE, base::Bind(&DeleteDirectoryAndLogResults, | 699 FROM_HERE, base::Bind(&DeleteDirectoryAndLogResults, |
698 std::move(icon_dir_old), kFileDeleteLimit)); | 700 std::move(icon_dir_old), kFileDeleteLimit)); |
699 } | 701 } |
700 | 702 |
701 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { | 703 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { |
702 } | 704 } |
703 | 705 |
704 void JumpList::TopSitesChanged(history::TopSites* top_sites, | 706 void JumpList::TopSitesChanged(history::TopSites* top_sites, |
705 ChangeReason change_reason) { | 707 ChangeReason change_reason) { |
706 top_sites->GetMostVisitedURLs( | 708 top_sites->GetMostVisitedURLs( |
707 base::Bind(&JumpList::OnMostVisitedURLsAvailable, | 709 base::Bind(&JumpList::OnMostVisitedURLsAvailable, |
708 weak_ptr_factory_.GetWeakPtr()), | 710 weak_ptr_factory_.GetWeakPtr()), |
709 false); | 711 false); |
710 } | 712 } |
OLD | NEW |