| 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" | 16 #include "sync/internal_api/public/util/weak_handle.h" |
| 17 #include "sync/notifier/fake_invalidation_handler.h" | 17 #include "sync/notifier/fake_invalidation_handler.h" |
| 18 #include "sync/notifier/invalidation_state_tracker.h" | 18 #include "sync/notifier/invalidation_state_tracker.h" |
| 19 #include "sync/notifier/invalidator_test_template.h" | 19 #include "sync/notifier/invalidator_test_template.h" |
| 20 #include "sync/notifier/object_id_invalidation_map_test_util.h" | |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 21 |
| 23 namespace syncer { | 22 namespace syncer { |
| 24 | 23 |
| 25 namespace { | 24 namespace { |
| 26 | 25 |
| 27 class NonBlockingInvalidatorTestDelegate { | 26 class NonBlockingInvalidatorTestDelegate { |
| 28 public: | 27 public: |
| 29 NonBlockingInvalidatorTestDelegate() : io_thread_("IO thread") {} | 28 NonBlockingInvalidatorTestDelegate() : io_thread_("IO thread") {} |
| 30 | 29 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 42 options.message_loop_type = base::MessageLoop::TYPE_IO; | 41 options.message_loop_type = base::MessageLoop::TYPE_IO; |
| 43 io_thread_.StartWithOptions(options); | 42 io_thread_.StartWithOptions(options); |
| 44 request_context_getter_ = | 43 request_context_getter_ = |
| 45 new net::TestURLRequestContextGetter(io_thread_.message_loop_proxy()); | 44 new net::TestURLRequestContextGetter(io_thread_.message_loop_proxy()); |
| 46 notifier::NotifierOptions invalidator_options; | 45 notifier::NotifierOptions invalidator_options; |
| 47 invalidator_options.request_context_getter = request_context_getter_; | 46 invalidator_options.request_context_getter = request_context_getter_; |
| 48 invalidator_.reset( | 47 invalidator_.reset( |
| 49 new NonBlockingInvalidator( | 48 new NonBlockingInvalidator( |
| 50 invalidator_options, | 49 invalidator_options, |
| 51 invalidator_client_id, | 50 invalidator_client_id, |
| 52 InvalidationStateMap(), | 51 UnackedInvalidationStorageMap(), |
| 53 initial_state, | 52 initial_state, |
| 54 MakeWeakHandle(invalidation_state_tracker), | 53 MakeWeakHandle(invalidation_state_tracker), |
| 55 "fake_client_info")); | 54 "fake_client_info")); |
| 56 } | 55 } |
| 57 | 56 |
| 58 Invalidator* GetInvalidator() { | 57 Invalidator* GetInvalidator() { |
| 59 return invalidator_.get(); | 58 return invalidator_.get(); |
| 60 } | 59 } |
| 61 | 60 |
| 62 void DestroyInvalidator() { | 61 void DestroyInvalidator() { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 74 base::Bind(&base::DoNothing), | 73 base::Bind(&base::DoNothing), |
| 75 run_loop.QuitClosure())); | 74 run_loop.QuitClosure())); |
| 76 run_loop.Run(); | 75 run_loop.Run(); |
| 77 } | 76 } |
| 78 | 77 |
| 79 void TriggerOnInvalidatorStateChange(InvalidatorState state) { | 78 void TriggerOnInvalidatorStateChange(InvalidatorState state) { |
| 80 invalidator_->OnInvalidatorStateChange(state); | 79 invalidator_->OnInvalidatorStateChange(state); |
| 81 } | 80 } |
| 82 | 81 |
| 83 void TriggerOnIncomingInvalidation( | 82 void TriggerOnIncomingInvalidation( |
| 84 const ObjectIdInvalidationMap& invalidation_map) { | 83 const ObjectIdInvalidationMap& invalidations) { |
| 85 invalidator_->OnIncomingInvalidation(invalidation_map); | 84 invalidator_->OnIncomingInvalidation(invalidations); |
| 86 } | 85 } |
| 87 | 86 |
| 88 private: | 87 private: |
| 89 base::MessageLoop message_loop_; | 88 base::MessageLoop message_loop_; |
| 90 base::Thread io_thread_; | 89 base::Thread io_thread_; |
| 91 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 90 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
| 92 scoped_ptr<NonBlockingInvalidator> invalidator_; | 91 scoped_ptr<NonBlockingInvalidator> invalidator_; |
| 93 }; | 92 }; |
| 94 | 93 |
| 95 INSTANTIATE_TYPED_TEST_CASE_P( | 94 INSTANTIATE_TYPED_TEST_CASE_P( |
| 96 NonBlockingInvalidatorTest, InvalidatorTest, | 95 NonBlockingInvalidatorTest, InvalidatorTest, |
| 97 NonBlockingInvalidatorTestDelegate); | 96 NonBlockingInvalidatorTestDelegate); |
| 98 | 97 |
| 99 } // namespace | 98 } // namespace |
| 100 | 99 |
| 101 } // namespace syncer | 100 } // namespace syncer |
| OLD | NEW |