OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/internal_api/sync_context_proxy_impl.h" | 5 #include "sync/internal_api/sync_context_proxy_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/memory/ptr_util.h" |
11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
12 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
13 #include "base/sequenced_task_runner.h" | 14 #include "base/sequenced_task_runner.h" |
14 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
15 #include "sync/internal_api/public/activation_context.h" | 16 #include "sync/internal_api/public/activation_context.h" |
16 #include "sync/internal_api/public/base/model_type.h" | 17 #include "sync/internal_api/public/base/model_type.h" |
17 #include "sync/internal_api/public/shared_model_type_processor.h" | 18 #include "sync/internal_api/public/shared_model_type_processor.h" |
18 #include "sync/internal_api/public/sync_context.h" | 19 #include "sync/internal_api/public/sync_context.h" |
19 #include "sync/internal_api/public/test/fake_model_type_service.h" | 20 #include "sync/internal_api/public/test/fake_model_type_service.h" |
20 #include "sync/sessions/model_type_registry.h" | 21 #include "sync/sessions/model_type_registry.h" |
(...skipping 26 matching lines...) Expand all Loading... |
47 // The sync thread could be shut down at any time without warning. This | 48 // The sync thread could be shut down at any time without warning. This |
48 // function simulates such an event. | 49 // function simulates such an event. |
49 void DisableSync() { registry_.reset(); } | 50 void DisableSync() { registry_.reset(); } |
50 | 51 |
51 void OnSyncStarting(SharedModelTypeProcessor* processor) { | 52 void OnSyncStarting(SharedModelTypeProcessor* processor) { |
52 processor->OnSyncStarting(base::Bind( | 53 processor->OnSyncStarting(base::Bind( |
53 &SyncContextProxyImplTest::OnReadyToConnect, base::Unretained(this))); | 54 &SyncContextProxyImplTest::OnReadyToConnect, base::Unretained(this))); |
54 } | 55 } |
55 | 56 |
56 void OnReadyToConnect(syncer::SyncError error, | 57 void OnReadyToConnect(syncer::SyncError error, |
57 scoped_ptr<ActivationContext> context) { | 58 std::unique_ptr<ActivationContext> context) { |
58 context_proxy_->ConnectTypeToSync(syncer::THEMES, std::move(context)); | 59 context_proxy_->ConnectTypeToSync(syncer::THEMES, std::move(context)); |
59 } | 60 } |
60 | 61 |
61 scoped_ptr<SharedModelTypeProcessor> CreateModelTypeProcessor() { | 62 std::unique_ptr<SharedModelTypeProcessor> CreateModelTypeProcessor() { |
62 scoped_ptr<SharedModelTypeProcessor> processor = | 63 std::unique_ptr<SharedModelTypeProcessor> processor = |
63 make_scoped_ptr(new SharedModelTypeProcessor(syncer::THEMES, this)); | 64 base::WrapUnique(new SharedModelTypeProcessor(syncer::THEMES, this)); |
64 processor->OnMetadataLoaded(make_scoped_ptr(new MetadataBatch())); | 65 processor->OnMetadataLoaded(base::WrapUnique(new MetadataBatch())); |
65 return processor; | 66 return processor; |
66 } | 67 } |
67 | 68 |
68 private: | 69 private: |
69 base::MessageLoop loop_; | 70 base::MessageLoop loop_; |
70 scoped_refptr<base::SingleThreadTaskRunner> sync_task_runner_; | 71 scoped_refptr<base::SingleThreadTaskRunner> sync_task_runner_; |
71 scoped_refptr<base::SingleThreadTaskRunner> type_task_runner_; | 72 scoped_refptr<base::SingleThreadTaskRunner> type_task_runner_; |
72 | 73 |
73 std::vector<scoped_refptr<syncer::ModelSafeWorker>> workers_; | 74 std::vector<scoped_refptr<syncer::ModelSafeWorker>> workers_; |
74 syncer::TestDirectorySetterUpper dir_maker_; | 75 syncer::TestDirectorySetterUpper dir_maker_; |
75 syncer::MockNudgeHandler nudge_handler_; | 76 syncer::MockNudgeHandler nudge_handler_; |
76 scoped_ptr<syncer::ModelTypeRegistry> registry_; | 77 std::unique_ptr<syncer::ModelTypeRegistry> registry_; |
77 | 78 |
78 scoped_ptr<SyncContextProxyImpl> context_proxy_; | 79 std::unique_ptr<SyncContextProxyImpl> context_proxy_; |
79 }; | 80 }; |
80 | 81 |
81 // Try to connect a type to a SyncContext that has already shut down. | 82 // Try to connect a type to a SyncContext that has already shut down. |
82 TEST_F(SyncContextProxyImplTest, FailToConnect1) { | 83 TEST_F(SyncContextProxyImplTest, FailToConnect1) { |
83 scoped_ptr<SharedModelTypeProcessor> processor = CreateModelTypeProcessor(); | 84 std::unique_ptr<SharedModelTypeProcessor> processor = |
| 85 CreateModelTypeProcessor(); |
84 DisableSync(); | 86 DisableSync(); |
85 OnSyncStarting(processor.get()); | 87 OnSyncStarting(processor.get()); |
86 | 88 |
87 base::RunLoop run_loop_; | 89 base::RunLoop run_loop_; |
88 run_loop_.RunUntilIdle(); | 90 run_loop_.RunUntilIdle(); |
89 EXPECT_FALSE(processor->IsConnected()); | 91 EXPECT_FALSE(processor->IsConnected()); |
90 } | 92 } |
91 | 93 |
92 // Try to connect a type to a SyncContext as it shuts down. | 94 // Try to connect a type to a SyncContext as it shuts down. |
93 TEST_F(SyncContextProxyImplTest, FailToConnect2) { | 95 TEST_F(SyncContextProxyImplTest, FailToConnect2) { |
94 scoped_ptr<SharedModelTypeProcessor> processor = CreateModelTypeProcessor(); | 96 std::unique_ptr<SharedModelTypeProcessor> processor = |
| 97 CreateModelTypeProcessor(); |
95 OnSyncStarting(processor.get()); | 98 OnSyncStarting(processor.get()); |
96 DisableSync(); | 99 DisableSync(); |
97 | 100 |
98 base::RunLoop run_loop_; | 101 base::RunLoop run_loop_; |
99 run_loop_.RunUntilIdle(); | 102 run_loop_.RunUntilIdle(); |
100 EXPECT_FALSE(processor->IsConnected()); | 103 EXPECT_FALSE(processor->IsConnected()); |
101 } | 104 } |
102 | 105 |
103 // Tests the case where the type's sync proxy shuts down first. | 106 // Tests the case where the type's sync proxy shuts down first. |
104 TEST_F(SyncContextProxyImplTest, TypeDisconnectsFirst) { | 107 TEST_F(SyncContextProxyImplTest, TypeDisconnectsFirst) { |
105 scoped_ptr<SharedModelTypeProcessor> processor = CreateModelTypeProcessor(); | 108 std::unique_ptr<SharedModelTypeProcessor> processor = |
| 109 CreateModelTypeProcessor(); |
106 OnSyncStarting(processor.get()); | 110 OnSyncStarting(processor.get()); |
107 | 111 |
108 base::RunLoop run_loop_; | 112 base::RunLoop run_loop_; |
109 run_loop_.RunUntilIdle(); | 113 run_loop_.RunUntilIdle(); |
110 | 114 |
111 EXPECT_TRUE(processor->IsConnected()); | 115 EXPECT_TRUE(processor->IsConnected()); |
112 processor.reset(); | 116 processor.reset(); |
113 } | 117 } |
114 | 118 |
115 // Tests the case where the sync thread shuts down first. | 119 // Tests the case where the sync thread shuts down first. |
116 TEST_F(SyncContextProxyImplTest, SyncDisconnectsFirst) { | 120 TEST_F(SyncContextProxyImplTest, SyncDisconnectsFirst) { |
117 scoped_ptr<SharedModelTypeProcessor> processor = CreateModelTypeProcessor(); | 121 std::unique_ptr<SharedModelTypeProcessor> processor = |
| 122 CreateModelTypeProcessor(); |
118 OnSyncStarting(processor.get()); | 123 OnSyncStarting(processor.get()); |
119 | 124 |
120 base::RunLoop run_loop_; | 125 base::RunLoop run_loop_; |
121 run_loop_.RunUntilIdle(); | 126 run_loop_.RunUntilIdle(); |
122 | 127 |
123 EXPECT_TRUE(processor->IsConnected()); | 128 EXPECT_TRUE(processor->IsConnected()); |
124 DisableSync(); | 129 DisableSync(); |
125 } | 130 } |
126 | 131 |
127 } // namespace syncer_v2 | 132 } // namespace syncer_v2 |
OLD | NEW |