| 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 #ifndef SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_SERVICE_PROXY_FOR_TEST_H
_ | 5 #ifndef SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_SERVICE_PROXY_FOR_TEST_H
_ |
| 6 #define SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_SERVICE_PROXY_FOR_TEST_H
_ | 6 #define SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_SERVICE_PROXY_FOR_TEST_H
_ |
| 7 | 7 |
| 8 #include <memory> |
| 9 |
| 8 #include "base/macros.h" | 10 #include "base/macros.h" |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 11 #include "sync/base/sync_export.h" | 12 #include "sync/base/sync_export.h" |
| 12 #include "sync/internal_api/public/attachments/attachment_service_proxy.h" | 13 #include "sync/internal_api/public/attachments/attachment_service_proxy.h" |
| 13 | 14 |
| 14 namespace syncer { | 15 namespace syncer { |
| 15 | 16 |
| 16 // An self-contained AttachmentServiceProxy to reduce boilerplate code in tests. | 17 // An self-contained AttachmentServiceProxy to reduce boilerplate code in tests. |
| 17 // | 18 // |
| 18 // Constructs and owns an AttachmentService suitable for use in tests. | 19 // Constructs and owns an AttachmentService suitable for use in tests. |
| 19 // NOTE: This class does not require the current thread to have a MessageLoop, | 20 // NOTE: This class does not require the current thread to have a MessageLoop, |
| 20 // however all methods will effectively become no-op stubs in that case. | 21 // however all methods will effectively become no-op stubs in that case. |
| 21 class SYNC_EXPORT AttachmentServiceProxyForTest | 22 class SYNC_EXPORT AttachmentServiceProxyForTest |
| 22 : public AttachmentServiceProxy { | 23 : public AttachmentServiceProxy { |
| 23 public: | 24 public: |
| 24 static AttachmentServiceProxy Create(); | 25 static AttachmentServiceProxy Create(); |
| 25 ~AttachmentServiceProxyForTest() override; | 26 ~AttachmentServiceProxyForTest() override; |
| 26 | 27 |
| 27 private: | 28 private: |
| 28 // A Core that owns the wrapped AttachmentService. | 29 // A Core that owns the wrapped AttachmentService. |
| 29 class OwningCore : public AttachmentServiceProxy::Core { | 30 class OwningCore : public AttachmentServiceProxy::Core { |
| 30 public: | 31 public: |
| 31 OwningCore( | 32 OwningCore(std::unique_ptr<AttachmentService>, |
| 32 scoped_ptr<AttachmentService>, | 33 std::unique_ptr<base::WeakPtrFactory<AttachmentService>> |
| 33 scoped_ptr<base::WeakPtrFactory<AttachmentService> > weak_ptr_factory); | 34 weak_ptr_factory); |
| 34 | 35 |
| 35 private: | 36 private: |
| 36 ~OwningCore() override; | 37 ~OwningCore() override; |
| 37 | 38 |
| 38 scoped_ptr<AttachmentService> wrapped_; | 39 std::unique_ptr<AttachmentService> wrapped_; |
| 39 // WeakPtrFactory for wrapped_. See Create() for why this is a scoped_ptr. | 40 // WeakPtrFactory for wrapped_. See Create() for why this is a scoped_ptr. |
| 40 scoped_ptr<base::WeakPtrFactory<AttachmentService> > weak_ptr_factory_; | 41 std::unique_ptr<base::WeakPtrFactory<AttachmentService>> weak_ptr_factory_; |
| 41 | 42 |
| 42 DISALLOW_COPY_AND_ASSIGN(OwningCore); | 43 DISALLOW_COPY_AND_ASSIGN(OwningCore); |
| 43 }; | 44 }; |
| 44 | 45 |
| 45 AttachmentServiceProxyForTest( | 46 AttachmentServiceProxyForTest( |
| 46 const scoped_refptr<base::SequencedTaskRunner>& wrapped_task_runner, | 47 const scoped_refptr<base::SequencedTaskRunner>& wrapped_task_runner, |
| 47 const scoped_refptr<Core>& core); | 48 const scoped_refptr<Core>& core); |
| 48 }; | 49 }; |
| 49 | 50 |
| 50 } // namespace syncer | 51 } // namespace syncer |
| 51 | 52 |
| 52 #endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_SERVICE_PROXY_FOR_TES
T_H_ | 53 #endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_SERVICE_PROXY_FOR_TES
T_H_ |
| OLD | NEW |