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/public/attachments/attachment_service_proxy_for_test
.h" | 5 #include "sync/internal_api/public/attachments/attachment_service_proxy_for_test
.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
11 #include "sync/internal_api/public/attachments/attachment_service_impl.h" | 11 #include "sync/internal_api/public/attachments/attachment_service_impl.h" |
12 | 12 |
13 namespace syncer { | 13 namespace syncer { |
14 | 14 |
15 AttachmentServiceProxyForTest::OwningCore::OwningCore( | 15 AttachmentServiceProxyForTest::OwningCore::OwningCore( |
16 scoped_ptr<AttachmentService> wrapped, | 16 std::unique_ptr<AttachmentService> wrapped, |
17 scoped_ptr<base::WeakPtrFactory<AttachmentService>> weak_ptr_factory) | 17 std::unique_ptr<base::WeakPtrFactory<AttachmentService>> weak_ptr_factory) |
18 : Core(weak_ptr_factory->GetWeakPtr()), | 18 : Core(weak_ptr_factory->GetWeakPtr()), |
19 wrapped_(std::move(wrapped)), | 19 wrapped_(std::move(wrapped)), |
20 weak_ptr_factory_(std::move(weak_ptr_factory)) { | 20 weak_ptr_factory_(std::move(weak_ptr_factory)) { |
21 DCHECK(wrapped_); | 21 DCHECK(wrapped_); |
22 } | 22 } |
23 | 23 |
24 AttachmentServiceProxyForTest::OwningCore::~OwningCore() { | 24 AttachmentServiceProxyForTest::OwningCore::~OwningCore() { |
25 } | 25 } |
26 | 26 |
27 // Static. | 27 // Static. |
28 AttachmentServiceProxy AttachmentServiceProxyForTest::Create() { | 28 AttachmentServiceProxy AttachmentServiceProxyForTest::Create() { |
29 scoped_ptr<AttachmentService> wrapped(AttachmentServiceImpl::CreateForTest()); | 29 std::unique_ptr<AttachmentService> wrapped( |
| 30 AttachmentServiceImpl::CreateForTest()); |
30 // This class's base class, AttachmentServiceProxy, must be initialized with a | 31 // This class's base class, AttachmentServiceProxy, must be initialized with a |
31 // WeakPtr to an AttachmentService. Because the base class ctor must be | 32 // WeakPtr to an AttachmentService. Because the base class ctor must be |
32 // invoked before any of this class's members are initialized, we create the | 33 // invoked before any of this class's members are initialized, we create the |
33 // WeakPtrFactory here and pass it to the ctor so that it may initialize its | 34 // WeakPtrFactory here and pass it to the ctor so that it may initialize its |
34 // base class and own the WeakPtrFactory. | 35 // base class and own the WeakPtrFactory. |
35 // | 36 // |
36 // We must pass by scoped_ptr because WeakPtrFactory has no copy constructor. | 37 // We must pass by scoped_ptr because WeakPtrFactory has no copy constructor. |
37 scoped_ptr<base::WeakPtrFactory<AttachmentService> > weak_ptr_factory( | 38 std::unique_ptr<base::WeakPtrFactory<AttachmentService>> weak_ptr_factory( |
38 new base::WeakPtrFactory<AttachmentService>(wrapped.get())); | 39 new base::WeakPtrFactory<AttachmentService>(wrapped.get())); |
39 | 40 |
40 scoped_refptr<Core> core_for_test( | 41 scoped_refptr<Core> core_for_test( |
41 new OwningCore(std::move(wrapped), std::move(weak_ptr_factory))); | 42 new OwningCore(std::move(wrapped), std::move(weak_ptr_factory))); |
42 | 43 |
43 scoped_refptr<base::SequencedTaskRunner> runner; | 44 scoped_refptr<base::SequencedTaskRunner> runner; |
44 if (base::ThreadTaskRunnerHandle::IsSet()) { | 45 if (base::ThreadTaskRunnerHandle::IsSet()) { |
45 runner = base::ThreadTaskRunnerHandle::Get(); | 46 runner = base::ThreadTaskRunnerHandle::Get(); |
46 } else { | 47 } else { |
47 // Dummy runner for tests that don't have MessageLoop. | 48 // Dummy runner for tests that don't have MessageLoop. |
48 DVLOG(1) << "Creating dummy MessageLoop for AttachmentServiceProxy."; | 49 DVLOG(1) << "Creating dummy MessageLoop for AttachmentServiceProxy."; |
49 base::MessageLoop loop; | 50 base::MessageLoop loop; |
50 // This works because |runner| takes a ref to the proxy. | 51 // This works because |runner| takes a ref to the proxy. |
51 runner = base::ThreadTaskRunnerHandle::Get(); | 52 runner = base::ThreadTaskRunnerHandle::Get(); |
52 } | 53 } |
53 return AttachmentServiceProxyForTest(runner, core_for_test); | 54 return AttachmentServiceProxyForTest(runner, core_for_test); |
54 } | 55 } |
55 | 56 |
56 AttachmentServiceProxyForTest::~AttachmentServiceProxyForTest() { | 57 AttachmentServiceProxyForTest::~AttachmentServiceProxyForTest() { |
57 } | 58 } |
58 | 59 |
59 AttachmentServiceProxyForTest::AttachmentServiceProxyForTest( | 60 AttachmentServiceProxyForTest::AttachmentServiceProxyForTest( |
60 const scoped_refptr<base::SequencedTaskRunner>& wrapped_task_runner, | 61 const scoped_refptr<base::SequencedTaskRunner>& wrapped_task_runner, |
61 const scoped_refptr<Core>& core) | 62 const scoped_refptr<Core>& core) |
62 : AttachmentServiceProxy(wrapped_task_runner, core) { | 63 : AttachmentServiceProxy(wrapped_task_runner, core) { |
63 } | 64 } |
64 | 65 |
65 } // namespace syncer | 66 } // namespace syncer |
OLD | NEW |