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

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

Issue 2846383002: Improve JumpList icon folders' naming style (Closed)
Patch Set: Merge branch 'master' of https://chromium.googlesource.com/chromium/src into updatejumplisticonsfol… Created 3 years, 7 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
« no previous file with comments | « chrome/browser/win/jumplist.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 base::ReplaceSubstringsAfterOffset( 190 base::ReplaceSubstringsAfterOffset(
191 &incognito_title, 0, L"&", base::StringPiece16()); 191 &incognito_title, 0, L"&", base::StringPiece16());
192 incognito->set_title(incognito_title); 192 incognito->set_title(incognito_title);
193 incognito->set_icon(chrome_path.value(), icon_resources::kIncognitoIndex); 193 incognito->set_icon(chrome_path.value(), icon_resources::kIncognitoIndex);
194 items.push_back(incognito); 194 items.push_back(incognito);
195 } 195 }
196 196
197 return jumplist_updater->AddTasks(items); 197 return jumplist_updater->AddTasks(items);
198 } 198 }
199 199
200 // Returns the full path of the JumpListIcons[|suffix|] directory in
201 // |profile_dir|.
202 base::FilePath GenerateJumplistIconDirName(
203 const base::FilePath& profile_dir,
204 const base::FilePath::StringPieceType& suffix) {
205 base::FilePath::StringType dir_name(chrome::kJumpListIconDirname);
206 suffix.AppendToString(&dir_name);
207 return profile_dir.Append(dir_name);
208 }
209
200 // Updates the application JumpList, which consists of 1) delete old icon files; 210 // Updates the application JumpList, which consists of 1) delete old icon files;
201 // 2) create new icon files; 3) notify the OS. 211 // 2) create new icon files; 3) notify the OS.
202 // Note that any timeout error along the way results in the old jumplist being 212 // Note that any timeout error along the way results in the old jumplist being
203 // left as-is, while any non-timeout error results in the old jumplist being 213 // left as-is, while any non-timeout error results in the old jumplist being
204 // left as-is, but without icon files. 214 // left as-is, but without icon files.
205 bool UpdateJumpList(const wchar_t* app_id, 215 bool UpdateJumpList(const wchar_t* app_id,
206 const base::FilePath& icon_dir, 216 const base::FilePath& profile_dir,
207 const ShellLinkItemList& most_visited_pages, 217 const ShellLinkItemList& most_visited_pages,
208 const ShellLinkItemList& recently_closed_pages, 218 const ShellLinkItemList& recently_closed_pages,
209 bool most_visited_pages_have_updates, 219 bool most_visited_pages_have_updates,
210 bool recently_closed_pages_have_updates, 220 bool recently_closed_pages_have_updates,
211 IncognitoModePrefs::Availability incognito_availability) { 221 IncognitoModePrefs::Availability incognito_availability) {
212 if (!JumpListUpdater::IsEnabled()) 222 if (!JumpListUpdater::IsEnabled())
213 return true; 223 return true;
214 224
215 JumpListUpdater jumplist_updater(app_id); 225 JumpListUpdater jumplist_updater(app_id);
216 226
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 if (recently_closed_pages.size() < recently_closed_items) { 264 if (recently_closed_pages.size() < recently_closed_items) {
255 most_visited_items += recently_closed_items - recently_closed_pages.size(); 265 most_visited_items += recently_closed_items - recently_closed_pages.size();
256 recently_closed_items = recently_closed_pages.size(); 266 recently_closed_items = recently_closed_pages.size();
257 } 267 }
258 268
259 // Record the desired number of icons to create in this JumpList update. 269 // Record the desired number of icons to create in this JumpList update.
260 int icons_to_create = 0; 270 int icons_to_create = 0;
261 271
262 // Update the icons for "Most Visisted" category of the JumpList if needed. 272 // Update the icons for "Most Visisted" category of the JumpList if needed.
263 if (most_visited_pages_have_updates) { 273 if (most_visited_pages_have_updates) {
264 base::FilePath icon_dir_most_visited = icon_dir.DirName().Append( 274 base::FilePath icon_dir_most_visited = GenerateJumplistIconDirName(
265 icon_dir.BaseName().value() + FILE_PATH_LITERAL("MostVisited")); 275 profile_dir, FILE_PATH_LITERAL("MostVisited"));
266 276
267 UpdateIconFiles(icon_dir_most_visited, most_visited_pages, 277 UpdateIconFiles(icon_dir_most_visited, most_visited_pages,
268 most_visited_items); 278 most_visited_items);
269 279
270 icons_to_create += std::min(most_visited_pages.size(), most_visited_items); 280 icons_to_create += std::min(most_visited_pages.size(), most_visited_items);
271 } 281 }
272 282
273 // Update the icons for "Recently Closed" category of the JumpList if needed. 283 // Update the icons for "Recently Closed" category of the JumpList if needed.
274 if (recently_closed_pages_have_updates) { 284 if (recently_closed_pages_have_updates) {
275 base::FilePath icon_dir_recent_closed = icon_dir.DirName().Append( 285 base::FilePath icon_dir_recent_closed = GenerateJumplistIconDirName(
276 icon_dir.BaseName().value() + FILE_PATH_LITERAL("RecentClosed")); 286 profile_dir, FILE_PATH_LITERAL("RecentClosed"));
277 287
278 UpdateIconFiles(icon_dir_recent_closed, recently_closed_pages, 288 UpdateIconFiles(icon_dir_recent_closed, recently_closed_pages,
279 recently_closed_items); 289 recently_closed_items);
280 290
281 icons_to_create += 291 icons_to_create +=
282 std::min(recently_closed_pages.size(), recently_closed_items); 292 std::min(recently_closed_pages.size(), recently_closed_items);
283 } 293 }
284 294
285 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. 295 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407.
286 UMA_HISTOGRAM_COUNTS_100("WinJumplist.CreateIconFilesCount", icons_to_create); 296 UMA_HISTOGRAM_COUNTS_100("WinJumplist.CreateIconFilesCount", icons_to_create);
(...skipping 21 matching lines...) Expand all
308 if (!UpdateTaskCategory(&jumplist_updater, incognito_availability)) 318 if (!UpdateTaskCategory(&jumplist_updater, incognito_availability))
309 return false; 319 return false;
310 320
311 // Commit this transaction and send the updated JumpList to Windows. 321 // Commit this transaction and send the updated JumpList to Windows.
312 return jumplist_updater.CommitUpdate(); 322 return jumplist_updater.CommitUpdate();
313 } 323 }
314 324
315 // Updates the jumplist, once all the data has been fetched. 325 // Updates the jumplist, once all the data has been fetched.
316 void RunUpdateJumpList(IncognitoModePrefs::Availability incognito_availability, 326 void RunUpdateJumpList(IncognitoModePrefs::Availability incognito_availability,
317 const std::wstring& app_id, 327 const std::wstring& app_id,
318 const base::FilePath& icon_dir, 328 const base::FilePath& profile_dir,
319 base::RefCountedData<JumpListData>* ref_counted_data) { 329 base::RefCountedData<JumpListData>* ref_counted_data) {
320 JumpListData* data = &ref_counted_data->data; 330 JumpListData* data = &ref_counted_data->data;
321 ShellLinkItemList local_most_visited_pages; 331 ShellLinkItemList local_most_visited_pages;
322 ShellLinkItemList local_recently_closed_pages; 332 ShellLinkItemList local_recently_closed_pages;
323 bool most_visited_pages_have_updates; 333 bool most_visited_pages_have_updates;
324 bool recently_closed_pages_have_updates; 334 bool recently_closed_pages_have_updates;
325 335
326 { 336 {
327 base::AutoLock auto_lock(data->list_lock_); 337 base::AutoLock auto_lock(data->list_lock_);
328 // Make sure we are not out of date: if icon_urls_ is not empty, then 338 // Make sure we are not out of date: if icon_urls_ is not empty, then
(...skipping 14 matching lines...) Expand all
343 data->recently_closed_pages_have_updates_ = false; 353 data->recently_closed_pages_have_updates_ = false;
344 } 354 }
345 355
346 if (!most_visited_pages_have_updates && !recently_closed_pages_have_updates) 356 if (!most_visited_pages_have_updates && !recently_closed_pages_have_updates)
347 return; 357 return;
348 358
349 // Update the application JumpList. If it fails, reset the flags to true if 359 // Update the application JumpList. If it fails, reset the flags to true if
350 // they were so that the corresponding JumpList categories will be tried to 360 // they were so that the corresponding JumpList categories will be tried to
351 // update again in the next run. 361 // update again in the next run.
352 if (!UpdateJumpList( 362 if (!UpdateJumpList(
353 app_id.c_str(), icon_dir, local_most_visited_pages, 363 app_id.c_str(), profile_dir, local_most_visited_pages,
354 local_recently_closed_pages, most_visited_pages_have_updates, 364 local_recently_closed_pages, most_visited_pages_have_updates,
355 recently_closed_pages_have_updates, incognito_availability)) { 365 recently_closed_pages_have_updates, incognito_availability)) {
356 base::AutoLock auto_lock(data->list_lock_); 366 base::AutoLock auto_lock(data->list_lock_);
357 if (most_visited_pages_have_updates) 367 if (most_visited_pages_have_updates)
358 data->most_visited_pages_have_updates_ = true; 368 data->most_visited_pages_have_updates_ = true;
359 if (recently_closed_pages_have_updates) 369 if (recently_closed_pages_have_updates)
360 data->recently_closed_pages_have_updates_ = true; 370 data->recently_closed_pages_have_updates_ = true;
361 } 371 }
362 } 372 }
363 373
(...skipping 23 matching lines...) Expand all
387 // When we add this object to the observer list, we save the pointer to this 397 // 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 398 // TabRestoreService object. This pointer is used when we remove this object
389 // from the observer list. 399 // from the observer list.
390 sessions::TabRestoreService* tab_restore_service = 400 sessions::TabRestoreService* tab_restore_service =
391 TabRestoreServiceFactory::GetForProfile(profile_); 401 TabRestoreServiceFactory::GetForProfile(profile_);
392 if (!tab_restore_service) 402 if (!tab_restore_service)
393 return; 403 return;
394 404
395 app_id_ = 405 app_id_ =
396 shell_integration::win::GetChromiumModelIdForProfile(profile_->GetPath()); 406 shell_integration::win::GetChromiumModelIdForProfile(profile_->GetPath());
397 icon_dir_ = profile_->GetPath().Append(chrome::kJumpListIconDirname);
398 407
399 scoped_refptr<history::TopSites> top_sites = 408 scoped_refptr<history::TopSites> top_sites =
400 TopSitesFactory::GetForProfile(profile_); 409 TopSitesFactory::GetForProfile(profile_);
401 if (top_sites) { 410 if (top_sites) {
402 // TopSites updates itself after a delay. This is especially noticable when 411 // TopSites updates itself after a delay. This is especially noticable when
403 // your profile is empty. Ask TopSites to update itself when jumplist is 412 // your profile is empty. Ask TopSites to update itself when jumplist is
404 // initialized. 413 // initialized.
405 top_sites->SyncWithHistory(); 414 top_sites->SyncWithHistory();
406 // Register as TopSitesObserver so that we can update ourselves when the 415 // Register as TopSitesObserver so that we can update ourselves when the
407 // TopSites changes. 416 // TopSites changes.
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 } else { 684 } else {
676 timer_.Start(FROM_HERE, kDelayForJumplistUpdate, this, 685 timer_.Start(FROM_HERE, kDelayForJumplistUpdate, this,
677 &JumpList::DeferredRunUpdate); 686 &JumpList::DeferredRunUpdate);
678 } 687 }
679 } 688 }
680 689
681 void JumpList::DeferredRunUpdate() { 690 void JumpList::DeferredRunUpdate() {
682 DCHECK(CalledOnValidThread()); 691 DCHECK(CalledOnValidThread());
683 692
684 TRACE_EVENT0("browser", "JumpList::DeferredRunUpdate"); 693 TRACE_EVENT0("browser", "JumpList::DeferredRunUpdate");
694 if (!profile_)
695 return;
696
697 base::FilePath profile_dir = profile_->GetPath();
698
685 // Check if incognito windows (or normal windows) are disabled by policy. 699 // Check if incognito windows (or normal windows) are disabled by policy.
686 IncognitoModePrefs::Availability incognito_availability = 700 IncognitoModePrefs::Availability incognito_availability =
687 profile_ ? IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) 701 IncognitoModePrefs::GetAvailability(profile_->GetPrefs());
688 : IncognitoModePrefs::ENABLED;
689 702
690 // Post a task to update the JumpList, which consists of 1) delete old icons, 703 // Post a task to update the JumpList, which consists of 1) delete old icons,
691 // 2) create new icons, 3) notify the OS. 704 // 2) create new icons, 3) notify the OS.
692 update_jumplist_task_runner_->PostTask( 705 update_jumplist_task_runner_->PostTask(
693 FROM_HERE, base::Bind(&RunUpdateJumpList, incognito_availability, app_id_, 706 FROM_HERE, base::Bind(&RunUpdateJumpList, incognito_availability, app_id_,
694 icon_dir_, base::RetainedRef(jumplist_data_))); 707 profile_dir, base::RetainedRef(jumplist_data_)));
695 708
696 // Post a task to delete JumpListIcons folder as it's no longer needed. 709 // Post a task to delete JumpListIcons folder as it's no longer needed.
697 // Now we have JumpListIconsMostVisited folder and JumpListIconsRecentClosed 710 // Now we have JumpListIconsMostVisited folder and JumpListIconsRecentClosed
698 // folder instead. 711 // folder instead.
699 delete_jumplisticons_task_runner_->PostTask( 712 base::FilePath icon_dir =
700 FROM_HERE, base::Bind(&DeleteDirectory, icon_dir_, kFileDeleteLimit)); 713 GenerateJumplistIconDirName(profile_dir, FILE_PATH_LITERAL(""));
701
702 // Post a task to delete JumpListIconsOld folder as it's no longer needed.
703 base::FilePath icon_dir_old = icon_dir_.DirName().Append(
704 icon_dir_.BaseName().value() + FILE_PATH_LITERAL("Old"));
705 714
706 delete_jumplisticons_task_runner_->PostTask( 715 delete_jumplisticons_task_runner_->PostTask(
707 FROM_HERE, 716 FROM_HERE,
717 base::Bind(&DeleteDirectory, std::move(icon_dir), kFileDeleteLimit));
718
719 // Post a task to delete JumpListIconsOld folder as it's no longer needed.
720 base::FilePath icon_dir_old =
721 GenerateJumplistIconDirName(profile_dir, FILE_PATH_LITERAL("Old"));
722
723 delete_jumplisticons_task_runner_->PostTask(
724 FROM_HERE,
708 base::Bind(&DeleteDirectory, std::move(icon_dir_old), kFileDeleteLimit)); 725 base::Bind(&DeleteDirectory, std::move(icon_dir_old), kFileDeleteLimit));
709 } 726 }
710 727
711 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { 728 void JumpList::TopSitesLoaded(history::TopSites* top_sites) {
712 } 729 }
713 730
714 void JumpList::TopSitesChanged(history::TopSites* top_sites, 731 void JumpList::TopSitesChanged(history::TopSites* top_sites,
715 ChangeReason change_reason) { 732 ChangeReason change_reason) {
716 top_sites->GetMostVisitedURLs( 733 top_sites->GetMostVisitedURLs(
717 base::Bind(&JumpList::OnMostVisitedURLsAvailable, 734 base::Bind(&JumpList::OnMostVisitedURLsAvailable,
718 weak_ptr_factory_.GetWeakPtr()), 735 weak_ptr_factory_.GetWeakPtr()),
719 false); 736 false);
720 } 737 }
OLDNEW
« no previous file with comments | « chrome/browser/win/jumplist.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698