| 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 "sync/notifier/non_blocking_invalidator.h" | 5 #include "sync/notifier/non_blocking_invalidator.h" |
| 6 | 6 |
| 7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
| 13 #include "google/cacheinvalidation/types.pb.h" | 13 #include "google/cacheinvalidation/types.pb.h" |
| 14 #include "jingle/notifier/base/fake_base_task.h" | 14 #include "jingle/notifier/base/fake_base_task.h" |
| 15 #include "net/url_request/url_request_test_util.h" | 15 #include "net/url_request/url_request_test_util.h" |
| 16 #include "sync/internal_api/public/util/weak_handle.h" | |
| 17 #include "sync/notifier/fake_invalidation_handler.h" | 16 #include "sync/notifier/fake_invalidation_handler.h" |
| 18 #include "sync/notifier/invalidation_state_tracker.h" | 17 #include "sync/notifier/invalidation_state_tracker.h" |
| 19 #include "sync/notifier/invalidator_test_template.h" | 18 #include "sync/notifier/invalidator_test_template.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 20 |
| 22 namespace syncer { | 21 namespace syncer { |
| 23 | 22 |
| 24 namespace { | 23 namespace { |
| 25 | 24 |
| 26 class NonBlockingInvalidatorTestDelegate { | 25 class NonBlockingInvalidatorTestDelegate { |
| 27 public: | 26 public: |
| 28 NonBlockingInvalidatorTestDelegate() : io_thread_("IO thread") {} | 27 NonBlockingInvalidatorTestDelegate() : io_thread_("IO thread") {} |
| 29 | 28 |
| 30 ~NonBlockingInvalidatorTestDelegate() { | 29 ~NonBlockingInvalidatorTestDelegate() { |
| 31 DestroyInvalidator(); | 30 DestroyInvalidator(); |
| 32 } | 31 } |
| 33 | 32 |
| 34 void CreateInvalidator( | 33 void CreateInvalidator( |
| 35 const std::string& invalidator_client_id, | 34 const std::string& invalidator_client_id, |
| 36 const std::string& initial_state, | 35 const std::string& initial_state, |
| 37 const base::WeakPtr<InvalidationStateTracker>& | 36 InvalidationStateTracker* invalidation_state_tracker) { |
| 38 invalidation_state_tracker) { | |
| 39 DCHECK(!invalidator_.get()); | 37 DCHECK(!invalidator_.get()); |
| 40 base::Thread::Options options; | 38 base::Thread::Options options; |
| 41 options.message_loop_type = base::MessageLoop::TYPE_IO; | 39 options.message_loop_type = base::MessageLoop::TYPE_IO; |
| 42 io_thread_.StartWithOptions(options); | 40 io_thread_.StartWithOptions(options); |
| 43 request_context_getter_ = | 41 request_context_getter_ = |
| 44 new net::TestURLRequestContextGetter(io_thread_.message_loop_proxy()); | 42 new net::TestURLRequestContextGetter(io_thread_.message_loop_proxy()); |
| 45 notifier::NotifierOptions notifier_options; | 43 notifier::NotifierOptions notifier_options; |
| 46 notifier_options.request_context_getter = request_context_getter_; | 44 notifier_options.request_context_getter = request_context_getter_; |
| 47 NetworkChannelCreator network_channel_creator = | 45 NetworkChannelCreator network_channel_creator = |
| 48 NonBlockingInvalidator::MakePushClientChannelCreator(notifier_options); | 46 NonBlockingInvalidator::MakePushClientChannelCreator(notifier_options); |
| 49 invalidator_.reset( | 47 invalidator_.reset( |
| 50 new NonBlockingInvalidator( | 48 new NonBlockingInvalidator( |
| 51 network_channel_creator, | 49 network_channel_creator, |
| 52 invalidator_client_id, | 50 invalidator_client_id, |
| 53 UnackedInvalidationsMap(), | 51 UnackedInvalidationsMap(), |
| 54 initial_state, | 52 initial_state, |
| 55 MakeWeakHandle(invalidation_state_tracker), | 53 invalidation_state_tracker, |
| 56 "fake_client_info", | 54 "fake_client_info", |
| 57 request_context_getter_)); | 55 request_context_getter_)); |
| 58 } | 56 } |
| 59 | 57 |
| 60 Invalidator* GetInvalidator() { | 58 Invalidator* GetInvalidator() { |
| 61 return invalidator_.get(); | 59 return invalidator_.get(); |
| 62 } | 60 } |
| 63 | 61 |
| 64 void DestroyInvalidator() { | 62 void DestroyInvalidator() { |
| 65 invalidator_.reset(); | 63 invalidator_.reset(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 94 scoped_ptr<NonBlockingInvalidator> invalidator_; | 92 scoped_ptr<NonBlockingInvalidator> invalidator_; |
| 95 }; | 93 }; |
| 96 | 94 |
| 97 INSTANTIATE_TYPED_TEST_CASE_P( | 95 INSTANTIATE_TYPED_TEST_CASE_P( |
| 98 NonBlockingInvalidatorTest, InvalidatorTest, | 96 NonBlockingInvalidatorTest, InvalidatorTest, |
| 99 NonBlockingInvalidatorTestDelegate); | 97 NonBlockingInvalidatorTestDelegate); |
| 100 | 98 |
| 101 } // namespace | 99 } // namespace |
| 102 | 100 |
| 103 } // namespace syncer | 101 } // namespace syncer |
| OLD | NEW |