Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: chrome/browser/win/jumplist.cc

Issue 2807883002: Separate JumpListIcons delete task and update task (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
(...skipping 13 matching lines...) Expand all
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 single_thread_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 sequenced_task_runner_(base::CreateSequencedTaskRunnerWithTraits(
292 base::TaskTraits()
293 .WithPriority(base::TaskPriority::BACKGROUND)
294 .WithShutdownBehavior(
295 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN)
296 .MayBlock())),
311 weak_ptr_factory_(this) { 297 weak_ptr_factory_(this) {
312 DCHECK(Enabled()); 298 DCHECK(Enabled());
313 // To update JumpList when a tab is added or removed, we add this object to 299 // To update JumpList when a tab is added or removed, we add this object to
314 // the observer list of the TabRestoreService class. 300 // the observer list of the TabRestoreService class.
315 // When we add this object to the observer list, we save the pointer to this 301 // 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 302 // TabRestoreService object. This pointer is used when we remove this object
317 // from the observer list. 303 // from the observer list.
318 sessions::TabRestoreService* tab_restore_service = 304 sessions::TabRestoreService* tab_restore_service =
319 TabRestoreServiceFactory::GetForProfile(profile_); 305 TabRestoreServiceFactory::GetForProfile(profile_);
320 if (!tab_restore_service) 306 if (!tab_restore_service)
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 583
598 void JumpList::DeferredRunUpdate() { 584 void JumpList::DeferredRunUpdate() {
599 DCHECK(CalledOnValidThread()); 585 DCHECK(CalledOnValidThread());
600 586
601 TRACE_EVENT0("browser", "JumpList::DeferredRunUpdate"); 587 TRACE_EVENT0("browser", "JumpList::DeferredRunUpdate");
602 // Check if incognito windows (or normal windows) are disabled by policy. 588 // Check if incognito windows (or normal windows) are disabled by policy.
603 IncognitoModePrefs::Availability incognito_availability = 589 IncognitoModePrefs::Availability incognito_availability =
604 profile_ ? IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) 590 profile_ ? IncognitoModePrefs::GetAvailability(profile_->GetPrefs())
605 : IncognitoModePrefs::ENABLED; 591 : IncognitoModePrefs::ENABLED;
606 592
593 // Post a task to delete the content in JumpListIcons folder and log the
594 // results to UMA.
595 single_thread_task_runner_->PostTask(
596 FROM_HERE, base::Bind(&DeleteDirectoryContentAndLogResults, icon_dir_,
597 kFileDeleteLimit));
598
607 // Post a task to update the jumplist used by the shell. 599 // Post a task to update the jumplist used by the shell.
608 single_thread_task_runner_->PostTask( 600 single_thread_task_runner_->PostTask(
609 FROM_HERE, base::Bind(&RunUpdateJumpList, incognito_availability, app_id_, 601 FROM_HERE, base::Bind(&RunUpdateJumpList, incognito_availability, app_id_,
610 icon_dir_, base::RetainedRef(jumplist_data_))); 602 icon_dir_, base::RetainedRef(jumplist_data_)));
611 603
612 // Post a task to delete JumpListIconsOld folder if it exists and log the 604 // 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( 605 base::FilePath icon_dir_old = icon_dir_.DirName().Append(
615 icon_dir_.BaseName().value() + FILE_PATH_LITERAL("Old")); 606 icon_dir_.BaseName().value() + FILE_PATH_LITERAL("Old"));
616 607
617 single_thread_task_runner_->PostTask( 608 sequenced_task_runner_->PostTask(
618 FROM_HERE, base::Bind(&DeleteDirectoryAndLogResults, 609 FROM_HERE, base::Bind(&DeleteDirectoryAndLogResults,
619 std::move(icon_dir_old), kFileDeleteLimit)); 610 std::move(icon_dir_old), kFileDeleteLimit));
620 } 611 }
621 612
622 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { 613 void JumpList::TopSitesLoaded(history::TopSites* top_sites) {
623 } 614 }
624 615
625 void JumpList::TopSitesChanged(history::TopSites* top_sites, 616 void JumpList::TopSitesChanged(history::TopSites* top_sites,
626 ChangeReason change_reason) { 617 ChangeReason change_reason) {
627 top_sites->GetMostVisitedURLs( 618 top_sites->GetMostVisitedURLs(
628 base::Bind(&JumpList::OnMostVisitedURLsAvailable, 619 base::Bind(&JumpList::OnMostVisitedURLsAvailable,
629 weak_ptr_factory_.GetWeakPtr()), 620 weak_ptr_factory_.GetWeakPtr()),
630 false); 621 false);
631 } 622 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698