OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/win/jumplist.h" | 5 #include "chrome/browser/win/jumplist.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
| 16 #include "base/sequenced_task_runner.h" |
16 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
17 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
18 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
19 #include "base/task_scheduler/post_task.h" | 20 #include "base/task_scheduler/post_task.h" |
20 #include "base/threading/thread.h" | 21 #include "base/threading/thread.h" |
21 #include "base/threading/thread_restrictions.h" | 22 #include "base/threading/thread_restrictions.h" |
22 #include "base/trace_event/trace_event.h" | 23 #include "base/trace_event/trace_event.h" |
23 #include "chrome/browser/chrome_notification_types.h" | 24 #include "chrome/browser/chrome_notification_types.h" |
24 #include "chrome/browser/favicon/favicon_service_factory.h" | 25 #include "chrome/browser/favicon/favicon_service_factory.h" |
25 #include "chrome/browser/history/top_sites_factory.h" | 26 #include "chrome/browser/history/top_sites_factory.h" |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 // Make sure we are not out of date: if icon_urls_ is not empty, then | 244 // Make sure we are not out of date: if icon_urls_ is not empty, then |
244 // another notification has been received since we processed this one | 245 // another notification has been received since we processed this one |
245 if (!data->icon_urls_.empty()) | 246 if (!data->icon_urls_.empty()) |
246 return; | 247 return; |
247 | 248 |
248 // Make local copies of lists so we can release the lock. | 249 // Make local copies of lists so we can release the lock. |
249 local_most_visited_pages = data->most_visited_pages_; | 250 local_most_visited_pages = data->most_visited_pages_; |
250 local_recently_closed_pages = data->recently_closed_pages_; | 251 local_recently_closed_pages = data->recently_closed_pages_; |
251 } | 252 } |
252 | 253 |
253 // Delete the contents in JumpListIcons directory and log the delete status | 254 // If JumpListIcons directory doesn't exist or is not empty, skip updating the |
254 // to UMA. | |
255 FolderDeleteResult delete_status = | |
256 DeleteDirectoryContent(icon_dir, kFileDeleteLimit); | |
257 | |
258 UMA_HISTOGRAM_ENUMERATION("WinJumplist.DeleteStatusJumpListIcons", | |
259 delete_status, END); | |
260 | |
261 // If JumpListIcons directory is not empty, skip updating the jumplist icons. | |
262 // If the directory doesn't exist which shouldn't though, try to create | |
263 // a new JumpListIcons directory. If the creation fails, skip updating the | |
264 // jumplist icons. The jumplist links should be updated anyway, as it doesn't | 255 // jumplist icons. The jumplist links should be updated anyway, as it doesn't |
265 // involve disk IO. | 256 // involve disk IO. |
266 | 257 if (base::DirectoryExists(icon_dir) && base::IsDirectoryEmpty(icon_dir)) { |
267 DirectoryStatus dir_status = NON_EXIST; | |
268 if (base::DirectoryExists(icon_dir)) | |
269 dir_status = base::IsDirectoryEmpty(icon_dir) ? EMPTY : NON_EMPTY; | |
270 | |
271 if (dir_status == NON_EXIST && base::CreateDirectory(icon_dir)) | |
272 dir_status = EMPTY; | |
273 | |
274 UMA_HISTOGRAM_ENUMERATION("WinJumplist.DirectoryStatusJumpListIcons", | |
275 dir_status, DIRECTORY_STATUS_END); | |
276 | |
277 if (dir_status == EMPTY) { | |
278 // Create icon files for shortcuts in the "Most Visited" category. | 258 // Create icon files for shortcuts in the "Most Visited" category. |
279 CreateIconFiles(icon_dir, local_most_visited_pages); | 259 CreateIconFiles(icon_dir, local_most_visited_pages); |
280 | 260 |
281 // Create icon files for shortcuts in the "Recently Closed" | 261 // Create icon files for shortcuts in the "Recently Closed" |
282 // category. | 262 // category. |
283 CreateIconFiles(icon_dir, local_recently_closed_pages); | 263 CreateIconFiles(icon_dir, local_recently_closed_pages); |
284 } | 264 } |
285 | 265 |
286 // Create a new JumpList and replace the current JumpList with it. The | 266 // Create a new JumpList and replace the current JumpList with it. The |
287 // jumplist links are updated anyway, while the jumplist icons may not as | 267 // jumplist links are updated anyway, while the jumplist icons may not as |
288 // mentioned above. | 268 // mentioned above. |
289 UpdateJumpList(app_id.c_str(), local_most_visited_pages, | 269 UpdateJumpList(app_id.c_str(), local_most_visited_pages, |
290 local_recently_closed_pages, incognito_availability); | 270 local_recently_closed_pages, incognito_availability); |
291 } | 271 } |
292 | 272 |
293 } // namespace | 273 } // namespace |
294 | 274 |
295 JumpList::JumpListData::JumpListData() {} | 275 JumpList::JumpListData::JumpListData() {} |
296 | 276 |
297 JumpList::JumpListData::~JumpListData() {} | 277 JumpList::JumpListData::~JumpListData() {} |
298 | 278 |
299 JumpList::JumpList(Profile* profile) | 279 JumpList::JumpList(Profile* profile) |
300 : RefcountedKeyedService(content::BrowserThread::GetTaskRunnerForThread( | 280 : RefcountedKeyedService(content::BrowserThread::GetTaskRunnerForThread( |
301 content::BrowserThread::UI)), | 281 content::BrowserThread::UI)), |
302 profile_(profile), | 282 profile_(profile), |
303 jumplist_data_(new base::RefCountedData<JumpListData>), | 283 jumplist_data_(new base::RefCountedData<JumpListData>), |
304 task_id_(base::CancelableTaskTracker::kBadTaskId), | 284 task_id_(base::CancelableTaskTracker::kBadTaskId), |
305 single_thread_task_runner_(base::CreateCOMSTATaskRunnerWithTraits( | 285 update_jumplisticons_task_runner_(base::CreateCOMSTATaskRunnerWithTraits( |
306 base::TaskTraits() | 286 base::TaskTraits() |
307 .WithPriority(base::TaskPriority::BACKGROUND) | 287 .WithPriority(base::TaskPriority::BACKGROUND) |
308 .WithShutdownBehavior( | 288 .WithShutdownBehavior( |
309 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) | 289 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) |
310 .MayBlock())), | 290 .MayBlock())), |
| 291 delete_jumplisticonsold_task_runner_( |
| 292 base::CreateSequencedTaskRunnerWithTraits( |
| 293 base::TaskTraits() |
| 294 .WithPriority(base::TaskPriority::BACKGROUND) |
| 295 .WithShutdownBehavior( |
| 296 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) |
| 297 .MayBlock())), |
311 weak_ptr_factory_(this) { | 298 weak_ptr_factory_(this) { |
312 DCHECK(Enabled()); | 299 DCHECK(Enabled()); |
313 // To update JumpList when a tab is added or removed, we add this object to | 300 // To update JumpList when a tab is added or removed, we add this object to |
314 // the observer list of the TabRestoreService class. | 301 // the observer list of the TabRestoreService class. |
315 // When we add this object to the observer list, we save the pointer to this | 302 // When we add this object to the observer list, we save the pointer to this |
316 // TabRestoreService object. This pointer is used when we remove this object | 303 // TabRestoreService object. This pointer is used when we remove this object |
317 // from the observer list. | 304 // from the observer list. |
318 sessions::TabRestoreService* tab_restore_service = | 305 sessions::TabRestoreService* tab_restore_service = |
319 TabRestoreServiceFactory::GetForProfile(profile_); | 306 TabRestoreServiceFactory::GetForProfile(profile_); |
320 if (!tab_restore_service) | 307 if (!tab_restore_service) |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 | 584 |
598 void JumpList::DeferredRunUpdate() { | 585 void JumpList::DeferredRunUpdate() { |
599 DCHECK(CalledOnValidThread()); | 586 DCHECK(CalledOnValidThread()); |
600 | 587 |
601 TRACE_EVENT0("browser", "JumpList::DeferredRunUpdate"); | 588 TRACE_EVENT0("browser", "JumpList::DeferredRunUpdate"); |
602 // Check if incognito windows (or normal windows) are disabled by policy. | 589 // Check if incognito windows (or normal windows) are disabled by policy. |
603 IncognitoModePrefs::Availability incognito_availability = | 590 IncognitoModePrefs::Availability incognito_availability = |
604 profile_ ? IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) | 591 profile_ ? IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) |
605 : IncognitoModePrefs::ENABLED; | 592 : IncognitoModePrefs::ENABLED; |
606 | 593 |
| 594 // Post a task to delete the content in JumpListIcons folder and log the |
| 595 // results to UMA. |
| 596 update_jumplisticons_task_runner_->PostTask( |
| 597 FROM_HERE, base::Bind(&DeleteDirectoryContentAndLogResults, icon_dir_, |
| 598 kFileDeleteLimit)); |
| 599 |
607 // Post a task to update the jumplist used by the shell. | 600 // Post a task to update the jumplist used by the shell. |
608 single_thread_task_runner_->PostTask( | 601 update_jumplisticons_task_runner_->PostTask( |
609 FROM_HERE, base::Bind(&RunUpdateJumpList, incognito_availability, app_id_, | 602 FROM_HERE, base::Bind(&RunUpdateJumpList, incognito_availability, app_id_, |
610 icon_dir_, base::RetainedRef(jumplist_data_))); | 603 icon_dir_, base::RetainedRef(jumplist_data_))); |
611 | 604 |
612 // Post a task to delete JumpListIconsOld folder if it exists and log the | 605 // Post a task to delete JumpListIconsOld folder and log the results to UMA. |
613 // delete results to UMA. | |
614 base::FilePath icon_dir_old = icon_dir_.DirName().Append( | 606 base::FilePath icon_dir_old = icon_dir_.DirName().Append( |
615 icon_dir_.BaseName().value() + FILE_PATH_LITERAL("Old")); | 607 icon_dir_.BaseName().value() + FILE_PATH_LITERAL("Old")); |
616 | 608 |
617 single_thread_task_runner_->PostTask( | 609 delete_jumplisticonsold_task_runner_->PostTask( |
618 FROM_HERE, base::Bind(&DeleteDirectoryAndLogResults, | 610 FROM_HERE, base::Bind(&DeleteDirectoryAndLogResults, |
619 std::move(icon_dir_old), kFileDeleteLimit)); | 611 std::move(icon_dir_old), kFileDeleteLimit)); |
620 } | 612 } |
621 | 613 |
622 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { | 614 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { |
623 } | 615 } |
624 | 616 |
625 void JumpList::TopSitesChanged(history::TopSites* top_sites, | 617 void JumpList::TopSitesChanged(history::TopSites* top_sites, |
626 ChangeReason change_reason) { | 618 ChangeReason change_reason) { |
627 top_sites->GetMostVisitedURLs( | 619 top_sites->GetMostVisitedURLs( |
628 base::Bind(&JumpList::OnMostVisitedURLsAvailable, | 620 base::Bind(&JumpList::OnMostVisitedURLsAvailable, |
629 weak_ptr_factory_.GetWeakPtr()), | 621 weak_ptr_factory_.GetWeakPtr()), |
630 false); | 622 false); |
631 } | 623 } |
OLD | NEW |