Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / drive / file_system_backend_delegate.cc
blobee606b600ab6d30ff15569b0573ca4407373141d
1 // Copyright 2013 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/drive/file_system_backend_delegate.h"
7 #include "base/bind.h"
8 #include "base/files/file_path.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/browser/chromeos/drive/async_file_util.h"
11 #include "chrome/browser/chromeos/drive/file_system_util.h"
12 #include "chrome/browser/chromeos/drive/webkit_file_stream_reader_impl.h"
13 #include "chrome/browser/chromeos/drive/webkit_file_stream_writer_impl.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "content/public/browser/browser_context.h"
16 #include "content/public/browser/browser_thread.h"
17 #include "webkit/browser/blob/file_stream_reader.h"
18 #include "webkit/browser/fileapi/async_file_util.h"
19 #include "webkit/browser/fileapi/file_system_context.h"
20 #include "webkit/browser/fileapi/file_system_url.h"
22 using content::BrowserThread;
24 namespace drive {
26 FileSystemBackendDelegate::FileSystemBackendDelegate(
27 content::BrowserContext* browser_context)
28 : profile_id_(Profile::FromBrowserContext(browser_context)),
29 async_file_util_(new internal::AsyncFileUtil(
30 base::Bind(&util::GetFileSystemByProfileId, profile_id_))) {
31 DCHECK(profile_id_);
34 FileSystemBackendDelegate::~FileSystemBackendDelegate() {
37 fileapi::AsyncFileUtil* FileSystemBackendDelegate::GetAsyncFileUtil(
38 fileapi::FileSystemType type) {
39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
40 DCHECK_EQ(fileapi::kFileSystemTypeDrive, type);
41 return async_file_util_.get();
44 scoped_ptr<webkit_blob::FileStreamReader>
45 FileSystemBackendDelegate::CreateFileStreamReader(
46 const fileapi::FileSystemURL& url,
47 int64 offset,
48 const base::Time& expected_modification_time,
49 fileapi::FileSystemContext* context) {
50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
51 DCHECK_EQ(fileapi::kFileSystemTypeDrive, url.type());
53 base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url);
54 if (file_path.empty())
55 return scoped_ptr<webkit_blob::FileStreamReader>();
57 return scoped_ptr<webkit_blob::FileStreamReader>(
58 new internal::WebkitFileStreamReaderImpl(
59 base::Bind(&util::GetFileSystemByProfileId, profile_id_),
60 context->default_file_task_runner(),
61 file_path, offset, expected_modification_time));
64 scoped_ptr<fileapi::FileStreamWriter>
65 FileSystemBackendDelegate::CreateFileStreamWriter(
66 const fileapi::FileSystemURL& url,
67 int64 offset,
68 fileapi::FileSystemContext* context) {
69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
70 DCHECK_EQ(fileapi::kFileSystemTypeDrive, url.type());
72 base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url);
73 // Hosted documents don't support stream writer.
74 if (file_path.empty() || util::HasGDocFileExtension(file_path))
75 return scoped_ptr<fileapi::FileStreamWriter>();
77 return scoped_ptr<fileapi::FileStreamWriter>(
78 new internal::WebkitFileStreamWriterImpl(
79 base::Bind(&util::GetFileSystemByProfileId, profile_id_),
80 context->default_file_task_runner(),file_path, offset));
83 } // namespace drive