Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / media_galleries / fileapi / device_media_async_file_util.h
1 // Copyright (c) 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.
4
5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_DEVICE_MEDIA_ASYNC_FILE_UTIL_H_
6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_DEVICE_MEDIA_ASYNC_FILE_UTIL_H_
7
8 #include "base/files/file.h"
9 #include "base/files/file_path.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "storage/browser/fileapi/async_file_util.h"
14 #include "storage/common/blob/shareable_file_reference.h"
15
16 namespace storage {
17 class FileSystemOperationContext;
18 class FileSystemURL;
19 }
20
21 namespace storage {
22 class FileStreamReader;
23 }
24
25 enum MediaFileValidationType {
26   NO_MEDIA_FILE_VALIDATION,
27   APPLY_MEDIA_FILE_VALIDATION,
28 };
29
30 class DeviceMediaAsyncFileUtil : public storage::AsyncFileUtil {
31  public:
32   ~DeviceMediaAsyncFileUtil() override;
33
34   // Returns an instance of DeviceMediaAsyncFileUtil.
35   static scoped_ptr<DeviceMediaAsyncFileUtil> Create(
36       const base::FilePath& profile_path,
37       MediaFileValidationType validation_type);
38
39   bool SupportsStreaming(const storage::FileSystemURL& url);
40
41   // AsyncFileUtil overrides.
42   void CreateOrOpen(scoped_ptr<storage::FileSystemOperationContext> context,
43                     const storage::FileSystemURL& url,
44                     int file_flags,
45                     const CreateOrOpenCallback& callback) override;
46   void EnsureFileExists(scoped_ptr<storage::FileSystemOperationContext> context,
47                         const storage::FileSystemURL& url,
48                         const EnsureFileExistsCallback& callback) override;
49   void CreateDirectory(scoped_ptr<storage::FileSystemOperationContext> context,
50                        const storage::FileSystemURL& url,
51                        bool exclusive,
52                        bool recursive,
53                        const StatusCallback& callback) override;
54   void GetFileInfo(scoped_ptr<storage::FileSystemOperationContext> context,
55                    const storage::FileSystemURL& url,
56                    const GetFileInfoCallback& callback) override;
57   void ReadDirectory(scoped_ptr<storage::FileSystemOperationContext> context,
58                      const storage::FileSystemURL& url,
59                      const ReadDirectoryCallback& callback) override;
60   void Touch(scoped_ptr<storage::FileSystemOperationContext> context,
61              const storage::FileSystemURL& url,
62              const base::Time& last_access_time,
63              const base::Time& last_modified_time,
64              const StatusCallback& callback) override;
65   void Truncate(scoped_ptr<storage::FileSystemOperationContext> context,
66                 const storage::FileSystemURL& url,
67                 int64 length,
68                 const StatusCallback& callback) override;
69   void CopyFileLocal(scoped_ptr<storage::FileSystemOperationContext> context,
70                      const storage::FileSystemURL& src_url,
71                      const storage::FileSystemURL& dest_url,
72                      CopyOrMoveOption option,
73                      const CopyFileProgressCallback& progress_callback,
74                      const StatusCallback& callback) override;
75   void MoveFileLocal(scoped_ptr<storage::FileSystemOperationContext> context,
76                      const storage::FileSystemURL& src_url,
77                      const storage::FileSystemURL& dest_url,
78                      CopyOrMoveOption option,
79                      const StatusCallback& callback) override;
80   void CopyInForeignFile(
81       scoped_ptr<storage::FileSystemOperationContext> context,
82       const base::FilePath& src_file_path,
83       const storage::FileSystemURL& dest_url,
84       const StatusCallback& callback) override;
85   void DeleteFile(scoped_ptr<storage::FileSystemOperationContext> context,
86                   const storage::FileSystemURL& url,
87                   const StatusCallback& callback) override;
88   void DeleteDirectory(scoped_ptr<storage::FileSystemOperationContext> context,
89                        const storage::FileSystemURL& url,
90                        const StatusCallback& callback) override;
91   void DeleteRecursively(
92       scoped_ptr<storage::FileSystemOperationContext> context,
93       const storage::FileSystemURL& url,
94       const StatusCallback& callback) override;
95   void CreateSnapshotFile(
96       scoped_ptr<storage::FileSystemOperationContext> context,
97       const storage::FileSystemURL& url,
98       const CreateSnapshotFileCallback& callback) override;
99
100   // This method is called when existing Blobs are read.
101   // |expected_modification_time| indicates the expected snapshot state of the
102   // underlying storage. The returned FileStreamReader must return an error
103   // when the state of the underlying storage changes. Any errors associated
104   // with reading this file are returned by the FileStreamReader itself.
105   virtual scoped_ptr<storage::FileStreamReader> GetFileStreamReader(
106       const storage::FileSystemURL& url,
107       int64 offset,
108       const base::Time& expected_modification_time,
109       storage::FileSystemContext* context);
110
111  private:
112   class MediaPathFilterWrapper;
113
114   // Use Create() to get an instance of DeviceMediaAsyncFileUtil.
115   DeviceMediaAsyncFileUtil(const base::FilePath& profile_path,
116                            MediaFileValidationType validation_type);
117
118   // Called when GetFileInfo method call succeeds. |file_info| contains the
119   // file details of the requested url. |callback| is invoked to complete the
120   // GetFileInfo request.
121   void OnDidGetFileInfo(
122       base::SequencedTaskRunner* task_runner,
123       const base::FilePath& path,
124       const GetFileInfoCallback& callback,
125       const base::File::Info& file_info);
126
127   // Called when ReadDirectory method call succeeds. |callback| is invoked to
128   // complete the ReadDirectory request.
129   //
130   // If the contents of the given directory are reported in one batch, then
131   // |file_list| will have the list of all files/directories in the given
132   // directory and |has_more| will be false.
133   //
134   // If the contents of the given directory are reported in multiple chunks,
135   // |file_list| will have only a subset of all contents (the subsets reported
136   // in any two calls are disjoint), and |has_more| will be true, except for
137   // the last chunk.
138   void OnDidReadDirectory(
139       base::SequencedTaskRunner* task_runner,
140       const ReadDirectoryCallback& callback,
141       const EntryList& file_list,
142       bool has_more);
143
144   bool validate_media_files() const;
145
146   // Profile path.
147   const base::FilePath profile_path_;
148
149   scoped_refptr<MediaPathFilterWrapper> media_path_filter_wrapper_;
150
151   // For callbacks that may run after destruction.
152   base::WeakPtrFactory<DeviceMediaAsyncFileUtil> weak_ptr_factory_;
153
154   DISALLOW_COPY_AND_ASSIGN(DeviceMediaAsyncFileUtil);
155 };
156
157 #endif  // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_DEVICE_MEDIA_ASYNC_FILE_UTIL_H_