| 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/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 io_thread()->Stop(); | 468 io_thread()->Stop(); |
| 469 } | 469 } |
| 470 | 470 |
| 471 void HttpBridgeRunOnSyncThread( | 471 void HttpBridgeRunOnSyncThread( |
| 472 net::URLRequestContextGetter* baseline_context_getter, | 472 net::URLRequestContextGetter* baseline_context_getter, |
| 473 CancelationSignal* factory_cancelation_signal, | 473 CancelationSignal* factory_cancelation_signal, |
| 474 syncer::HttpPostProviderFactory** bridge_factory_out, | 474 syncer::HttpPostProviderFactory** bridge_factory_out, |
| 475 syncer::HttpPostProviderInterface** bridge_out, | 475 syncer::HttpPostProviderInterface** bridge_out, |
| 476 base::WaitableEvent* signal_when_created, | 476 base::WaitableEvent* signal_when_created, |
| 477 base::WaitableEvent* wait_for_shutdown) { | 477 base::WaitableEvent* wait_for_shutdown) { |
| 478 scoped_ptr<syncer::HttpBridgeFactory> bridge_factory( | 478 std::unique_ptr<syncer::HttpBridgeFactory> bridge_factory( |
| 479 new syncer::HttpBridgeFactory(baseline_context_getter, | 479 new syncer::HttpBridgeFactory(baseline_context_getter, |
| 480 NetworkTimeUpdateCallback(), | 480 NetworkTimeUpdateCallback(), |
| 481 factory_cancelation_signal)); | 481 factory_cancelation_signal)); |
| 482 bridge_factory->Init("test", BindToTrackerCallback()); | 482 bridge_factory->Init("test", BindToTrackerCallback()); |
| 483 *bridge_factory_out = bridge_factory.get(); | 483 *bridge_factory_out = bridge_factory.get(); |
| 484 | 484 |
| 485 HttpPostProviderInterface* bridge = bridge_factory->Create(); | 485 HttpPostProviderInterface* bridge = bridge_factory->Create(); |
| 486 *bridge_out = bridge; | 486 *bridge_out = bridge; |
| 487 | 487 |
| 488 signal_when_created->Signal(); | 488 signal_when_created->Signal(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 TEST_F(MAYBE_SyncHttpBridgeTest, EarlyAbortFactory) { | 555 TEST_F(MAYBE_SyncHttpBridgeTest, EarlyAbortFactory) { |
| 556 // 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 |
| 557 // simplicity, this test uses only one thread. | 557 // simplicity, this test uses only one thread. |
| 558 | 558 |
| 559 scoped_refptr<net::URLRequestContextGetter> baseline_context_getter( | 559 scoped_refptr<net::URLRequestContextGetter> baseline_context_getter( |
| 560 new net::TestURLRequestContextGetter(io_thread()->task_runner())); | 560 new net::TestURLRequestContextGetter(io_thread()->task_runner())); |
| 561 CancelationSignal release_request_context_signal; | 561 CancelationSignal release_request_context_signal; |
| 562 | 562 |
| 563 // UI Thread: Initialize the HttpBridgeFactory. The next step would be to | 563 // UI Thread: Initialize the HttpBridgeFactory. The next step would be to |
| 564 // post a task to SBH::Core to have it initialized. | 564 // post a task to SBH::Core to have it initialized. |
| 565 scoped_ptr<syncer::HttpBridgeFactory> factory( | 565 std::unique_ptr<syncer::HttpBridgeFactory> factory(new HttpBridgeFactory( |
| 566 new HttpBridgeFactory(baseline_context_getter.get(), | 566 baseline_context_getter.get(), NetworkTimeUpdateCallback(), |
| 567 NetworkTimeUpdateCallback(), | 567 &release_request_context_signal)); |
| 568 &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 |