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 "base/base_paths.h" | 7 #include "base/base_paths.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
285 Terminate(); | 285 Terminate(); |
286 } | 286 } |
287 | 287 |
288 void JumpList::OnMostVisitedURLsAvailable( | 288 void JumpList::OnMostVisitedURLsAvailable( |
289 const history::MostVisitedURLList& urls) { | 289 const history::MostVisitedURLList& urls) { |
290 DCHECK(CalledOnValidThread()); | 290 DCHECK(CalledOnValidThread()); |
291 | 291 |
292 { | 292 { |
293 JumpListData* data = &jumplist_data_->data; | 293 JumpListData* data = &jumplist_data_->data; |
294 base::AutoLock auto_lock(data->list_lock_); | 294 base::AutoLock auto_lock(data->list_lock_); |
295 | |
296 bool need_update = false; | |
grt (UTC plus 2)
2017/05/24 07:22:12
i think it makes sense to make a helper function f
chengx
2017/05/24 23:44:14
I've added the helper function. I think it's bette
| |
297 | |
298 // If the number of the top sites going to be displayed is larger than the | |
grt (UTC plus 2)
2017/05/24 07:22:12
although it's unexpected, i think you also want to
chengx
2017/05/24 23:44:14
Done. You're right.
| |
299 // current one, schedule an update. | |
300 size_t topsites_count_updated = std::min(urls.size(), kMostVisitedItems); | |
301 if (topsites_count_updated > data->most_visited_pages_.size()) | |
302 need_update = true; | |
303 | |
304 // Cancel this jumplist update if the top |kMostVisitedItems| most visited | |
305 // urls are unchanged. | |
306 if (!need_update) { | |
grt (UTC plus 2)
2017/05/24 07:22:12
how about something like this:
#include <algorith
chengx
2017/05/24 23:44:14
Done. This is really impressive!
| |
307 size_t i = 0; | |
308 for (ShellLinkItemList::const_iterator | |
309 iter = data->most_visited_pages_.begin(); | |
310 iter != data->most_visited_pages_.end(); ++iter, ++i) { | |
311 if ((*iter)->url() != urls[i].url.spec()) { | |
312 need_update = true; | |
313 break; | |
314 } | |
315 } | |
316 } | |
317 if (!need_update) | |
318 return; | |
319 | |
295 data->most_visited_pages_.clear(); | 320 data->most_visited_pages_.clear(); |
296 | 321 |
297 for (size_t i = 0; i < urls.size() && i < kMostVisitedItems; i++) { | 322 for (size_t i = 0; i < urls.size() && i < kMostVisitedItems; i++) { |
298 const history::MostVisitedURL& url = urls[i]; | 323 const history::MostVisitedURL& url = urls[i]; |
299 scoped_refptr<ShellLinkItem> link = CreateShellLink(); | 324 scoped_refptr<ShellLinkItem> link = CreateShellLink(); |
300 std::string url_string = url.url.spec(); | 325 std::string url_string = url.url.spec(); |
301 base::string16 url_string_wide = base::UTF8ToUTF16(url_string); | 326 base::string16 url_string_wide = base::UTF8ToUTF16(url_string); |
302 link->GetCommandLine()->AppendArgNative(url_string_wide); | 327 link->GetCommandLine()->AppendArgNative(url_string_wide); |
303 link->GetCommandLine()->AppendSwitchASCII( | 328 link->GetCommandLine()->AppendSwitchASCII( |
304 switches::kWinJumplistAction, jumplist::kMostVisitedCategory); | 329 switches::kWinJumplistAction, jumplist::kMostVisitedCategory); |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
856 app_id, profile_dir, local_most_visited_pages, | 881 app_id, profile_dir, local_most_visited_pages, |
857 local_recently_closed_pages, most_visited_pages_have_updates, | 882 local_recently_closed_pages, most_visited_pages_have_updates, |
858 recently_closed_pages_have_updates, incognito_availability)) { | 883 recently_closed_pages_have_updates, incognito_availability)) { |
859 base::AutoLock auto_lock(data->list_lock_); | 884 base::AutoLock auto_lock(data->list_lock_); |
860 if (most_visited_pages_have_updates) | 885 if (most_visited_pages_have_updates) |
861 data->most_visited_pages_have_updates_ = true; | 886 data->most_visited_pages_have_updates_ = true; |
862 if (recently_closed_pages_have_updates) | 887 if (recently_closed_pages_have_updates) |
863 data->recently_closed_pages_have_updates_ = true; | 888 data->recently_closed_pages_have_updates_ = true; |
864 } | 889 } |
865 } | 890 } |
OLD | NEW |