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

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

Issue 2896233003: Cancel the JumpList update if top 5 most visited URLs are unchanged (Closed)
Patch Set: Address comments 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 | « no previous file | 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 <algorithm>
8 #include <iterator>
9
7 #include "base/base_paths.h" 10 #include "base/base_paths.h"
8 #include "base/bind.h" 11 #include "base/bind.h"
9 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
10 #include "base/command_line.h" 13 #include "base/command_line.h"
11 #include "base/containers/flat_set.h" 14 #include "base/containers/flat_set.h"
12 #include "base/files/file_util.h" 15 #include "base/files/file_util.h"
13 #include "base/metrics/histogram_macros.h" 16 #include "base/metrics/histogram_macros.h"
14 #include "base/path_service.h" 17 #include "base/path_service.h"
15 #include "base/sequenced_task_runner.h" 18 #include "base/sequenced_task_runner.h"
16 #include "base/single_thread_task_runner.h" 19 #include "base/single_thread_task_runner.h"
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 // Returns the full path of the JumpListIcons[|suffix|] directory in 189 // Returns the full path of the JumpListIcons[|suffix|] directory in
187 // |profile_dir|. 190 // |profile_dir|.
188 base::FilePath GenerateJumplistIconDirName( 191 base::FilePath GenerateJumplistIconDirName(
189 const base::FilePath& profile_dir, 192 const base::FilePath& profile_dir,
190 const base::FilePath::StringPieceType& suffix) { 193 const base::FilePath::StringPieceType& suffix) {
191 base::FilePath::StringType dir_name(chrome::kJumpListIconDirname); 194 base::FilePath::StringType dir_name(chrome::kJumpListIconDirname);
192 suffix.AppendToString(&dir_name); 195 suffix.AppendToString(&dir_name);
193 return profile_dir.Append(dir_name); 196 return profile_dir.Append(dir_name);
194 } 197 }
195 198
199 // Checks if the urls stored in |items| have new ones coming from |urls|.
200 bool HasNewMostVisitedItems(const ShellLinkItemList& items,
201 const history::MostVisitedURLList& urls) {
202 // If the number of the top sites going to be displayed is larger than the
203 // current one, or if the available urls from TopSites are fewer than the ones
204 // currenlty in display, we consider there are new most visited items.
205 // Otherwise, check if the current urls stored in |items| are different from
206 // |urls| to determine if there are new items.
207
208 size_t topsites_count_updated = std::min(urls.size(), kMostVisitedItems);
209 if (topsites_count_updated > items.size() || urls.size() < items.size())
210 return true;
211
212 return std::equal(std::begin(items), std::end(items), std::begin(urls),
grt (UTC plus 2) 2017/05/29 07:14:44 shouldn't this return false if the ranges are equa
chengx 2017/05/30 02:56:44 You're right. I've fixed this in the new patch set
213 [](const auto& item_ptr, const auto& most_visited_url) {
214 return item_ptr->url() == most_visited_url.url.spec();
215 });
216 }
217
196 } // namespace 218 } // namespace
197 219
198 JumpList::JumpListData::JumpListData() {} 220 JumpList::JumpListData::JumpListData() {}
199 221
200 JumpList::JumpListData::~JumpListData() {} 222 JumpList::JumpListData::~JumpListData() {}
201 223
202 JumpList::JumpList(Profile* profile) 224 JumpList::JumpList(Profile* profile)
203 : RefcountedKeyedService(content::BrowserThread::GetTaskRunnerForThread( 225 : RefcountedKeyedService(content::BrowserThread::GetTaskRunnerForThread(
204 content::BrowserThread::UI)), 226 content::BrowserThread::UI)),
205 profile_(profile), 227 profile_(profile),
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 Terminate(); 307 Terminate();
286 } 308 }
287 309
288 void JumpList::OnMostVisitedURLsAvailable( 310 void JumpList::OnMostVisitedURLsAvailable(
289 const history::MostVisitedURLList& urls) { 311 const history::MostVisitedURLList& urls) {
290 DCHECK(CalledOnValidThread()); 312 DCHECK(CalledOnValidThread());
291 313
292 { 314 {
293 JumpListData* data = &jumplist_data_->data; 315 JumpListData* data = &jumplist_data_->data;
294 base::AutoLock auto_lock(data->list_lock_); 316 base::AutoLock auto_lock(data->list_lock_);
317
318 // There is no need to update the JumpList if the top most visited sites in
319 // display have not changed.
320 if (!HasNewMostVisitedItems(data->most_visited_pages_, urls))
321 return;
322
295 data->most_visited_pages_.clear(); 323 data->most_visited_pages_.clear();
296 324
297 for (size_t i = 0; i < urls.size() && i < kMostVisitedItems; i++) { 325 for (size_t i = 0; i < urls.size() && i < kMostVisitedItems; i++) {
298 const history::MostVisitedURL& url = urls[i]; 326 const history::MostVisitedURL& url = urls[i];
299 scoped_refptr<ShellLinkItem> link = CreateShellLink(); 327 scoped_refptr<ShellLinkItem> link = CreateShellLink();
300 std::string url_string = url.url.spec(); 328 std::string url_string = url.url.spec();
301 base::string16 url_string_wide = base::UTF8ToUTF16(url_string); 329 base::string16 url_string_wide = base::UTF8ToUTF16(url_string);
302 link->GetCommandLine()->AppendArgNative(url_string_wide); 330 link->GetCommandLine()->AppendArgNative(url_string_wide);
303 link->GetCommandLine()->AppendSwitchASCII( 331 link->GetCommandLine()->AppendSwitchASCII(
304 switches::kWinJumplistAction, jumplist::kMostVisitedCategory); 332 switches::kWinJumplistAction, jumplist::kMostVisitedCategory);
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 app_id, profile_dir, local_most_visited_pages, 884 app_id, profile_dir, local_most_visited_pages,
857 local_recently_closed_pages, most_visited_pages_have_updates, 885 local_recently_closed_pages, most_visited_pages_have_updates,
858 recently_closed_pages_have_updates, incognito_availability)) { 886 recently_closed_pages_have_updates, incognito_availability)) {
859 base::AutoLock auto_lock(data->list_lock_); 887 base::AutoLock auto_lock(data->list_lock_);
860 if (most_visited_pages_have_updates) 888 if (most_visited_pages_have_updates)
861 data->most_visited_pages_have_updates_ = true; 889 data->most_visited_pages_have_updates_ = true;
862 if (recently_closed_pages_have_updates) 890 if (recently_closed_pages_have_updates)
863 data->recently_closed_pages_have_updates_ = true; 891 data->recently_closed_pages_have_updates_ = true;
864 } 892 }
865 } 893 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698