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