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

Side by Side Diff: chrome/browser/chromeos/drive/fileapi/file_system_backend_delegate.cc

Issue 145973016: Support cross-profile copy between Chrome OS Google Drive folders. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fix. Created 6 years, 10 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/drive/fileapi/file_system_backend_delegate.h" 5 #include "chrome/browser/chromeos/drive/fileapi/file_system_backend_delegate.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/browser/chromeos/drive/file_system_util.h" 10 #include "chrome/browser/chromeos/drive/file_system_util.h"
11 #include "chrome/browser/chromeos/drive/fileapi/async_file_util.h" 11 #include "chrome/browser/chromeos/drive/fileapi/async_file_util.h"
12 #include "chrome/browser/chromeos/drive/fileapi/fileapi_worker.h"
12 #include "chrome/browser/chromeos/drive/fileapi/webkit_file_stream_reader_impl.h " 13 #include "chrome/browser/chromeos/drive/fileapi/webkit_file_stream_reader_impl.h "
13 #include "chrome/browser/chromeos/drive/fileapi/webkit_file_stream_writer_impl.h " 14 #include "chrome/browser/chromeos/drive/fileapi/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" 15 #include "content/public/browser/browser_thread.h"
17 #include "webkit/browser/blob/file_stream_reader.h" 16 #include "webkit/browser/blob/file_stream_reader.h"
18 #include "webkit/browser/fileapi/async_file_util.h" 17 #include "webkit/browser/fileapi/async_file_util.h"
19 #include "webkit/browser/fileapi/file_system_context.h" 18 #include "webkit/browser/fileapi/file_system_context.h"
20 #include "webkit/browser/fileapi/file_system_url.h" 19 #include "webkit/browser/fileapi/file_system_url.h"
21 20
22 using content::BrowserThread; 21 using content::BrowserThread;
23 22
24 namespace drive { 23 namespace drive {
25 24
26 FileSystemBackendDelegate::FileSystemBackendDelegate( 25 FileSystemBackendDelegate::FileSystemBackendDelegate()
27 content::BrowserContext* browser_context) 26 : async_file_util_(new internal::AsyncFileUtil) {
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_);
32 } 27 }
33 28
34 FileSystemBackendDelegate::~FileSystemBackendDelegate() { 29 FileSystemBackendDelegate::~FileSystemBackendDelegate() {
35 } 30 }
36 31
37 fileapi::AsyncFileUtil* FileSystemBackendDelegate::GetAsyncFileUtil( 32 fileapi::AsyncFileUtil* FileSystemBackendDelegate::GetAsyncFileUtil(
38 fileapi::FileSystemType type) { 33 fileapi::FileSystemType type) {
39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
40 DCHECK_EQ(fileapi::kFileSystemTypeDrive, type); 35 DCHECK_EQ(fileapi::kFileSystemTypeDrive, type);
41 return async_file_util_.get(); 36 return async_file_util_.get();
42 } 37 }
43 38
44 scoped_ptr<webkit_blob::FileStreamReader> 39 scoped_ptr<webkit_blob::FileStreamReader>
45 FileSystemBackendDelegate::CreateFileStreamReader( 40 FileSystemBackendDelegate::CreateFileStreamReader(
46 const fileapi::FileSystemURL& url, 41 const fileapi::FileSystemURL& url,
47 int64 offset, 42 int64 offset,
48 const base::Time& expected_modification_time, 43 const base::Time& expected_modification_time,
49 fileapi::FileSystemContext* context) { 44 fileapi::FileSystemContext* context) {
50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
51 DCHECK_EQ(fileapi::kFileSystemTypeDrive, url.type()); 46 DCHECK_EQ(fileapi::kFileSystemTypeDrive, url.type());
52 47
53 base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url); 48 base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url);
54 if (file_path.empty()) 49 if (file_path.empty())
55 return scoped_ptr<webkit_blob::FileStreamReader>(); 50 return scoped_ptr<webkit_blob::FileStreamReader>();
56 51
57 return scoped_ptr<webkit_blob::FileStreamReader>( 52 return scoped_ptr<webkit_blob::FileStreamReader>(
58 new internal::WebkitFileStreamReaderImpl( 53 new internal::WebkitFileStreamReaderImpl(
59 base::Bind(&util::GetFileSystemByProfileId, profile_id_), 54 base::Bind(&fileapi_internal::GetFileSystemFromUrl, url),
60 context->default_file_task_runner(), 55 context->default_file_task_runner(),
61 file_path, offset, expected_modification_time)); 56 file_path, offset, expected_modification_time));
62 } 57 }
63 58
64 scoped_ptr<fileapi::FileStreamWriter> 59 scoped_ptr<fileapi::FileStreamWriter>
65 FileSystemBackendDelegate::CreateFileStreamWriter( 60 FileSystemBackendDelegate::CreateFileStreamWriter(
66 const fileapi::FileSystemURL& url, 61 const fileapi::FileSystemURL& url,
67 int64 offset, 62 int64 offset,
68 fileapi::FileSystemContext* context) { 63 fileapi::FileSystemContext* context) {
69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
70 DCHECK_EQ(fileapi::kFileSystemTypeDrive, url.type()); 65 DCHECK_EQ(fileapi::kFileSystemTypeDrive, url.type());
71 66
72 base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url); 67 base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url);
73 // Hosted documents don't support stream writer. 68 // Hosted documents don't support stream writer.
74 if (file_path.empty() || util::HasGDocFileExtension(file_path)) 69 if (file_path.empty() || util::HasGDocFileExtension(file_path))
75 return scoped_ptr<fileapi::FileStreamWriter>(); 70 return scoped_ptr<fileapi::FileStreamWriter>();
76 71
77 return scoped_ptr<fileapi::FileStreamWriter>( 72 return scoped_ptr<fileapi::FileStreamWriter>(
78 new internal::WebkitFileStreamWriterImpl( 73 new internal::WebkitFileStreamWriterImpl(
79 base::Bind(&util::GetFileSystemByProfileId, profile_id_), 74 base::Bind(&fileapi_internal::GetFileSystemFromUrl, url),
80 context->default_file_task_runner(),file_path, offset)); 75 context->default_file_task_runner(),file_path, offset));
81 } 76 }
82 77
83 } // namespace drive 78 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698