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

Side by Side Diff: chrome/browser/history/top_sites_impl_unittest.cc

Issue 352913002: Port HistoryService::ScheduleDBTask to CancelableTaskTracker (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/memory/weak_ptr.h" 6 #include "base/memory/weak_ptr.h"
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/task/cancelable_task_tracker.h" 10 #include "base/task/cancelable_task_tracker.h"
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 // loaded from the db. 175 // loaded from the db.
176 void RefreshTopSitesAndRecreate() { 176 void RefreshTopSitesAndRecreate() {
177 StartQueryForMostVisited(); 177 StartQueryForMostVisited();
178 WaitForHistory(); 178 WaitForHistory();
179 RecreateTopSitesAndBlock(); 179 RecreateTopSitesAndBlock();
180 } 180 }
181 181
182 // Blocks the caller until history processes a task. This is useful if you 182 // Blocks the caller until history processes a task. This is useful if you
183 // need to wait until you know history has processed a task. 183 // need to wait until you know history has processed a task.
184 void WaitForHistory() { 184 void WaitForHistory() {
185 history_service()->ScheduleDBTask(new WaitForHistoryTask(), &consumer_); 185 history_service()->ScheduleDBTask(
186 new WaitForHistoryTask(), &history_tracker_);
186 base::MessageLoop::current()->Run(); 187 base::MessageLoop::current()->Run();
187 } 188 }
188 189
189 // Waits for top sites to finish processing a task. This is useful if you need 190 // Waits for top sites to finish processing a task. This is useful if you need
190 // to wait until top sites finishes processing a task. 191 // to wait until top sites finishes processing a task.
191 void WaitForTopSites() { 192 void WaitForTopSites() {
192 top_sites()->backend_->DoEmptyRequest( 193 top_sites()->backend_->DoEmptyRequest(
193 base::Bind(&TopSitesImplTest::QuitCallback, base::Unretained(this)), 194 base::Bind(&TopSitesImplTest::QuitCallback, base::Unretained(this)),
194 &cancelable_task_tracker_); 195 &top_sites_tracker_);
195 base::MessageLoop::current()->Run(); 196 base::MessageLoop::current()->Run();
196 } 197 }
197 198
198 TopSitesImpl* top_sites() { 199 TopSitesImpl* top_sites() {
199 return static_cast<TopSitesImpl*>(profile_->GetTopSites()); 200 return static_cast<TopSitesImpl*>(profile_->GetTopSites());
200 } 201 }
201 CancelableRequestConsumer* consumer() { return &consumer_; }
202 TestingProfile* profile() {return profile_.get();} 202 TestingProfile* profile() {return profile_.get();}
203 HistoryService* history_service() { 203 HistoryService* history_service() {
204 return HistoryServiceFactory::GetForProfile(profile_.get(), 204 return HistoryServiceFactory::GetForProfile(profile_.get(),
205 Profile::EXPLICIT_ACCESS); 205 Profile::EXPLICIT_ACCESS);
206 } 206 }
207 207
208 MostVisitedURLList GetPrepopulatePages() { 208 MostVisitedURLList GetPrepopulatePages() {
209 return top_sites()->GetPrepopulatePages(); 209 return top_sites()->GetPrepopulatePages();
210 } 210 }
211 211
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 top_sites()->thread_safe_cache_->SetTopSites(empty); 326 top_sites()->thread_safe_cache_->SetTopSites(empty);
327 } 327 }
328 328
329 private: 329 private:
330 base::MessageLoopForUI message_loop_; 330 base::MessageLoopForUI message_loop_;
331 content::TestBrowserThread ui_thread_; 331 content::TestBrowserThread ui_thread_;
332 content::TestBrowserThread db_thread_; 332 content::TestBrowserThread db_thread_;
333 scoped_ptr<TestingProfile> profile_; 333 scoped_ptr<TestingProfile> profile_;
334 334
335 // To cancel HistoryService tasks. 335 // To cancel HistoryService tasks.
336 CancelableRequestConsumer consumer_; 336 base::CancelableTaskTracker history_tracker_;
337 337
338 // To cancel TopSitesBackend tasks. 338 // To cancel TopSitesBackend tasks.
339 base::CancelableTaskTracker cancelable_task_tracker_; 339 base::CancelableTaskTracker top_sites_tracker_;
340 340
341 DISALLOW_COPY_AND_ASSIGN(TopSitesImplTest); 341 DISALLOW_COPY_AND_ASSIGN(TopSitesImplTest);
342 }; // Class TopSitesImplTest 342 }; // Class TopSitesImplTest
343 343
344 // Helper function for appending a URL to a vector of "most visited" URLs, 344 // Helper function for appending a URL to a vector of "most visited" URLs,
345 // using the default values for everything but the URL. 345 // using the default values for everything but the URL.
346 static void AppendMostVisitedURL(std::vector<MostVisitedURL>* list, 346 static void AppendMostVisitedURL(std::vector<MostVisitedURL>* list,
347 const GURL& url) { 347 const GURL& url) {
348 MostVisitedURL mv; 348 MostVisitedURL mv;
349 mv.url = url; 349 mv.url = url;
(...skipping 1217 matching lines...) Expand 10 before | Expand all | Expand 10 after
1567 ASSERT_EQ(orig_thumbnail.getSize(), thumbnail.getSize()); 1567 ASSERT_EQ(orig_thumbnail.getSize(), thumbnail.getSize());
1568 orig_thumbnail.lockPixels(); 1568 orig_thumbnail.lockPixels();
1569 thumbnail.lockPixels(); 1569 thumbnail.lockPixels();
1570 EXPECT_EQ(0, memcmp(orig_thumbnail.getPixels(), thumbnail.getPixels(), 1570 EXPECT_EQ(0, memcmp(orig_thumbnail.getPixels(), thumbnail.getPixels(),
1571 orig_thumbnail.getSize())); 1571 orig_thumbnail.getSize()));
1572 thumbnail.unlockPixels(); 1572 thumbnail.unlockPixels();
1573 orig_thumbnail.unlockPixels(); 1573 orig_thumbnail.unlockPixels();
1574 } 1574 }
1575 1575
1576 } // namespace history 1576 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698