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

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

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