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 "chrome/browser/chromeos/file_system_provider/fileapi/backend_delegate.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "chrome/browser/chromeos/file_system_provider/fileapi/buffering_file_stream_reader.h"
9 #include "chrome/browser/chromeos/file_system_provider/fileapi/buffering_file_stream_writer.h"
10 #include "chrome/browser/chromeos/file_system_provider/fileapi/file_stream_reader.h"
11 #include "chrome/browser/chromeos/file_system_provider/fileapi/file_stream_writer.h"
12 #include "chrome/browser/chromeos/file_system_provider/fileapi/provider_async_file_util.h"
13 #include "chrome/browser/chromeos/file_system_provider/fileapi/watcher_manager.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "storage/browser/fileapi/file_stream_reader.h"
16 #include "storage/browser/fileapi/file_stream_writer.h"
17 #include "storage/browser/fileapi/file_system_url.h"
19 using content::BrowserThread
;
22 namespace file_system_provider
{
25 // Size of the stream reader internal buffer. At most this number of bytes will
26 // be read ahead of the requested data.
27 const int kReaderBufferSize
= 512 * 1024; // 512KB.
29 // Size of the stream writer internal buffer. At most this number of bytes will
30 // be postponed for writing.
31 const int kWriterBufferSize
= 512 * 1024; // 512KB.
35 BackendDelegate::BackendDelegate()
36 : async_file_util_(new internal::ProviderAsyncFileUtil
),
37 watcher_manager_(new WatcherManager
) {
40 BackendDelegate::~BackendDelegate() {}
42 storage::AsyncFileUtil
* BackendDelegate::GetAsyncFileUtil(
43 storage::FileSystemType type
) {
44 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
45 DCHECK_EQ(storage::kFileSystemTypeProvided
, type
);
46 return async_file_util_
.get();
49 scoped_ptr
<storage::FileStreamReader
> BackendDelegate::CreateFileStreamReader(
50 const storage::FileSystemURL
& url
,
52 int64 max_bytes_to_read
,
53 const base::Time
& expected_modification_time
,
54 storage::FileSystemContext
* context
) {
55 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
56 DCHECK_EQ(storage::kFileSystemTypeProvided
, url
.type());
58 return scoped_ptr
<storage::FileStreamReader
>(new BufferingFileStreamReader(
59 scoped_ptr
<storage::FileStreamReader
>(new FileStreamReader(
60 context
, url
, offset
, expected_modification_time
)),
65 scoped_ptr
<storage::FileStreamWriter
> BackendDelegate::CreateFileStreamWriter(
66 const storage::FileSystemURL
& url
,
68 storage::FileSystemContext
* context
) {
69 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
70 DCHECK_EQ(storage::kFileSystemTypeProvided
, url
.type());
72 return scoped_ptr
<storage::FileStreamWriter
>(new BufferingFileStreamWriter(
73 scoped_ptr
<storage::FileStreamWriter
>(new FileStreamWriter(url
, offset
)),
77 storage::WatcherManager
* BackendDelegate::GetWatcherManager(
78 storage::FileSystemType type
) {
79 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
80 DCHECK_EQ(storage::kFileSystemTypeProvided
, type
);
81 return watcher_manager_
.get();
84 void BackendDelegate::GetRedirectURLForContents(
85 const storage::FileSystemURL
& url
,
86 const storage::URLCallback
& callback
) {
87 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
88 DCHECK_EQ(storage::kFileSystemTypeProvided
, url
.type());
92 } // namespace file_system_provider
93 } // namespace chromeos