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 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_OPEN_FILE_OPERATION_H_
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_OPEN_FILE_OPERATION_H_
10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/threading/thread_checker.h"
15 #include "chrome/browser/chromeos/drive/file_system_interface.h"
16 #include "components/drive/file_errors.h"
20 class ScopedClosureRunner
;
21 class SequencedTaskRunner
;
30 class ResourceMetadata
;
32 } // namespace internal
34 namespace file_system
{
36 class CreateFileOperation
;
37 class DownloadOperation
;
38 class OperationDelegate
;
40 class OpenFileOperation
{
42 OpenFileOperation(base::SequencedTaskRunner
* blocking_task_runner
,
43 OperationDelegate
* delegate
,
44 JobScheduler
* scheduler
,
45 internal::ResourceMetadata
* metadata
,
46 internal::FileCache
* cache
,
47 const base::FilePath
& temporary_file_directory
);
50 // Opens the file at |file_path|.
51 // If the file is not actually downloaded, this method starts
52 // to download it to the cache, and then runs |callback| upon the
53 // completion with the path to the local cache file.
54 // See also the definition of OpenMode for its meaning.
55 // If |mime_type| is non empty and the file is created by this OpenFile()
56 // call, the mime type is used as the file's property.
57 // |callback| must not be null.
58 void OpenFile(const base::FilePath
& file_path
,
60 const std::string
& mime_type
,
61 const OpenFileCallback
& callback
);
64 // Part of OpenFile(). Called after file creation is completed.
65 void OpenFileAfterCreateFile(const base::FilePath
& file_path
,
66 const OpenFileCallback
& callback
,
69 // Part of OpenFile(). Called after file downloading is completed.
70 void OpenFileAfterFileDownloaded(const OpenFileCallback
& callback
,
72 const base::FilePath
& local_file_path
,
73 scoped_ptr
<ResourceEntry
> entry
);
75 // Part of OpenFile(). Called after opening the cache file.
76 void OpenFileAfterOpenForWrite(
77 const base::FilePath
& local_file_path
,
78 const std::string
& local_id
,
79 const OpenFileCallback
& callback
,
80 scoped_ptr
<base::ScopedClosureRunner
>* file_closer
,
83 // Closes the file with |local_id|.
84 void CloseFile(const std::string
& local_id
,
85 scoped_ptr
<base::ScopedClosureRunner
> file_closer
);
87 scoped_refptr
<base::SequencedTaskRunner
> blocking_task_runner_
;
88 OperationDelegate
* delegate_
;
89 internal::FileCache
* cache_
;
91 scoped_ptr
<CreateFileOperation
> create_file_operation_
;
92 scoped_ptr
<DownloadOperation
> download_operation_
;
94 // The map from local id for an opened file to the number how many times
95 // the file is opened.
96 std::map
<std::string
, int> open_files_
;
98 base::ThreadChecker thread_checker_
;
100 // Note: This should remain the last member so it'll be destroyed and
101 // invalidate its weak pointers before any other members are destroyed.
102 base::WeakPtrFactory
<OpenFileOperation
> weak_ptr_factory_
;
103 DISALLOW_COPY_AND_ASSIGN(OpenFileOperation
);
106 } // namespace file_system
109 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_OPEN_FILE_OPERATION_H_