Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / chromeos / drive / write_on_cache_file.cc
blob340cf4eae153b4985825b7da4b6add0b43c516e4
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/write_on_cache_file.h"
7 #include "base/bind.h"
8 #include "base/callback.h"
9 #include "base/threading/sequenced_worker_pool.h"
10 #include "chrome/browser/chromeos/drive/file_system_interface.h"
11 #include "chrome/browser/chromeos/drive/file_system_util.h"
12 #include "content/public/browser/browser_thread.h"
14 using content::BrowserThread;
16 namespace drive {
18 namespace {
20 // Runs |close_callback| and |reply|.
21 void RunCloseCallbackAndReplyTask(const base::Closure& close_callback,
22 const FileOperationCallback& reply,
23 FileError error) {
24 if (!close_callback.is_null())
25 close_callback.Run();
26 DCHECK(!reply.is_null());
27 reply.Run(error);
30 // Runs |file_io_task_callback| in blocking pool and runs |close_callback|
31 // in the UI thread after that.
32 void WriteOnCacheFileAfterOpenFile(
33 const base::FilePath& drive_path,
34 const WriteOnCacheFileCallback& file_io_task_callback,
35 const FileOperationCallback& reply,
36 FileError error,
37 const base::FilePath& local_cache_path,
38 const base::Closure& close_callback) {
39 DCHECK_CURRENTLY_ON(BrowserThread::UI);
41 BrowserThread::GetBlockingPool()->PostTaskAndReply(
42 FROM_HERE,
43 base::Bind(file_io_task_callback, error, local_cache_path),
44 base::Bind(&RunCloseCallbackAndReplyTask, close_callback, reply, error));
47 } // namespace
49 void WriteOnCacheFile(FileSystemInterface* file_system,
50 const base::FilePath& path,
51 const std::string& mime_type,
52 const WriteOnCacheFileCallback& callback) {
53 WriteOnCacheFileAndReply(file_system, path, mime_type, callback,
54 base::Bind(&util::EmptyFileOperationCallback));
57 void WriteOnCacheFileAndReply(FileSystemInterface* file_system,
58 const base::FilePath& path,
59 const std::string& mime_type,
60 const WriteOnCacheFileCallback& callback,
61 const FileOperationCallback& reply) {
62 DCHECK_CURRENTLY_ON(BrowserThread::UI);
63 DCHECK(file_system);
64 DCHECK(!callback.is_null());
65 DCHECK(!reply.is_null());
67 file_system->OpenFile(
68 path,
69 OPEN_OR_CREATE_FILE,
70 mime_type,
71 base::Bind(&WriteOnCacheFileAfterOpenFile, path, callback, reply));
74 } // namespace drive