OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "sync/api/attachments/attachment_service_proxy_for_test.h" |
| 6 |
| 7 #include "base/message_loop/message_loop_proxy.h" |
| 8 #include "sync/api/attachments/fake_attachment_service.h" |
| 9 |
| 10 namespace syncer { |
| 11 |
| 12 AttachmentServiceProxyForTest::OwningCore::OwningCore( |
| 13 scoped_ptr<AttachmentService> wrapped, |
| 14 scoped_ptr<base::WeakPtrFactory<AttachmentService> > weak_ptr_factory) |
| 15 : Core(weak_ptr_factory->GetWeakPtr()), |
| 16 wrapped_(wrapped.Pass()), |
| 17 weak_ptr_factory_(weak_ptr_factory.Pass()) { |
| 18 DCHECK(wrapped_); |
| 19 } |
| 20 |
| 21 AttachmentServiceProxyForTest::OwningCore::~OwningCore() { |
| 22 } |
| 23 |
| 24 // Static. |
| 25 AttachmentServiceProxy AttachmentServiceProxyForTest::Create() { |
| 26 scoped_ptr<AttachmentService> wrapped(FakeAttachmentService::CreateForTest()); |
| 27 // This class's base class, AttachmentServiceProxy, must be initialized with a |
| 28 // WeakPtr to an AttachmentService. Because the base class ctor must be |
| 29 // invoked before any of this class's members are initialized, we create the |
| 30 // WeakPtrFactory here and pass it to the ctor so that it may initialize its |
| 31 // base class and own the WeakPtrFactory. |
| 32 // |
| 33 // We must pass by scoped_ptr because WeakPtrFactory has no copy constructor. |
| 34 scoped_ptr<base::WeakPtrFactory<AttachmentService> > weak_ptr_factory( |
| 35 new base::WeakPtrFactory<AttachmentService>(wrapped.get())); |
| 36 |
| 37 scoped_refptr<Core> core_for_test( |
| 38 new OwningCore(wrapped.Pass(), weak_ptr_factory.Pass())); |
| 39 return AttachmentServiceProxyForTest(base::MessageLoopProxy::current(), |
| 40 core_for_test); |
| 41 } |
| 42 |
| 43 AttachmentServiceProxyForTest::~AttachmentServiceProxyForTest() { |
| 44 } |
| 45 |
| 46 AttachmentServiceProxyForTest::AttachmentServiceProxyForTest( |
| 47 const scoped_refptr<base::SequencedTaskRunner>& wrapped_task_runner, |
| 48 const scoped_refptr<Core>& core) |
| 49 : AttachmentServiceProxy(wrapped_task_runner, core) { |
| 50 } |
| 51 |
| 52 } // namespace syncer |
OLD | NEW |