OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ios/chrome/browser/browser_state/test_chrome_browser_state.h" | 5 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
353 return true; | 353 return true; |
354 } | 354 } |
355 | 355 |
356 void TestChromeBrowserState::DestroyHistoryService() { | 356 void TestChromeBrowserState::DestroyHistoryService() { |
357 history::HistoryService* history_service = | 357 history::HistoryService* history_service = |
358 ios::HistoryServiceFactory::GetInstance()->GetForBrowserStateIfExists( | 358 ios::HistoryServiceFactory::GetInstance()->GetForBrowserStateIfExists( |
359 this, ServiceAccessType::EXPLICIT_ACCESS); | 359 this, ServiceAccessType::EXPLICIT_ACCESS); |
360 if (!history_service) | 360 if (!history_service) |
361 return; | 361 return; |
362 | 362 |
363 base::RunLoop run_loop; | |
364 | |
363 history_service->ClearCachedDataForContextID(0); | 365 history_service->ClearCachedDataForContextID(0); |
364 history_service->SetOnBackendDestroyTask( | 366 history_service->SetOnBackendDestroyTask(run_loop.QuitWhenIdleClosure()); |
365 base::MessageLoop::QuitWhenIdleClosure()); | |
366 history_service->Shutdown(); | 367 history_service->Shutdown(); |
367 history_service = nullptr; | 368 history_service = nullptr; |
368 | 369 |
369 // Resetting the testing factory force the destruction of the current | 370 // Resetting the testing factory force the destruction of the current |
370 // HistoryService instance associated with the TestChromeBrowserState. | 371 // HistoryService instance associated with the TestChromeBrowserState. |
371 ios::HistoryServiceFactory::GetInstance()->SetTestingFactory(this, nullptr); | 372 ios::HistoryServiceFactory::GetInstance()->SetTestingFactory(this, nullptr); |
372 | 373 |
373 // Wait for the backend class to terminate before deleting the files and | 374 // Wait for the backend class to terminate before deleting the files and |
374 // moving to the next test. Note: if this never terminates, somebody is | 375 // moving to the next test. Note: if this never terminates, somebody is |
375 // probably leaking a reference to the history backend, so it never calls | 376 // probably leaking a reference to the history backend, so it never calls |
376 // our destroy task. | 377 // our destroy task. |
377 base::MessageLoop::current()->Run(); | 378 run_loop.Run(); |
378 | 379 |
379 // Make sure we don't have any event pending that could disrupt the next | 380 // Make sure we don't have any event pending that could disrupt the next |
380 // test. | 381 // test. |
381 base::ThreadTaskRunnerHandle::Get()->PostTask( | 382 base::RunLoop().RunUntilIdle(); |
sdefresne
2016/09/07 11:06:36
Why use a second base::RunLoop() object here inste
fdoray
2016/09/07 13:16:03
A RunLoop can't be reused.
In the latest patch se
| |
382 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | |
383 base::MessageLoop::current()->Run(); | |
384 } | 383 } |
385 | 384 |
386 syncable_prefs::TestingPrefServiceSyncable* | 385 syncable_prefs::TestingPrefServiceSyncable* |
387 TestChromeBrowserState::GetTestingPrefService() { | 386 TestChromeBrowserState::GetTestingPrefService() { |
388 DCHECK(prefs_); | 387 DCHECK(prefs_); |
389 DCHECK(testing_prefs_); | 388 DCHECK(testing_prefs_); |
390 return testing_prefs_; | 389 return testing_prefs_; |
391 } | 390 } |
392 | 391 |
393 TestChromeBrowserState::Builder::Builder() : build_called_(false) {} | 392 TestChromeBrowserState::Builder::Builder() : build_called_(false) {} |
(...skipping 25 matching lines...) Expand all Loading... | |
419 pref_service_ = std::move(prefs); | 418 pref_service_ = std::move(prefs); |
420 } | 419 } |
421 | 420 |
422 std::unique_ptr<TestChromeBrowserState> | 421 std::unique_ptr<TestChromeBrowserState> |
423 TestChromeBrowserState::Builder::Build() { | 422 TestChromeBrowserState::Builder::Build() { |
424 DCHECK(!build_called_); | 423 DCHECK(!build_called_); |
425 return base::WrapUnique(new TestChromeBrowserState( | 424 return base::WrapUnique(new TestChromeBrowserState( |
426 state_path_, std::move(pref_service_), testing_factories_, | 425 state_path_, std::move(pref_service_), testing_factories_, |
427 refcounted_testing_factories_)); | 426 refcounted_testing_factories_)); |
428 } | 427 } |
OLD | NEW |