Revert of Add support for escaped target names in isolate driver. (patchset #6 id...
[chromium-blink-merge.git] / sync / api / attachments / attachment_store.cc
blob91b3f956f85593c33daa3da4441907bc6b6f7415
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.
5 #include "sync/api/attachments/attachment_store.h"
7 #include "base/bind.h"
8 #include "base/callback.h"
9 #include "base/location.h"
10 #include "base/message_loop/message_loop.h"
11 #include "base/sequenced_task_runner.h"
12 #include "base/thread_task_runner_handle.h"
13 #include "sync/internal_api/public/attachments/attachment_store_handle.h"
14 #include "sync/internal_api/public/attachments/in_memory_attachment_store.h"
15 #include "sync/internal_api/public/attachments/on_disk_attachment_store.h"
17 namespace syncer {
19 AttachmentStore::AttachmentStore() {}
20 AttachmentStore::~AttachmentStore() {}
22 scoped_refptr<AttachmentStore> AttachmentStore::CreateInMemoryStore() {
23 // Both frontend and backend of attachment store will live on current thread.
24 scoped_refptr<base::SingleThreadTaskRunner> runner;
25 if (base::ThreadTaskRunnerHandle::IsSet()) {
26 runner = base::ThreadTaskRunnerHandle::Get();
27 } else {
28 // Dummy runner for tests that don't have MessageLoop.
29 base::MessageLoop loop;
30 // This works because |runner| takes a ref to the proxy.
31 runner = base::ThreadTaskRunnerHandle::Get();
33 scoped_ptr<AttachmentStoreBackend> backend(
34 new InMemoryAttachmentStore(runner));
35 return scoped_refptr<AttachmentStore>(
36 new AttachmentStoreHandle(backend.Pass(), runner));
39 scoped_refptr<AttachmentStore> AttachmentStore::CreateOnDiskStore(
40 const base::FilePath& path,
41 const scoped_refptr<base::SequencedTaskRunner>& backend_task_runner,
42 const InitCallback& callback) {
43 scoped_ptr<OnDiskAttachmentStore> backend(
44 new OnDiskAttachmentStore(base::ThreadTaskRunnerHandle::Get(), path));
46 scoped_refptr<AttachmentStore> attachment_store =
47 new AttachmentStoreHandle(backend.Pass(), backend_task_runner);
48 attachment_store->Init(callback);
50 return attachment_store;
53 AttachmentStoreBackend::AttachmentStoreBackend(
54 const scoped_refptr<base::SequencedTaskRunner>& callback_task_runner)
55 : callback_task_runner_(callback_task_runner) {
58 AttachmentStoreBackend::~AttachmentStoreBackend() {
61 void AttachmentStoreBackend::PostCallback(const base::Closure& callback) {
62 callback_task_runner_->PostTask(FROM_HERE, callback);
65 } // namespace syncer