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/file_system_provider/fileapi/provider_async_fi
le_util.h" | 5 #include "chrome/browser/chromeos/file_system_provider/fileapi/provider_async_fi
le_util.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/files/file.h" | 8 #include "base/files/file.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 void OnReadDirectory( | 76 void OnReadDirectory( |
77 const fileapi::AsyncFileUtil::ReadDirectoryCallback& callback, | 77 const fileapi::AsyncFileUtil::ReadDirectoryCallback& callback, |
78 base::File::Error result, | 78 base::File::Error result, |
79 const fileapi::AsyncFileUtil::EntryList& entry_list, | 79 const fileapi::AsyncFileUtil::EntryList& entry_list, |
80 bool has_more) { | 80 bool has_more) { |
81 BrowserThread::PostTask(BrowserThread::IO, | 81 BrowserThread::PostTask(BrowserThread::IO, |
82 FROM_HERE, | 82 FROM_HERE, |
83 base::Bind(callback, result, entry_list, has_more)); | 83 base::Bind(callback, result, entry_list, has_more)); |
84 } | 84 } |
85 | 85 |
| 86 // Executes CreateDirectory on the UI thread. |
| 87 void CreateDirectoryOnUIThread( |
| 88 scoped_ptr<fileapi::FileSystemOperationContext> context, |
| 89 const fileapi::FileSystemURL& url, |
| 90 bool exclusive, |
| 91 bool recursive, |
| 92 const fileapi::AsyncFileUtil::StatusCallback& callback) { |
| 93 util::FileSystemURLParser parser(url); |
| 94 if (!parser.Parse()) { |
| 95 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION); |
| 96 return; |
| 97 } |
| 98 |
| 99 parser.file_system()->CreateDirectory( |
| 100 parser.file_path(), exclusive, recursive, callback); |
| 101 } |
| 102 |
| 103 // Routes the response of CreateDirectory back to the IO thread. |
| 104 void OnCreateDirectory(const fileapi::AsyncFileUtil::StatusCallback& callback, |
| 105 base::File::Error result) { |
| 106 BrowserThread::PostTask( |
| 107 BrowserThread::IO, FROM_HERE, base::Bind(callback, result)); |
| 108 } |
| 109 |
86 } // namespace | 110 } // namespace |
87 | 111 |
88 ProviderAsyncFileUtil::ProviderAsyncFileUtil() {} | 112 ProviderAsyncFileUtil::ProviderAsyncFileUtil() {} |
89 | 113 |
90 ProviderAsyncFileUtil::~ProviderAsyncFileUtil() {} | 114 ProviderAsyncFileUtil::~ProviderAsyncFileUtil() {} |
91 | 115 |
92 void ProviderAsyncFileUtil::CreateOrOpen( | 116 void ProviderAsyncFileUtil::CreateOrOpen( |
93 scoped_ptr<fileapi::FileSystemOperationContext> context, | 117 scoped_ptr<fileapi::FileSystemOperationContext> context, |
94 const fileapi::FileSystemURL& url, | 118 const fileapi::FileSystemURL& url, |
95 int file_flags, | 119 int file_flags, |
(...skipping 21 matching lines...) Expand all Loading... |
117 callback.Run(base::File::FILE_ERROR_ACCESS_DENIED, false /* created */); | 141 callback.Run(base::File::FILE_ERROR_ACCESS_DENIED, false /* created */); |
118 } | 142 } |
119 | 143 |
120 void ProviderAsyncFileUtil::CreateDirectory( | 144 void ProviderAsyncFileUtil::CreateDirectory( |
121 scoped_ptr<fileapi::FileSystemOperationContext> context, | 145 scoped_ptr<fileapi::FileSystemOperationContext> context, |
122 const fileapi::FileSystemURL& url, | 146 const fileapi::FileSystemURL& url, |
123 bool exclusive, | 147 bool exclusive, |
124 bool recursive, | 148 bool recursive, |
125 const StatusCallback& callback) { | 149 const StatusCallback& callback) { |
126 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 150 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
127 callback.Run(base::File::FILE_ERROR_ACCESS_DENIED); | 151 BrowserThread::PostTask(BrowserThread::UI, |
| 152 FROM_HERE, |
| 153 base::Bind(&CreateDirectoryOnUIThread, |
| 154 base::Passed(&context), |
| 155 url, |
| 156 exclusive, |
| 157 recursive, |
| 158 base::Bind(&OnCreateDirectory, callback))); |
128 } | 159 } |
129 | 160 |
130 void ProviderAsyncFileUtil::GetFileInfo( | 161 void ProviderAsyncFileUtil::GetFileInfo( |
131 scoped_ptr<fileapi::FileSystemOperationContext> context, | 162 scoped_ptr<fileapi::FileSystemOperationContext> context, |
132 const fileapi::FileSystemURL& url, | 163 const fileapi::FileSystemURL& url, |
133 const GetFileInfoCallback& callback) { | 164 const GetFileInfoCallback& callback) { |
134 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 165 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
135 BrowserThread::PostTask(BrowserThread::UI, | 166 BrowserThread::PostTask(BrowserThread::UI, |
136 FROM_HERE, | 167 FROM_HERE, |
137 base::Bind(&GetFileInfoOnUIThread, | 168 base::Bind(&GetFileInfoOnUIThread, |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 NOTIMPLEMENTED(); | 265 NOTIMPLEMENTED(); |
235 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION, | 266 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION, |
236 base::File::Info(), | 267 base::File::Info(), |
237 base::FilePath(), | 268 base::FilePath(), |
238 scoped_refptr<webkit_blob::ShareableFileReference>()); | 269 scoped_refptr<webkit_blob::ShareableFileReference>()); |
239 } | 270 } |
240 | 271 |
241 } // namespace internal | 272 } // namespace internal |
242 } // namespace file_system_provider | 273 } // namespace file_system_provider |
243 } // namespace chromeos | 274 } // namespace chromeos |
OLD | NEW |