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