Chromium Code Reviews| 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/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "base/task/cancelable_task_tracker.h" | 9 #include "base/task/cancelable_task_tracker.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| 11 #include "chrome/browser/history/history_db_task.h" | 11 #include "chrome/browser/history/history_db_task.h" |
| 12 #include "chrome/browser/history/history_notifications.h" | 12 #include "chrome/browser/history/history_notifications.h" |
| 13 #include "chrome/browser/history/history_service_factory.h" | 13 #include "chrome/browser/history/history_service_factory.h" |
| 14 #include "chrome/browser/history/history_unittest_base.h" | 14 #include "chrome/browser/history/history_unittest_base.h" |
| 15 #include "chrome/browser/history/top_sites.h" | 15 #include "chrome/browser/history/top_sites.h" |
| 16 #include "chrome/browser/history/top_sites_cache.h" | 16 #include "chrome/browser/history/top_sites_cache.h" |
| 17 #include "chrome/browser/history/top_sites_impl.h" | 17 #include "chrome/browser/history/top_sites_impl.h" |
| 18 #include "chrome/browser/history/top_sites_factory.h" | |
| 18 #include "chrome/common/chrome_constants.h" | 19 #include "chrome/common/chrome_constants.h" |
| 19 #include "chrome/common/chrome_paths.h" | 20 #include "chrome/common/chrome_paths.h" |
| 20 #include "chrome/test/base/testing_profile.h" | 21 #include "chrome/test/base/testing_profile.h" |
| 21 #include "components/history/core/browser/history_types.h" | 22 #include "components/history/core/browser/history_types.h" |
| 22 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
| 23 #include "content/public/test/test_browser_thread.h" | 24 #include "content/public/test/test_browser_thread.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 25 #include "third_party/skia/include/core/SkBitmap.h" | 26 #include "third_party/skia/include/core/SkBitmap.h" |
| 26 #include "ui/gfx/codec/jpeg_codec.h" | 27 #include "ui/gfx/codec/jpeg_codec.h" |
| 27 #include "url/gurl.h" | 28 #include "url/gurl.h" |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 47 | 48 |
| 48 TestTopSitesObserver::TestTopSitesObserver(Profile* profile, | 49 TestTopSitesObserver::TestTopSitesObserver(Profile* profile, |
| 49 history::TopSites* top_sites) | 50 history::TopSites* top_sites) |
| 50 : profile_(profile), top_sites_(top_sites) { | 51 : profile_(profile), top_sites_(top_sites) { |
| 51 DCHECK(top_sites_); | 52 DCHECK(top_sites_); |
| 52 top_sites_->AddObserver(this); | 53 top_sites_->AddObserver(this); |
| 53 } | 54 } |
| 54 | 55 |
| 55 void TestTopSitesObserver::TopSitesLoaded(history::TopSites* top_sites) { | 56 void TestTopSitesObserver::TopSitesLoaded(history::TopSites* top_sites) { |
| 56 content::NotificationService::current()->Notify( | 57 content::NotificationService::current()->Notify( |
| 57 chrome::NOTIFICATION_TOP_SITES_LOADED, | 58 chrome::NOTIFICATION_TOP_SITES_LOADED, content::Source<Profile>(profile_), |
| 58 content::Source<Profile>(profile_), | |
| 59 content::Details<history::TopSites>(top_sites)); | 59 content::Details<history::TopSites>(top_sites)); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void TestTopSitesObserver::TopSitesChanged(history::TopSites* top_sites) { | 62 void TestTopSitesObserver::TopSitesChanged(history::TopSites* top_sites) { |
| 63 content::NotificationService::current()->Notify( | 63 content::NotificationService::current()->Notify( |
| 64 chrome::NOTIFICATION_TOP_SITES_CHANGED, | 64 chrome::NOTIFICATION_TOP_SITES_CHANGED, |
| 65 content::Source<Profile>(profile_), | 65 content::Source<Profile>(profile_), |
| 66 content::NotificationService::NoDetails()); | 66 content::NotificationService::NoDetails()); |
| 67 } | 67 } |
| 68 | 68 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 // Waits for top sites to finish processing a task. This is useful if you need | 229 // Waits for top sites to finish processing a task. This is useful if you need |
| 230 // to wait until top sites finishes processing a task. | 230 // to wait until top sites finishes processing a task. |
| 231 void WaitForTopSites() { | 231 void WaitForTopSites() { |
| 232 top_sites()->backend_->DoEmptyRequest( | 232 top_sites()->backend_->DoEmptyRequest( |
| 233 base::Bind(&TopSitesImplTest::QuitCallback, base::Unretained(this)), | 233 base::Bind(&TopSitesImplTest::QuitCallback, base::Unretained(this)), |
| 234 &top_sites_tracker_); | 234 &top_sites_tracker_); |
| 235 base::MessageLoop::current()->Run(); | 235 base::MessageLoop::current()->Run(); |
| 236 } | 236 } |
| 237 | 237 |
| 238 TopSitesImpl* top_sites() { | 238 TopSitesImpl* top_sites() { |
| 239 return static_cast<TopSitesImpl*>(profile_->GetTopSites()); | 239 return static_cast<TopSitesImpl*>( |
| 240 TopSitesFactory::GetForProfile(profile_).get()); | |
| 240 } | 241 } |
| 241 TestingProfile* profile() {return profile_.get();} | 242 TestingProfile* profile() {return profile_.get();} |
| 242 HistoryService* history_service() { | 243 HistoryService* history_service() { |
| 243 return HistoryServiceFactory::GetForProfile(profile_.get(), | 244 return HistoryServiceFactory::GetForProfile(profile_.get(), |
| 244 Profile::EXPLICIT_ACCESS); | 245 Profile::EXPLICIT_ACCESS); |
| 245 } | 246 } |
| 246 | 247 |
| 247 MostVisitedURLList GetPrepopulatePages() { | 248 MostVisitedURLList GetPrepopulatePages() { |
| 248 return top_sites()->GetPrepopulatePages(); | 249 return top_sites()->GetPrepopulatePages(); |
| 249 } | 250 } |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 362 void EmptyThreadSafeCache() { | 363 void EmptyThreadSafeCache() { |
| 363 base::AutoLock lock(top_sites()->lock_); | 364 base::AutoLock lock(top_sites()->lock_); |
| 364 MostVisitedURLList empty; | 365 MostVisitedURLList empty; |
| 365 top_sites()->thread_safe_cache_->SetTopSites(empty); | 366 top_sites()->thread_safe_cache_->SetTopSites(empty); |
| 366 } | 367 } |
| 367 | 368 |
| 368 void CreateTopSitesAndObserver() { | 369 void CreateTopSitesAndObserver() { |
| 369 if (top_sites_observer_) | 370 if (top_sites_observer_) |
| 370 top_sites_observer_.reset(); | 371 top_sites_observer_.reset(); |
| 371 | 372 |
| 372 profile_->CreateTopSites(); | 373 profile_->CreateTopSitesService(); |
| 373 top_sites_observer_.reset( | 374 top_sites_observer_.reset( |
| 374 new TestTopSitesObserver(profile_.get(), profile_->GetTopSites())); | 375 new TestTopSitesObserver( |
| 376 profile_.get(), | |
|
Bernhard Bauer
2015/01/08 10:22:05
Indentation: four spaces more than the previous li
Jitu( very slow this week)
2015/01/12 11:30:08
Done.
seems git cl format not worked here :(
| |
| 377 TopSitesFactory::GetForProfile(profile_)); | |
| 375 } | 378 } |
| 376 | 379 |
| 377 private: | 380 private: |
| 378 base::MessageLoopForUI message_loop_; | 381 base::MessageLoopForUI message_loop_; |
| 379 content::TestBrowserThread ui_thread_; | 382 content::TestBrowserThread ui_thread_; |
| 380 content::TestBrowserThread db_thread_; | 383 content::TestBrowserThread db_thread_; |
| 381 scoped_ptr<TestingProfile> profile_; | 384 scoped_ptr<TestingProfile> profile_; |
| 382 scoped_ptr<TestTopSitesObserver> top_sites_observer_; | 385 scoped_ptr<TestTopSitesObserver> top_sites_observer_; |
| 383 // To cancel HistoryService tasks. | 386 // To cancel HistoryService tasks. |
| 384 base::CancelableTaskTracker history_tracker_; | 387 base::CancelableTaskTracker history_tracker_; |
| (...skipping 1297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1682 ASSERT_EQ(orig_thumbnail.getSize(), thumbnail.getSize()); | 1685 ASSERT_EQ(orig_thumbnail.getSize(), thumbnail.getSize()); |
| 1683 orig_thumbnail.lockPixels(); | 1686 orig_thumbnail.lockPixels(); |
| 1684 thumbnail.lockPixels(); | 1687 thumbnail.lockPixels(); |
| 1685 EXPECT_EQ(0, memcmp(orig_thumbnail.getPixels(), thumbnail.getPixels(), | 1688 EXPECT_EQ(0, memcmp(orig_thumbnail.getPixels(), thumbnail.getPixels(), |
| 1686 orig_thumbnail.getSize())); | 1689 orig_thumbnail.getSize())); |
| 1687 thumbnail.unlockPixels(); | 1690 thumbnail.unlockPixels(); |
| 1688 orig_thumbnail.unlockPixels(); | 1691 orig_thumbnail.unlockPixels(); |
| 1689 } | 1692 } |
| 1690 | 1693 |
| 1691 } // namespace history | 1694 } // namespace history |
| OLD | NEW |