OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include "base/bit_cast.h" | 8 #include "base/bit_cast.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 io_waiter.Signal(); | 458 io_waiter.Signal(); |
459 | 459 |
460 // Done. | 460 // Done. |
461 sync_thread.Stop(); | 461 sync_thread.Stop(); |
462 io_thread()->Stop(); | 462 io_thread()->Stop(); |
463 } | 463 } |
464 | 464 |
465 void HttpBridgeRunOnSyncThread( | 465 void HttpBridgeRunOnSyncThread( |
466 net::URLRequestContextGetter* baseline_context_getter, | 466 net::URLRequestContextGetter* baseline_context_getter, |
467 CancelationSignal* factory_cancelation_signal, | 467 CancelationSignal* factory_cancelation_signal, |
468 syncer::HttpPostProviderFactory** bridge_factory_out, | 468 HttpPostProviderFactory** bridge_factory_out, |
469 syncer::HttpPostProviderInterface** bridge_out, | 469 HttpPostProviderInterface** bridge_out, |
470 base::WaitableEvent* signal_when_created, | 470 base::WaitableEvent* signal_when_created, |
471 base::WaitableEvent* wait_for_shutdown) { | 471 base::WaitableEvent* wait_for_shutdown) { |
472 std::unique_ptr<syncer::HttpBridgeFactory> bridge_factory( | 472 std::unique_ptr<HttpBridgeFactory> bridge_factory(new HttpBridgeFactory( |
473 new syncer::HttpBridgeFactory(baseline_context_getter, | 473 baseline_context_getter, NetworkTimeUpdateCallback(), |
474 NetworkTimeUpdateCallback(), | 474 factory_cancelation_signal)); |
475 factory_cancelation_signal)); | |
476 bridge_factory->Init("test", BindToTrackerCallback()); | 475 bridge_factory->Init("test", BindToTrackerCallback()); |
477 *bridge_factory_out = bridge_factory.get(); | 476 *bridge_factory_out = bridge_factory.get(); |
478 | 477 |
479 HttpPostProviderInterface* bridge = bridge_factory->Create(); | 478 HttpPostProviderInterface* bridge = bridge_factory->Create(); |
480 *bridge_out = bridge; | 479 *bridge_out = bridge; |
481 | 480 |
482 signal_when_created->Signal(); | 481 signal_when_created->Signal(); |
483 wait_for_shutdown->Wait(); | 482 wait_for_shutdown->Wait(); |
484 | 483 |
485 bridge_factory->Destroy(bridge); | 484 bridge_factory->Destroy(bridge); |
486 } | 485 } |
487 | 486 |
488 void WaitOnIOThread(base::WaitableEvent* signal_wait_start, | 487 void WaitOnIOThread(base::WaitableEvent* signal_wait_start, |
489 base::WaitableEvent* wait_done) { | 488 base::WaitableEvent* wait_done) { |
490 signal_wait_start->Signal(); | 489 signal_wait_start->Signal(); |
491 wait_done->Wait(); | 490 wait_done->Wait(); |
492 } | 491 } |
493 | 492 |
494 // Tests RequestContextGetter is properly released on IO thread even when | 493 // Tests RequestContextGetter is properly released on IO thread even when |
495 // IO thread stops before sync thread. | 494 // IO thread stops before sync thread. |
496 TEST_F(MAYBE_SyncHttpBridgeTest, RequestContextGetterReleaseOrder) { | 495 TEST_F(MAYBE_SyncHttpBridgeTest, RequestContextGetterReleaseOrder) { |
497 base::Thread sync_thread("SyncThread"); | 496 base::Thread sync_thread("SyncThread"); |
498 sync_thread.Start(); | 497 sync_thread.Start(); |
499 | 498 |
500 syncer::HttpPostProviderFactory* factory = NULL; | 499 HttpPostProviderFactory* factory = NULL; |
501 syncer::HttpPostProviderInterface* bridge = NULL; | 500 HttpPostProviderInterface* bridge = NULL; |
502 | 501 |
503 scoped_refptr<net::URLRequestContextGetter> baseline_context_getter( | 502 scoped_refptr<net::URLRequestContextGetter> baseline_context_getter( |
504 new net::TestURLRequestContextGetter(io_thread()->task_runner())); | 503 new net::TestURLRequestContextGetter(io_thread()->task_runner())); |
505 | 504 |
506 base::WaitableEvent signal_when_created( | 505 base::WaitableEvent signal_when_created( |
507 base::WaitableEvent::ResetPolicy::AUTOMATIC, | 506 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
508 base::WaitableEvent::InitialState::NOT_SIGNALED); | 507 base::WaitableEvent::InitialState::NOT_SIGNALED); |
509 base::WaitableEvent wait_for_shutdown( | 508 base::WaitableEvent wait_for_shutdown( |
510 base::WaitableEvent::ResetPolicy::AUTOMATIC, | 509 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
511 base::WaitableEvent::InitialState::NOT_SIGNALED); | 510 base::WaitableEvent::InitialState::NOT_SIGNALED); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 TEST_F(MAYBE_SyncHttpBridgeTest, EarlyAbortFactory) { | 555 TEST_F(MAYBE_SyncHttpBridgeTest, EarlyAbortFactory) { |
557 // In a real scenario, the following would happen on many threads. For | 556 // In a real scenario, the following would happen on many threads. For |
558 // simplicity, this test uses only one thread. | 557 // simplicity, this test uses only one thread. |
559 | 558 |
560 scoped_refptr<net::URLRequestContextGetter> baseline_context_getter( | 559 scoped_refptr<net::URLRequestContextGetter> baseline_context_getter( |
561 new net::TestURLRequestContextGetter(io_thread()->task_runner())); | 560 new net::TestURLRequestContextGetter(io_thread()->task_runner())); |
562 CancelationSignal release_request_context_signal; | 561 CancelationSignal release_request_context_signal; |
563 | 562 |
564 // UI Thread: Initialize the HttpBridgeFactory. The next step would be to | 563 // UI Thread: Initialize the HttpBridgeFactory. The next step would be to |
565 // post a task to SBH::Core to have it initialized. | 564 // post a task to SBH::Core to have it initialized. |
566 std::unique_ptr<syncer::HttpBridgeFactory> factory(new HttpBridgeFactory( | 565 std::unique_ptr<HttpBridgeFactory> factory(new HttpBridgeFactory( |
567 baseline_context_getter.get(), NetworkTimeUpdateCallback(), | 566 baseline_context_getter.get(), NetworkTimeUpdateCallback(), |
568 &release_request_context_signal)); | 567 &release_request_context_signal)); |
569 | 568 |
570 // UI Thread: A very early shutdown request arrives and executes on the UI | 569 // UI Thread: A very early shutdown request arrives and executes on the UI |
571 // thread before the posted sync thread task is run. | 570 // thread before the posted sync thread task is run. |
572 release_request_context_signal.Signal(); | 571 release_request_context_signal.Signal(); |
573 | 572 |
574 // Sync thread: Finally run the posted task, only to find that our | 573 // Sync thread: Finally run the posted task, only to find that our |
575 // HttpBridgeFactory has been neutered. Should not crash. | 574 // HttpBridgeFactory has been neutered. Should not crash. |
576 factory->Init("TestUserAgent", BindToTrackerCallback()); | 575 factory->Init("TestUserAgent", BindToTrackerCallback()); |
577 | 576 |
578 // At this point, attempting to use the factory would trigger a crash. Both | 577 // At this point, attempting to use the factory would trigger a crash. Both |
579 // this test and the real world code should make sure this never happens. | 578 // this test and the real world code should make sure this never happens. |
580 } | 579 } |
581 | 580 |
582 } // namespace syncer | 581 } // namespace syncer |
OLD | NEW |