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