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

Side by Side Diff: chrome/browser/chromeos/extensions/file_manager/private_api_file_system.cc

Issue 23604042: Implement startCopy and cancelCopy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 3 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
« no previous file with comments | « chrome/browser/chromeos/extensions/file_manager/private_api_file_system.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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/extensions/file_manager/private_api_file_syste m.h" 5 #include "chrome/browser/chromeos/extensions/file_manager/private_api_file_syste m.h"
6 6
7 #include <sys/stat.h> 7 #include <sys/stat.h>
8 #include <sys/statvfs.h> 8 #include <sys/statvfs.h>
9 #include <sys/types.h> 9 #include <sys/types.h>
10 #include <utime.h> 10 #include <utime.h>
11 11
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/posix/eintr_wrapper.h" 13 #include "base/posix/eintr_wrapper.h"
14 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
15 #include "base/task_runner_util.h" 16 #include "base/task_runner_util.h"
16 #include "base/threading/sequenced_worker_pool.h" 17 #include "base/threading/sequenced_worker_pool.h"
18 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/chromeos/drive/drive.pb.h" 19 #include "chrome/browser/chromeos/drive/drive.pb.h"
18 #include "chrome/browser/chromeos/drive/file_system_interface.h" 20 #include "chrome/browser/chromeos/drive/file_system_interface.h"
19 #include "chrome/browser/chromeos/drive/file_system_util.h" 21 #include "chrome/browser/chromeos/drive/file_system_util.h"
20 #include "chrome/browser/chromeos/extensions/file_manager/event_router.h" 22 #include "chrome/browser/chromeos/extensions/file_manager/event_router.h"
21 #include "chrome/browser/chromeos/extensions/file_manager/file_browser_private_a pi.h" 23 #include "chrome/browser/chromeos/extensions/file_manager/file_browser_private_a pi.h"
22 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" 24 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h"
23 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" 25 #include "chrome/browser/chromeos/file_manager/fileapi_util.h"
24 #include "chrome/browser/chromeos/fileapi/file_system_backend.h" 26 #include "chrome/browser/chromeos/fileapi/file_system_backend.h"
25 #include "chrome/browser/profiles/profile.h" 27 #include "chrome/browser/profiles/profile.h"
28 #include "chrome/browser/profiles/profile_manager.h"
29 #include "chrome/common/extensions/api/file_browser_private.h"
26 #include "chromeos/disks/disk_mount_manager.h" 30 #include "chromeos/disks/disk_mount_manager.h"
27 #include "content/public/browser/browser_context.h" 31 #include "content/public/browser/browser_context.h"
28 #include "content/public/browser/child_process_security_policy.h" 32 #include "content/public/browser/child_process_security_policy.h"
29 #include "content/public/browser/render_process_host.h" 33 #include "content/public/browser/render_process_host.h"
30 #include "content/public/browser/render_view_host.h" 34 #include "content/public/browser/render_view_host.h"
31 #include "content/public/browser/storage_partition.h" 35 #include "content/public/browser/storage_partition.h"
32 #include "webkit/browser/fileapi/file_system_context.h" 36 #include "webkit/browser/fileapi/file_system_context.h"
33 #include "webkit/browser/fileapi/file_system_file_util.h" 37 #include "webkit/browser/fileapi/file_system_file_util.h"
34 #include "webkit/browser/fileapi/file_system_operation_context.h" 38 #include "webkit/browser/fileapi/file_system_operation_context.h"
39 #include "webkit/browser/fileapi/file_system_operation_runner.h"
35 #include "webkit/browser/fileapi/file_system_url.h" 40 #include "webkit/browser/fileapi/file_system_url.h"
36 #include "webkit/common/fileapi/file_system_types.h" 41 #include "webkit/common/fileapi/file_system_types.h"
37 #include "webkit/common/fileapi/file_system_util.h" 42 #include "webkit/common/fileapi/file_system_util.h"
38 43
39 using chromeos::disks::DiskMountManager; 44 using chromeos::disks::DiskMountManager;
40 using content::BrowserContext; 45 using content::BrowserContext;
41 using content::BrowserThread; 46 using content::BrowserThread;
42 using content::ChildProcessSecurityPolicy; 47 using content::ChildProcessSecurityPolicy;
43 using content::WebContents; 48 using content::WebContents;
44 using fileapi::FileSystemURL; 49 using fileapi::FileSystemURL;
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 struct stat stat_buffer; 173 struct stat stat_buffer;
169 if (stat(local_path.value().c_str(), &stat_buffer) != 0) 174 if (stat(local_path.value().c_str(), &stat_buffer) != 0)
170 return false; 175 return false;
171 176
172 struct utimbuf times; 177 struct utimbuf times;
173 times.actime = stat_buffer.st_atime; 178 times.actime = stat_buffer.st_atime;
174 times.modtime = timestamp; 179 times.modtime = timestamp;
175 return utime(local_path.value().c_str(), &times) == 0; 180 return utime(local_path.value().c_str(), &times) == 0;
176 } 181 }
177 182
183 // Notifies the copy completion to extensions via event router.
184 void NotifyCopyCompletion(
185 void* profile_id,
186 fileapi::FileSystemOperationRunner::OperationID operation_id,
187 const FileSystemURL& dest_url,
188 base::PlatformFileError error) {
189 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
190
191 // |profile_id| needs to be checked with ProfileManager::IsValidProfile
192 // before using it.
193 Profile* profile = reinterpret_cast<Profile*>(profile_id);
194 if (!g_browser_process->profile_manager()->IsValidProfile(profile))
195 return;
196
197 file_manager::EventRouter* event_router =
198 file_manager::FileBrowserPrivateAPI::Get(profile)->event_router();
199 event_router->OnCopyCompleted(operation_id, dest_url.ToGURL(), error);
200 }
201
202 // Callback invoked upon completion of Copy() (regardless of succeeded or
203 // failed).
204 void OnCopyCompleted(
205 void* profile_id,
206 fileapi::FileSystemOperationRunner::OperationID* operation_id,
207 const FileSystemURL& dest_url,
208 base::PlatformFileError error) {
209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
210
211 BrowserThread::PostTask(
212 BrowserThread::UI, FROM_HERE,
213 base::Bind(&NotifyCopyCompletion,
214 profile_id, *operation_id, dest_url, error));
215 }
216
217 // Starts the copy operation via FileSystemOperationRunner.
218 fileapi::FileSystemOperationRunner::OperationID StartCopyOnIOThread(
219 void* profile_id,
220 scoped_refptr<fileapi::FileSystemContext> file_system_context,
221 const FileSystemURL& source_url,
222 const FileSystemURL& dest_url) {
223 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
224
225 // Note: |operation_id| is owned by the callback for
226 // FileSystemOperationRunner::Copy(). It is always called in the next message
227 // loop or later, so at least during this invocation it should alive.
228 fileapi::FileSystemOperationRunner::OperationID* operation_id =
229 new fileapi::FileSystemOperationRunner::OperationID;
230 *operation_id = file_system_context->operation_runner()->Copy(
231 source_url, dest_url,
232 base::Bind(&OnCopyCompleted,
233 profile_id, base::Owned(operation_id), dest_url));
234 return *operation_id;
235 }
236
237 void OnCopyCancelled(base::PlatformFileError error) {
238 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
239
240 // We just ignore the status if the copy is actually cancelled or not,
241 // because failing cancellation means the operation is not running now.
242 DLOG_IF(WARNING, error != base::PLATFORM_FILE_OK)
243 << "Failed to cancel copy: " << error;
244 }
245
246 // Cancels the running copy operation identified by |operation_id|.
247 void CancelCopyOnIOThread(
248 scoped_refptr<fileapi::FileSystemContext> file_system_context,
249 fileapi::FileSystemOperationRunner::OperationID operation_id) {
250 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
251
252 file_system_context->operation_runner()->Cancel(
253 operation_id, base::Bind(&OnCopyCancelled));
254 }
255
178 } // namespace 256 } // namespace
179 257
180 FileBrowserPrivateRequestFileSystemFunction:: 258 FileBrowserPrivateRequestFileSystemFunction::
181 FileBrowserPrivateRequestFileSystemFunction() { 259 FileBrowserPrivateRequestFileSystemFunction() {
182 } 260 }
183 261
184 FileBrowserPrivateRequestFileSystemFunction:: 262 FileBrowserPrivateRequestFileSystemFunction::
185 ~FileBrowserPrivateRequestFileSystemFunction() { 263 ~FileBrowserPrivateRequestFileSystemFunction() {
186 } 264 }
187 265
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 return true; 702 return true;
625 } 703 }
626 704
627 FileBrowserPrivateStartCopyFunction::FileBrowserPrivateStartCopyFunction() { 705 FileBrowserPrivateStartCopyFunction::FileBrowserPrivateStartCopyFunction() {
628 } 706 }
629 707
630 FileBrowserPrivateStartCopyFunction::~FileBrowserPrivateStartCopyFunction() { 708 FileBrowserPrivateStartCopyFunction::~FileBrowserPrivateStartCopyFunction() {
631 } 709 }
632 710
633 bool FileBrowserPrivateStartCopyFunction::RunImpl() { 711 bool FileBrowserPrivateStartCopyFunction::RunImpl() {
634 // TODO(hidehiko): Implement startCopy function. 712 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
635 NOTIMPLEMENTED(); 713
636 return false; 714 using extensions::api::file_browser_private::StartCopy::Params;
715 const scoped_ptr<Params> params(Params::Create(*args_));
716 EXTENSION_FUNCTION_VALIDATE(params);
717
718 if (params->source_url.empty() || params->parent.empty() ||
719 params->new_name.empty()) {
720 error_ = base::IntToString(fileapi::PlatformFileErrorToWebFileError(
721 base::PLATFORM_FILE_ERROR_INVALID_URL));
722 return false;
723 }
724
725 scoped_refptr<fileapi::FileSystemContext> file_system_context =
726 file_manager::util::GetFileSystemContextForRenderViewHost(
727 profile(), render_view_host());
728
729 fileapi::FileSystemURL source_url(
730 file_system_context->CrackURL(GURL(params->source_url)));
731 fileapi::FileSystemURL dest_url(file_system_context->CrackURL(
732 GURL(params->parent + "/" + params->new_name)));
733
734 if (!source_url.is_valid() || !dest_url.is_valid()) {
735 error_ = base::IntToString(fileapi::PlatformFileErrorToWebFileError(
736 base::PLATFORM_FILE_ERROR_INVALID_URL));
737 return false;
738 }
739
740 return BrowserThread::PostTaskAndReplyWithResult(
741 BrowserThread::IO,
742 FROM_HERE,
743 base::Bind(&StartCopyOnIOThread,
744 profile(), file_system_context, source_url, dest_url),
745 base::Bind(&FileBrowserPrivateStartCopyFunction::RunAfterStartCopy,
746 this));
747 }
748
749 void FileBrowserPrivateStartCopyFunction::RunAfterStartCopy(
750 int operation_id) {
751 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
752
753 SetResult(Value::CreateIntegerValue(operation_id));
754 SendResponse(true);
637 } 755 }
638 756
639 FileBrowserPrivateCancelCopyFunction::FileBrowserPrivateCancelCopyFunction() { 757 FileBrowserPrivateCancelCopyFunction::FileBrowserPrivateCancelCopyFunction() {
640 } 758 }
641 759
642 FileBrowserPrivateCancelCopyFunction::~FileBrowserPrivateCancelCopyFunction() { 760 FileBrowserPrivateCancelCopyFunction::~FileBrowserPrivateCancelCopyFunction() {
643 } 761 }
644 762
645 bool FileBrowserPrivateCancelCopyFunction::RunImpl() { 763 bool FileBrowserPrivateCancelCopyFunction::RunImpl() {
646 // TODO(hidehiko): Implement cancelCopy function. 764 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
647 NOTIMPLEMENTED(); 765
648 return false; 766 using extensions::api::file_browser_private::CancelCopy::Params;
767 const scoped_ptr<Params> params(Params::Create(*args_));
768 EXTENSION_FUNCTION_VALIDATE(params);
769
770 scoped_refptr<fileapi::FileSystemContext> file_system_context =
771 file_manager::util::GetFileSystemContextForRenderViewHost(
772 profile(), render_view_host());
773
774 // We don't much take care about the result of cancellation.
775 BrowserThread::PostTask(
776 BrowserThread::IO,
777 FROM_HERE,
778 base::Bind(&CancelCopyOnIOThread, file_system_context, params->copy_id));
779 SendResponse(true);
780 return true;
649 } 781 }
650 782
651 } // namespace extensions 783 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/extensions/file_manager/private_api_file_system.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698