OLD | NEW |
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_interface.h" |
10 #include "chrome/browser/chromeos/drive/file_system_util.h" | 11 #include "chrome/browser/chromeos/drive/file_system_util.h" |
11 #include "chrome/browser/chromeos/drive/fileapi/async_file_util.h" | 12 #include "chrome/browser/chromeos/drive/fileapi/async_file_util.h" |
12 #include "chrome/browser/chromeos/drive/fileapi/fileapi_worker.h" | 13 #include "chrome/browser/chromeos/drive/fileapi/fileapi_worker.h" |
13 #include "chrome/browser/chromeos/drive/fileapi/webkit_file_stream_reader_impl.h
" | 14 #include "chrome/browser/chromeos/drive/fileapi/webkit_file_stream_reader_impl.h
" |
14 #include "chrome/browser/chromeos/drive/fileapi/webkit_file_stream_writer_impl.h
" | 15 #include "chrome/browser/chromeos/drive/fileapi/webkit_file_stream_writer_impl.h
" |
15 #include "chrome/browser/drive/drive_api_util.h" | 16 #include "chrome/browser/drive/drive_api_util.h" |
16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
17 #include "webkit/browser/blob/file_stream_reader.h" | 18 #include "webkit/browser/blob/file_stream_reader.h" |
18 #include "webkit/browser/fileapi/async_file_util.h" | 19 #include "webkit/browser/fileapi/async_file_util.h" |
19 #include "webkit/browser/fileapi/file_system_context.h" | 20 #include "webkit/browser/fileapi/file_system_context.h" |
20 #include "webkit/browser/fileapi/file_system_url.h" | 21 #include "webkit/browser/fileapi/file_system_url.h" |
21 | 22 |
22 using content::BrowserThread; | 23 using content::BrowserThread; |
23 | 24 |
24 namespace drive { | 25 namespace drive { |
| 26 namespace { |
| 27 |
| 28 // Called on the UI thread after GetRedirectURLForContentsOnUIThread. Obtains |
| 29 // the browser URL from |entry|. |callback| will be called on the IO thread. |
| 30 void GetRedirectURLForContentsOnUIThreadWithResourceEntry( |
| 31 const storage::URLCallback& callback, |
| 32 FileError error, |
| 33 scoped_ptr<ResourceEntry> entry) { |
| 34 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 35 GURL url; |
| 36 if (error == FILE_ERROR_OK && entry->has_file_specific_info() && |
| 37 entry->file_specific_info().is_hosted_document()) { |
| 38 url = GURL(entry->file_specific_info().alternate_url()); |
| 39 } |
| 40 BrowserThread::PostTask( |
| 41 BrowserThread::IO, FROM_HERE, base::Bind(callback, url)); |
| 42 } |
| 43 |
| 44 // Called on the UI thread after |
| 45 // FileSystemBackendDelegate::GetRedirectURLForContents. Requestes to obtain |
| 46 // ResourceEntry for the |url|. |
| 47 void GetRedirectURLForContentsOnUIThread( |
| 48 const storage::FileSystemURL& url, |
| 49 const storage::URLCallback& callback) { |
| 50 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 51 FileSystemInterface* const file_system = |
| 52 fileapi_internal::GetFileSystemFromUrl(url); |
| 53 if (!file_system) { |
| 54 BrowserThread::PostTask( |
| 55 BrowserThread::IO, FROM_HERE, base::Bind(callback, GURL())); |
| 56 return; |
| 57 } |
| 58 const base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url); |
| 59 file_system->GetResourceEntry( |
| 60 file_path, |
| 61 base::Bind(&GetRedirectURLForContentsOnUIThreadWithResourceEntry, |
| 62 callback)); |
| 63 } |
| 64 |
| 65 } // namespace |
25 | 66 |
26 FileSystemBackendDelegate::FileSystemBackendDelegate() | 67 FileSystemBackendDelegate::FileSystemBackendDelegate() |
27 : async_file_util_(new internal::AsyncFileUtil) { | 68 : async_file_util_(new internal::AsyncFileUtil) { |
28 } | 69 } |
29 | 70 |
30 FileSystemBackendDelegate::~FileSystemBackendDelegate() { | 71 FileSystemBackendDelegate::~FileSystemBackendDelegate() { |
31 } | 72 } |
32 | 73 |
33 storage::AsyncFileUtil* FileSystemBackendDelegate::GetAsyncFileUtil( | 74 storage::AsyncFileUtil* FileSystemBackendDelegate::GetAsyncFileUtil( |
34 storage::FileSystemType type) { | 75 storage::FileSystemType type) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 file_path, | 120 file_path, |
80 offset)); | 121 offset)); |
81 } | 122 } |
82 | 123 |
83 storage::WatcherManager* FileSystemBackendDelegate::GetWatcherManager( | 124 storage::WatcherManager* FileSystemBackendDelegate::GetWatcherManager( |
84 const storage::FileSystemURL& url) { | 125 const storage::FileSystemURL& url) { |
85 NOTIMPLEMENTED(); | 126 NOTIMPLEMENTED(); |
86 return NULL; | 127 return NULL; |
87 } | 128 } |
88 | 129 |
| 130 void FileSystemBackendDelegate::GetRedirectURLForContents( |
| 131 const storage::FileSystemURL& url, |
| 132 const storage::URLCallback& callback) { |
| 133 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 134 BrowserThread::PostTask( |
| 135 BrowserThread::UI, |
| 136 FROM_HERE, |
| 137 base::Bind(&GetRedirectURLForContentsOnUIThread, url, callback)); |
| 138 } |
| 139 |
89 } // namespace drive | 140 } // namespace drive |
OLD | NEW |