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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 return true; | 189 return true; |
190 | 190 |
191 JumpListUpdater jumplist_updater(app_id); | 191 JumpListUpdater jumplist_updater(app_id); |
192 if (!jumplist_updater.BeginUpdate()) | 192 if (!jumplist_updater.BeginUpdate()) |
193 return false; | 193 return false; |
194 | 194 |
195 // We allocate 60% of the given JumpList slots to "most-visited" items | 195 // We allocate 60% of the given JumpList slots to "most-visited" items |
196 // and 40% to "recently-closed" items, respectively. | 196 // and 40% to "recently-closed" items, respectively. |
197 // Nevertheless, if there are not so many items in |recently_closed_pages|, | 197 // Nevertheless, if there are not so many items in |recently_closed_pages|, |
198 // we give the remaining slots to "most-visited" items. | 198 // we give the remaining slots to "most-visited" items. |
| 199 // The default maximum number of items to display in JumpList is 10. |
| 200 // https://msdn.microsoft.com/en-us/library/windows/desktop/dd378398(v=vs.85).
aspx |
199 const int kMostVisited = 60; | 201 const int kMostVisited = 60; |
200 const int kRecentlyClosed = 40; | 202 const int kRecentlyClosed = 40; |
201 const int kTotal = kMostVisited + kRecentlyClosed; | 203 const int kTotal = kMostVisited + kRecentlyClosed; |
202 size_t most_visited_items = | 204 size_t most_visited_items = |
203 MulDiv(jumplist_updater.user_max_items(), kMostVisited, kTotal); | 205 MulDiv(jumplist_updater.user_max_items(), kMostVisited, kTotal); |
204 size_t recently_closed_items = | 206 size_t recently_closed_items = |
205 jumplist_updater.user_max_items() - most_visited_items; | 207 jumplist_updater.user_max_items() - most_visited_items; |
206 if (recently_closed_pages.size() < recently_closed_items) { | 208 if (recently_closed_pages.size() < recently_closed_items) { |
207 most_visited_items += recently_closed_items - recently_closed_pages.size(); | 209 most_visited_items += recently_closed_items - recently_closed_pages.size(); |
208 recently_closed_items = recently_closed_pages.size(); | 210 recently_closed_items = recently_closed_pages.size(); |
209 } | 211 } |
210 | 212 |
| 213 // Delete the content in JumpListIcons folder and log the results to UMA. |
| 214 DeleteDirectoryContentAndLogResults(icon_dir, kFileDeleteLimit); |
| 215 |
211 // If JumpListIcons directory doesn't exist (we have tried to create it | 216 // If JumpListIcons directory doesn't exist (we have tried to create it |
212 // already) or is not empty, skip updating the jumplist icons. The jumplist | 217 // already) or is not empty, skip updating the jumplist icons. The jumplist |
213 // links should be updated anyway, as it doesn't involve disk IO. In this | 218 // links should be updated anyway, as it doesn't involve disk IO. In this |
214 // case, Chrome's icon will be used for the new links. | 219 // case, Chrome's icon will be used for the new links. |
215 | 220 |
216 if (base::DirectoryExists(icon_dir) && base::IsDirectoryEmpty(icon_dir)) { | 221 if (base::DirectoryExists(icon_dir) && base::IsDirectoryEmpty(icon_dir)) { |
217 // TODO(chengx): Remove this UMA metric after fixing http://crbug.com/40407. | 222 // TODO(chengx): Remove this UMA metric after fixing http://crbug.com/40407. |
218 UMA_HISTOGRAM_COUNTS_100( | 223 UMA_HISTOGRAM_COUNTS_100( |
219 "WinJumplist.CreateIconFilesCount", | 224 "WinJumplist.CreateIconFilesCount", |
220 most_visited_pages.size() + recently_closed_pages.size()); | 225 most_visited_pages.size() + recently_closed_pages.size()); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 // Make sure we are not out of date: if icon_urls_ is not empty, then | 275 // Make sure we are not out of date: if icon_urls_ is not empty, then |
271 // another notification has been received since we processed this one | 276 // another notification has been received since we processed this one |
272 if (!data->icon_urls_.empty()) | 277 if (!data->icon_urls_.empty()) |
273 return; | 278 return; |
274 | 279 |
275 // Make local copies of lists so we can release the lock. | 280 // Make local copies of lists so we can release the lock. |
276 local_most_visited_pages = data->most_visited_pages_; | 281 local_most_visited_pages = data->most_visited_pages_; |
277 local_recently_closed_pages = data->recently_closed_pages_; | 282 local_recently_closed_pages = data->recently_closed_pages_; |
278 } | 283 } |
279 | 284 |
280 // Delete the content in JumpListIcons folder and log the results to UMA. | |
281 DeleteDirectoryContentAndLogResults(icon_dir, kFileDeleteLimit); | |
282 | |
283 // Create a new JumpList and replace the current JumpList with it. The | 285 // Create a new JumpList and replace the current JumpList with it. The |
284 // jumplist links are updated anyway, while the jumplist icons may not as | 286 // jumplist links are updated anyway, while the jumplist icons may not as |
285 // mentioned above. | 287 // mentioned above. |
286 UpdateJumpList(app_id.c_str(), icon_dir, local_most_visited_pages, | 288 UpdateJumpList(app_id.c_str(), icon_dir, local_most_visited_pages, |
287 local_recently_closed_pages, incognito_availability); | 289 local_recently_closed_pages, incognito_availability); |
288 } | 290 } |
289 | 291 |
290 } // namespace | 292 } // namespace |
291 | 293 |
292 JumpList::JumpListData::JumpListData() {} | 294 JumpList::JumpListData::JumpListData() {} |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { | 629 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { |
628 } | 630 } |
629 | 631 |
630 void JumpList::TopSitesChanged(history::TopSites* top_sites, | 632 void JumpList::TopSitesChanged(history::TopSites* top_sites, |
631 ChangeReason change_reason) { | 633 ChangeReason change_reason) { |
632 top_sites->GetMostVisitedURLs( | 634 top_sites->GetMostVisitedURLs( |
633 base::Bind(&JumpList::OnMostVisitedURLsAvailable, | 635 base::Bind(&JumpList::OnMostVisitedURLsAvailable, |
634 weak_ptr_factory_.GetWeakPtr()), | 636 weak_ptr_factory_.GetWeakPtr()), |
635 false); | 637 false); |
636 } | 638 } |
OLD | NEW |