1a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// Copyright 2014 The Chromium Authors. All rights reserved.
2a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// Use of this source code is governed by a BSD-style license that can be
3a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// found in the LICENSE file.
4a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
55f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#ifndef SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_SERVICE_PROXY_FOR_TEST_H_
65f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#define SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_SERVICE_PROXY_FOR_TEST_H_
7a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
8a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "base/memory/scoped_ptr.h"
9a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "base/memory/weak_ptr.h"
10a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "sync/base/sync_export.h"
115f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "sync/internal_api/public/attachments/attachment_service_proxy.h"
12a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
13a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochnamespace syncer {
14a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
15a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// An self-contained AttachmentServiceProxy to reduce boilerplate code in tests.
16a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch//
175c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// Constructs and owns an AttachmentService suitable for use in tests.
185c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// NOTE: This class does not require the current thread to have a MessageLoop,
195c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// however all methods will effectively become no-op stubs in that case.
20a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochclass SYNC_EXPORT AttachmentServiceProxyForTest
21a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    : public AttachmentServiceProxy {
22a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch public:
23a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  static AttachmentServiceProxy Create();
24a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  virtual ~AttachmentServiceProxyForTest();
25a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
26a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch private:
27a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // A Core that owns the wrapped AttachmentService.
28a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  class OwningCore : public AttachmentServiceProxy::Core {
29a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch   public:
30a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    OwningCore(
31a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch        scoped_ptr<AttachmentService>,
32a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch        scoped_ptr<base::WeakPtrFactory<AttachmentService> > weak_ptr_factory);
33a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
34a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch   private:
351320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    virtual ~OwningCore();
361320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
37a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    scoped_ptr<AttachmentService> wrapped_;
38a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    // WeakPtrFactory for wrapped_.  See Create() for why this is a scoped_ptr.
39a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    scoped_ptr<base::WeakPtrFactory<AttachmentService> > weak_ptr_factory_;
40a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
41a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    DISALLOW_COPY_AND_ASSIGN(OwningCore);
42a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  };
43a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
44a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  AttachmentServiceProxyForTest(
45a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      const scoped_refptr<base::SequencedTaskRunner>& wrapped_task_runner,
46a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      const scoped_refptr<Core>& core);
47a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch};
48a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
49a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}  // namespace syncer
50a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
515f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#endif  // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_SERVICE_PROXY_FOR_TEST_H_
52