Chromium Code Reviews| 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 | 113 |
| 114 // Add this icon file to the list and return its absolute path. | 114 // Add this icon file to the list and return its absolute path. |
| 115 // The IShellLink::SetIcon() function needs the absolute path to an icon. | 115 // The IShellLink::SetIcon() function needs the absolute path to an icon. |
| 116 *icon_path = path; | 116 *icon_path = path; |
| 117 return true; | 117 return true; |
| 118 } | 118 } |
| 119 | 119 |
| 120 // Helper method for RunUpdate to create icon files for the asynchrounously | 120 // Helper method for RunUpdate to create icon files for the asynchrounously |
| 121 // loaded icons. | 121 // loaded icons. |
| 122 void CreateIconFiles(const base::FilePath& icon_dir, | 122 void CreateIconFiles(const base::FilePath& icon_dir, |
| 123 const ShellLinkItemList& item_list) { | 123 const ShellLinkItemList& item_list, |
| 124 size_t max_items) { | |
| 124 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. | 125 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. |
| 125 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplist.CreateIconFilesDuration"); | 126 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplist.CreateIconFilesDuration"); |
| 126 | 127 |
| 127 for (ShellLinkItemList::const_iterator item = item_list.begin(); | 128 for (ShellLinkItemList::const_iterator item = item_list.begin(); |
| 128 item != item_list.end(); ++item) { | 129 item != item_list.end() && max_items > 0; ++item, --max_items) { |
| 129 base::FilePath icon_path; | 130 base::FilePath icon_path; |
| 130 if (CreateIconFile((*item)->icon_image(), icon_dir, &icon_path)) | 131 if (CreateIconFile((*item)->icon_image(), icon_dir, &icon_path)) |
| 131 (*item)->set_icon(icon_path.value(), 0); | 132 (*item)->set_icon(icon_path.value(), 0); |
| 132 } | 133 } |
| 133 } | 134 } |
| 134 | 135 |
| 135 // Updates the "Tasks" category of the JumpList. | 136 // Updates the "Tasks" category of the JumpList. |
| 136 bool UpdateTaskCategory( | 137 bool UpdateTaskCategory( |
| 137 JumpListUpdater* jumplist_updater, | 138 JumpListUpdater* jumplist_updater, |
| 138 IncognitoModePrefs::Availability incognito_availability) { | 139 IncognitoModePrefs::Availability incognito_availability) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 incognito->set_title(incognito_title); | 171 incognito->set_title(incognito_title); |
| 171 incognito->set_icon(chrome_path.value(), icon_resources::kIncognitoIndex); | 172 incognito->set_icon(chrome_path.value(), icon_resources::kIncognitoIndex); |
| 172 items.push_back(incognito); | 173 items.push_back(incognito); |
| 173 } | 174 } |
| 174 | 175 |
| 175 return jumplist_updater->AddTasks(items); | 176 return jumplist_updater->AddTasks(items); |
| 176 } | 177 } |
| 177 | 178 |
| 178 // Updates the application JumpList. | 179 // Updates the application JumpList. |
| 179 bool UpdateJumpList(const wchar_t* app_id, | 180 bool UpdateJumpList(const wchar_t* app_id, |
| 181 const base::FilePath& icon_dir, | |
| 180 const ShellLinkItemList& most_visited_pages, | 182 const ShellLinkItemList& most_visited_pages, |
| 181 const ShellLinkItemList& recently_closed_pages, | 183 const ShellLinkItemList& recently_closed_pages, |
| 182 IncognitoModePrefs::Availability incognito_availability) { | 184 IncognitoModePrefs::Availability incognito_availability) { |
| 183 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. | |
| 184 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplist.UpdateJumpListDuration"); | |
| 185 | |
| 186 // JumpList is implemented only on Windows 7 or later. | 185 // JumpList is implemented only on Windows 7 or later. |
| 187 // So, we should return now when this function is called on earlier versions | 186 // So, we should return now when this function is called on earlier versions |
| 188 // of Windows. | 187 // of Windows. |
| 189 if (!JumpListUpdater::IsEnabled()) | 188 if (!JumpListUpdater::IsEnabled()) |
| 190 return true; | 189 return true; |
| 191 | 190 |
| 192 JumpListUpdater jumplist_updater(app_id); | 191 JumpListUpdater jumplist_updater(app_id); |
| 193 if (!jumplist_updater.BeginUpdate()) | 192 if (!jumplist_updater.BeginUpdate()) |
| 194 return false; | 193 return false; |
| 195 | 194 |
| 196 // 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 |
| 197 // and 40% to "recently-closed" items, respectively. | 196 // and 40% to "recently-closed" items, respectively. |
| 198 // 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|, |
| 199 // we give the remaining slots to "most-visited" items. | 198 // we give the remaining slots to "most-visited" items. |
| 200 const int kMostVisited = 60; | 199 const int kMostVisited = 60; |
| 201 const int kRecentlyClosed = 40; | 200 const int kRecentlyClosed = 40; |
| 202 const int kTotal = kMostVisited + kRecentlyClosed; | 201 const int kTotal = kMostVisited + kRecentlyClosed; |
| 203 size_t most_visited_items = | 202 size_t most_visited_items = |
| 204 MulDiv(jumplist_updater.user_max_items(), kMostVisited, kTotal); | 203 MulDiv(jumplist_updater.user_max_items(), kMostVisited, kTotal); |
| 205 size_t recently_closed_items = | 204 size_t recently_closed_items = |
| 206 jumplist_updater.user_max_items() - most_visited_items; | 205 jumplist_updater.user_max_items() - most_visited_items; |
| 207 if (recently_closed_pages.size() < recently_closed_items) { | 206 if (recently_closed_pages.size() < recently_closed_items) { |
| 208 most_visited_items += recently_closed_items - recently_closed_pages.size(); | 207 most_visited_items += recently_closed_items - recently_closed_pages.size(); |
| 209 recently_closed_items = recently_closed_pages.size(); | 208 recently_closed_items = recently_closed_pages.size(); |
| 210 } | 209 } |
| 211 | 210 |
| 211 // 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 | |
| 213 // 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. | |
| 215 | |
| 216 if (base::DirectoryExists(icon_dir) && base::IsDirectoryEmpty(icon_dir)) { | |
| 217 // TODO(chengx): Remove this UMA metric after fixing http://crbug.com/40407. | |
| 218 UMA_HISTOGRAM_COUNTS_100( | |
| 219 "WinJumplist.CreateIconFilesCount", | |
| 220 most_visited_pages.size() + recently_closed_pages.size()); | |
| 221 | |
| 222 // Create icon files for shortcuts in the "Most Visited" category. | |
| 223 CreateIconFiles(icon_dir, most_visited_pages, most_visited_items); | |
| 224 | |
| 225 // Create icon files for shortcuts in the "Recently Closed" category. | |
| 226 CreateIconFiles(icon_dir, recently_closed_pages, recently_closed_items); | |
| 227 } | |
| 228 | |
| 229 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. | |
| 230 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplist.UpdateJumpListDuration"); | |
|
gab
2017/04/18 19:21:11
This changed the timing of this histogram without
chengx
2017/04/18 19:31:47
I am now heavily using version filters (thanks for
| |
| 231 | |
| 212 // Update the "Most Visited" category of the JumpList if it exists. | 232 // Update the "Most Visited" category of the JumpList if it exists. |
| 213 // This update request is applied into the JumpList when we commit this | 233 // This update request is applied into the JumpList when we commit this |
| 214 // transaction. | 234 // transaction. |
| 215 if (!jumplist_updater.AddCustomCategory( | 235 if (!jumplist_updater.AddCustomCategory( |
| 216 l10n_util::GetStringUTF16(IDS_NEW_TAB_MOST_VISITED), | 236 l10n_util::GetStringUTF16(IDS_NEW_TAB_MOST_VISITED), |
| 217 most_visited_pages, most_visited_items)) { | 237 most_visited_pages, most_visited_items)) { |
| 218 return false; | 238 return false; |
| 219 } | 239 } |
| 220 | 240 |
| 221 // Update the "Recently Closed" category of the JumpList. | 241 // Update the "Recently Closed" category of the JumpList. |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 250 // Make sure we are not out of date: if icon_urls_ is not empty, then | 270 // Make sure we are not out of date: if icon_urls_ is not empty, then |
| 251 // another notification has been received since we processed this one | 271 // another notification has been received since we processed this one |
| 252 if (!data->icon_urls_.empty()) | 272 if (!data->icon_urls_.empty()) |
| 253 return; | 273 return; |
| 254 | 274 |
| 255 // Make local copies of lists so we can release the lock. | 275 // Make local copies of lists so we can release the lock. |
| 256 local_most_visited_pages = data->most_visited_pages_; | 276 local_most_visited_pages = data->most_visited_pages_; |
| 257 local_recently_closed_pages = data->recently_closed_pages_; | 277 local_recently_closed_pages = data->recently_closed_pages_; |
| 258 } | 278 } |
| 259 | 279 |
| 260 // If JumpListIcons directory doesn't exist or is not empty, skip updating the | |
| 261 // jumplist icons. The jumplist links should be updated anyway, as it doesn't | |
| 262 // involve disk IO. | |
| 263 if (base::DirectoryExists(icon_dir) && base::IsDirectoryEmpty(icon_dir)) { | |
| 264 // TODO(chengx): Remove the UMA histogram after fixing | |
| 265 // http://crbug.com/40407. | |
| 266 UMA_HISTOGRAM_COUNTS_100( | |
| 267 "WinJumplist.CreateIconFilesCount", | |
| 268 local_most_visited_pages.size() + local_recently_closed_pages.size()); | |
| 269 | |
| 270 // Create icon files for shortcuts in the "Most Visited" category. | |
| 271 CreateIconFiles(icon_dir, local_most_visited_pages); | |
| 272 | |
| 273 // Create icon files for shortcuts in the "Recently Closed" | |
| 274 // category. | |
| 275 CreateIconFiles(icon_dir, local_recently_closed_pages); | |
| 276 } | |
| 277 | |
| 278 // Create a new JumpList and replace the current JumpList with it. The | 280 // Create a new JumpList and replace the current JumpList with it. The |
| 279 // jumplist links are updated anyway, while the jumplist icons may not as | 281 // jumplist links are updated anyway, while the jumplist icons may not as |
| 280 // mentioned above. | 282 // mentioned above. |
| 281 UpdateJumpList(app_id.c_str(), local_most_visited_pages, | 283 UpdateJumpList(app_id.c_str(), icon_dir, local_most_visited_pages, |
| 282 local_recently_closed_pages, incognito_availability); | 284 local_recently_closed_pages, incognito_availability); |
| 283 } | 285 } |
| 284 | 286 |
| 285 } // namespace | 287 } // namespace |
| 286 | 288 |
| 287 JumpList::JumpListData::JumpListData() {} | 289 JumpList::JumpListData::JumpListData() {} |
| 288 | 290 |
| 289 JumpList::JumpListData::~JumpListData() {} | 291 JumpList::JumpListData::~JumpListData() {} |
| 290 | 292 |
| 291 JumpList::JumpList(Profile* profile) | 293 JumpList::JumpList(Profile* profile) |
| (...skipping 335 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 |