| 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 "chrome/browser/search_engines/template_url_service_test_util.h" | 5 #include "chrome/browser/search_engines/template_url_service_test_util.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #endif | 29 #endif |
| 30 | 30 |
| 31 using content::BrowserThread; | 31 using content::BrowserThread; |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 // A callback used to coordinate when the database has finished processing | 35 // A callback used to coordinate when the database has finished processing |
| 36 // requests. See note in BlockTillServiceProcessesRequests for details. | 36 // requests. See note in BlockTillServiceProcessesRequests for details. |
| 37 // | 37 // |
| 38 // Schedules a QuitClosure on the message loop it was created with. | 38 // Schedules a QuitClosure on the message loop it was created with. |
| 39 void QuitCallback(MessageLoop* message_loop) { | 39 void QuitCallback(base::MessageLoop* message_loop) { |
| 40 message_loop->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 40 message_loop->PostTask(FROM_HERE, base::MessageLoop::QuitClosure()); |
| 41 } | 41 } |
| 42 | 42 |
| 43 // Blocks the caller until thread has finished servicing all pending | 43 // Blocks the caller until thread has finished servicing all pending |
| 44 // requests. | 44 // requests. |
| 45 static void WaitForThreadToProcessRequests(BrowserThread::ID identifier) { | 45 static void WaitForThreadToProcessRequests(BrowserThread::ID identifier) { |
| 46 // Schedule a task on the thread that is processed after all | 46 // Schedule a task on the thread that is processed after all |
| 47 // pending requests on the thread. | 47 // pending requests on the thread. |
| 48 BrowserThread::PostTask(identifier, FROM_HERE, | 48 BrowserThread::PostTask( |
| 49 base::Bind(&QuitCallback, MessageLoop::current())); | 49 identifier, |
| 50 MessageLoop::current()->Run(); | 50 FROM_HERE, |
| 51 base::Bind(&QuitCallback, base::MessageLoop::current())); |
| 52 base::MessageLoop::current()->Run(); |
| 51 } | 53 } |
| 52 | 54 |
| 53 } // namespace | 55 } // namespace |
| 54 | 56 |
| 55 // Trivial subclass of TemplateURLService that records the last invocation of | 57 // Trivial subclass of TemplateURLService that records the last invocation of |
| 56 // SetKeywordSearchTermsForURL. | 58 // SetKeywordSearchTermsForURL. |
| 57 class TestingTemplateURLService : public TemplateURLService { | 59 class TestingTemplateURLService : public TemplateURLService { |
| 58 public: | 60 public: |
| 59 static BrowserContextKeyedService* Build(content::BrowserContext* profile) { | 61 static BrowserContextKeyedService* Build(content::BrowserContext* profile) { |
| 60 return new TestingTemplateURLService(static_cast<Profile*>(profile)); | 62 return new TestingTemplateURLService(static_cast<Profile*>(profile)); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 // Note that we must ensure the DB thread is stopped after WDS | 130 // Note that we must ensure the DB thread is stopped after WDS |
| 129 // shutdown (so it can commit pending transactions) but before | 131 // shutdown (so it can commit pending transactions) but before |
| 130 // deleting the test profile directory, otherwise we may not be | 132 // deleting the test profile directory, otherwise we may not be |
| 131 // able to delete it due to an open transaction. | 133 // able to delete it due to an open transaction. |
| 132 // Schedule another task on the DB thread to notify us that it's safe to | 134 // Schedule another task on the DB thread to notify us that it's safe to |
| 133 // carry on with the test. | 135 // carry on with the test. |
| 134 base::WaitableEvent done(false, false); | 136 base::WaitableEvent done(false, false); |
| 135 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 137 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 136 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); | 138 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); |
| 137 done.Wait(); | 139 done.Wait(); |
| 138 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 140 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 139 MessageLoop::current()->Run(); | 141 base::MessageLoop::QuitClosure()); |
| 142 base::MessageLoop::current()->Run(); |
| 140 db_thread_.Stop(); | 143 db_thread_.Stop(); |
| 141 | 144 |
| 142 UIThreadSearchTermsData::SetGoogleBaseURL(std::string()); | 145 UIThreadSearchTermsData::SetGoogleBaseURL(std::string()); |
| 143 | 146 |
| 144 // Flush the message loop to make application verifiers happy. | 147 // Flush the message loop to make application verifiers happy. |
| 145 message_loop_.RunUntilIdle(); | 148 message_loop_.RunUntilIdle(); |
| 146 } | 149 } |
| 147 | 150 |
| 148 void TemplateURLServiceTestUtil::OnTemplateURLServiceChanged() { | 151 void TemplateURLServiceTestUtil::OnTemplateURLServiceChanged() { |
| 149 changed_count_++; | 152 changed_count_++; |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 return profile_.get(); | 279 return profile_.get(); |
| 277 } | 280 } |
| 278 | 281 |
| 279 void TemplateURLServiceTestUtil::StartIOThread() { | 282 void TemplateURLServiceTestUtil::StartIOThread() { |
| 280 io_thread_.StartIOThread(); | 283 io_thread_.StartIOThread(); |
| 281 } | 284 } |
| 282 | 285 |
| 283 void TemplateURLServiceTestUtil::PumpLoop() { | 286 void TemplateURLServiceTestUtil::PumpLoop() { |
| 284 message_loop_.RunUntilIdle(); | 287 message_loop_.RunUntilIdle(); |
| 285 } | 288 } |
| OLD | NEW |