| 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 "base/message_loop/message_loop_proxy.h" | 5 #include "base/message_loop/message_loop_proxy.h" |
| 6 #include "base/synchronization/waitable_event.h" | 6 #include "base/synchronization/waitable_event.h" |
| 7 #include "base/threading/thread.h" | 7 #include "base/threading/thread.h" |
| 8 #include "net/test/spawned_test_server/spawned_test_server.h" | 8 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 9 #include "net/url_request/test_url_fetcher_factory.h" | 9 #include "net/url_request/test_url_fetcher_factory.h" |
| 10 #include "net/url_request/url_fetcher_delegate.h" | 10 #include "net/url_request/url_fetcher_delegate.h" |
| 11 #include "net/url_request/url_request_test_util.h" | 11 #include "net/url_request/url_request_test_util.h" |
| 12 #include "sync/internal_api/public/base/cancelation_signal.h" |
| 12 #include "sync/internal_api/public/http_bridge.h" | 13 #include "sync/internal_api/public/http_bridge.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 15 |
| 15 namespace syncer { | 16 namespace syncer { |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 // TODO(timsteele): Should use PathService here. See Chromium Issue 3113. | 19 // TODO(timsteele): Should use PathService here. See Chromium Issue 3113. |
| 19 const base::FilePath::CharType kDocRoot[] = | 20 const base::FilePath::CharType kDocRoot[] = |
| 20 FILE_PATH_LITERAL("chrome/test/data"); | 21 FILE_PATH_LITERAL("chrome/test/data"); |
| 21 } | 22 } |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 // Abort should have held a reference. | 401 // Abort should have held a reference. |
| 401 io_waiter.Signal(); | 402 io_waiter.Signal(); |
| 402 | 403 |
| 403 // Done. | 404 // Done. |
| 404 sync_thread.Stop(); | 405 sync_thread.Stop(); |
| 405 io_thread()->Stop(); | 406 io_thread()->Stop(); |
| 406 } | 407 } |
| 407 | 408 |
| 408 void HttpBridgeRunOnSyncThread( | 409 void HttpBridgeRunOnSyncThread( |
| 409 net::URLRequestContextGetter* baseline_context_getter, | 410 net::URLRequestContextGetter* baseline_context_getter, |
| 411 CancelationSignal* factory_cancelation_signal, |
| 410 syncer::HttpPostProviderFactory** bridge_factory_out, | 412 syncer::HttpPostProviderFactory** bridge_factory_out, |
| 411 syncer::HttpPostProviderInterface** bridge_out, | 413 syncer::HttpPostProviderInterface** bridge_out, |
| 412 base::WaitableEvent* signal_when_created, | 414 base::WaitableEvent* signal_when_created, |
| 413 base::WaitableEvent* wait_for_shutdown) { | 415 base::WaitableEvent* wait_for_shutdown) { |
| 414 scoped_ptr<syncer::HttpPostProviderFactory> bridge_factory( | 416 scoped_ptr<syncer::HttpBridgeFactory> bridge_factory( |
| 415 new syncer::HttpBridgeFactory(baseline_context_getter, | 417 new syncer::HttpBridgeFactory(baseline_context_getter, |
| 416 "test", | 418 NetworkTimeUpdateCallback(), |
| 417 NetworkTimeUpdateCallback())); | 419 factory_cancelation_signal)); |
| 420 bridge_factory->Init("test"); |
| 418 *bridge_factory_out = bridge_factory.get(); | 421 *bridge_factory_out = bridge_factory.get(); |
| 419 | 422 |
| 420 HttpPostProviderInterface* bridge = bridge_factory->Create(); | 423 HttpPostProviderInterface* bridge = bridge_factory->Create(); |
| 421 *bridge_out = bridge; | 424 *bridge_out = bridge; |
| 422 | 425 |
| 423 signal_when_created->Signal(); | 426 signal_when_created->Signal(); |
| 424 wait_for_shutdown->Wait(); | 427 wait_for_shutdown->Wait(); |
| 425 | 428 |
| 426 bridge_factory->Destroy(bridge); | 429 bridge_factory->Destroy(bridge); |
| 427 } | 430 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 440 | 443 |
| 441 syncer::HttpPostProviderFactory* factory = NULL; | 444 syncer::HttpPostProviderFactory* factory = NULL; |
| 442 syncer::HttpPostProviderInterface* bridge = NULL; | 445 syncer::HttpPostProviderInterface* bridge = NULL; |
| 443 | 446 |
| 444 scoped_refptr<net::URLRequestContextGetter> baseline_context_getter( | 447 scoped_refptr<net::URLRequestContextGetter> baseline_context_getter( |
| 445 new net::TestURLRequestContextGetter(io_thread()->message_loop_proxy())); | 448 new net::TestURLRequestContextGetter(io_thread()->message_loop_proxy())); |
| 446 | 449 |
| 447 base::WaitableEvent signal_when_created(false, false); | 450 base::WaitableEvent signal_when_created(false, false); |
| 448 base::WaitableEvent wait_for_shutdown(false, false); | 451 base::WaitableEvent wait_for_shutdown(false, false); |
| 449 | 452 |
| 453 CancelationSignal factory_cancelation_signal; |
| 454 |
| 450 // Create bridge factory and factory on sync thread and wait for the creation | 455 // Create bridge factory and factory on sync thread and wait for the creation |
| 451 // to finish. | 456 // to finish. |
| 452 sync_thread.message_loop()->PostTask(FROM_HERE, | 457 sync_thread.message_loop()->PostTask(FROM_HERE, |
| 453 base::Bind(&HttpBridgeRunOnSyncThread, | 458 base::Bind(&HttpBridgeRunOnSyncThread, |
| 454 base::Unretained(baseline_context_getter.get()), | 459 base::Unretained(baseline_context_getter.get()), |
| 455 &factory, &bridge, &signal_when_created, &wait_for_shutdown)); | 460 &factory_cancelation_signal ,&factory, &bridge, |
| 461 &signal_when_created, &wait_for_shutdown)); |
| 456 signal_when_created.Wait(); | 462 signal_when_created.Wait(); |
| 457 | 463 |
| 458 // Simulate sync shutdown by aborting bridge and shutting down factory on | 464 // Simulate sync shutdown by aborting bridge and shutting down factory on |
| 459 // frontend. | 465 // frontend. |
| 460 bridge->Abort(); | 466 bridge->Abort(); |
| 461 factory->Shutdown(); | 467 factory_cancelation_signal.RequestStop(); |
| 462 | 468 |
| 463 // Wait for sync's RequestContextGetter to be cleared on IO thread and | 469 // Wait for sync's RequestContextGetter to be cleared on IO thread and |
| 464 // check for reference count. | 470 // check for reference count. |
| 465 base::WaitableEvent signal_wait_start(false, false); | 471 base::WaitableEvent signal_wait_start(false, false); |
| 466 base::WaitableEvent wait_done(false, false); | 472 base::WaitableEvent wait_done(false, false); |
| 467 io_thread()->message_loop()->PostTask( | 473 io_thread()->message_loop()->PostTask( |
| 468 FROM_HERE, | 474 FROM_HERE, |
| 469 base::Bind(&WaitOnIOThread, &signal_wait_start, &wait_done)); | 475 base::Bind(&WaitOnIOThread, &signal_wait_start, &wait_done)); |
| 470 signal_wait_start.Wait(); | 476 signal_wait_start.Wait(); |
| 471 // |baseline_context_getter| should have only one reference from local | 477 // |baseline_context_getter| should have only one reference from local |
| 472 // variable. | 478 // variable. |
| 473 EXPECT_TRUE(baseline_context_getter->HasOneRef()); | 479 EXPECT_TRUE(baseline_context_getter->HasOneRef()); |
| 474 baseline_context_getter = NULL; | 480 baseline_context_getter = NULL; |
| 475 | 481 |
| 476 // Unblock and stop IO thread before sync thread. | 482 // Unblock and stop IO thread before sync thread. |
| 477 wait_done.Signal(); | 483 wait_done.Signal(); |
| 478 io_thread()->Stop(); | 484 io_thread()->Stop(); |
| 479 | 485 |
| 480 // Unblock and stop sync thread. | 486 // Unblock and stop sync thread. |
| 481 wait_for_shutdown.Signal(); | 487 wait_for_shutdown.Signal(); |
| 482 sync_thread.Stop(); | 488 sync_thread.Stop(); |
| 483 } | 489 } |
| 484 | 490 |
| 485 } // namespace syncer | 491 } // namespace syncer |
| OLD | NEW |