Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(974)

Side by Side Diff: sync/api/attachments/attachment_service_proxy_for_test.cc

Issue 436373002: Move non-API code out of sync/api/attachments/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Apply CR feedback. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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.h"
8 #include "base/thread_task_runner_handle.h"
9 #include "sync/api/attachments/attachment_service_impl.h"
10
11 namespace syncer {
12
13 AttachmentServiceProxyForTest::OwningCore::OwningCore(
14 scoped_ptr<AttachmentService> wrapped,
15 scoped_ptr<base::WeakPtrFactory<AttachmentService> > weak_ptr_factory)
16 : Core(weak_ptr_factory->GetWeakPtr()),
17 wrapped_(wrapped.Pass()),
18 weak_ptr_factory_(weak_ptr_factory.Pass()) {
19 DCHECK(wrapped_);
20 }
21
22 AttachmentServiceProxyForTest::OwningCore::~OwningCore() {
23 }
24
25 // Static.
26 AttachmentServiceProxy AttachmentServiceProxyForTest::Create() {
27 scoped_ptr<AttachmentService> wrapped(AttachmentServiceImpl::CreateForTest());
28 // This class's base class, AttachmentServiceProxy, must be initialized with a
29 // 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 // WeakPtrFactory here and pass it to the ctor so that it may initialize its
32 // base class and own the WeakPtrFactory.
33 //
34 // We must pass by scoped_ptr because WeakPtrFactory has no copy constructor.
35 scoped_ptr<base::WeakPtrFactory<AttachmentService> > weak_ptr_factory(
36 new base::WeakPtrFactory<AttachmentService>(wrapped.get()));
37
38 scoped_refptr<Core> core_for_test(
39 new OwningCore(wrapped.Pass(), weak_ptr_factory.Pass()));
40
41 scoped_refptr<base::SequencedTaskRunner> runner(
42 base::ThreadTaskRunnerHandle::Get());
43 if (!runner) {
44 // Dummy runner for tests that don't care about AttachmentServiceProxy.
45 DVLOG(1) << "Creating dummy MessageLoop for AttachmentServiceProxy.";
46 base::MessageLoop loop;
47 // This works because |runner| takes a ref to the proxy.
48 runner = loop.message_loop_proxy();
49 }
50 return AttachmentServiceProxyForTest(runner, core_for_test);
51 }
52
53 AttachmentServiceProxyForTest::~AttachmentServiceProxyForTest() {
54 }
55
56 AttachmentServiceProxyForTest::AttachmentServiceProxyForTest(
57 const scoped_refptr<base::SequencedTaskRunner>& wrapped_task_runner,
58 const scoped_refptr<Core>& core)
59 : AttachmentServiceProxy(wrapped_task_runner, core) {
60 }
61
62 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/api/attachments/attachment_service_proxy_for_test.h ('k') | sync/api/attachments/attachment_service_proxy_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698