Fix Win8 metro startup crash from window switcher button
[chromium-blink-merge.git] / webkit / fileapi / file_system_file_stream_reader.h
blob04ff96220ad14bad823f809fb6f22f411ab3da9e
1 // Copyright (c) 2012 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 WEBKIT_FILEAPI_FILE_SYSTEM_FILE_STREAM_READER_H_
6 #define WEBKIT_FILEAPI_FILE_SYSTEM_FILE_STREAM_READER_H_
8 #include "base/bind.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/platform_file.h"
11 #include "base/time.h"
12 #include "webkit/blob/file_stream_reader.h"
13 #include "webkit/blob/shareable_file_reference.h"
14 #include "webkit/fileapi/file_system_url.h"
15 #include "webkit/storage/webkit_storage_export.h"
17 namespace base {
18 class FilePath;
19 class SequencedTaskRunner;
22 namespace webkit_blob {
23 class LocalFileStreamReader;
26 namespace fileapi {
28 class FileSystemContext;
30 // TODO(kinaba,satorux): This generic implementation would work for any
31 // filesystems but remote filesystem should implement its own reader
32 // rather than relying on FileSystemOperation::GetSnapshotFile() which
33 // may force downloading the entire contents for remote files.
34 class WEBKIT_STORAGE_EXPORT_PRIVATE FileSystemFileStreamReader
35 : public webkit_blob::FileStreamReader {
36 public:
37 // Creates a new FileReader for a filesystem URL |url| form |initial_offset|.
38 // |expected_modification_time| specifies the expected last modification if
39 // the value is non-null, the reader will check the underlying file's actual
40 // modification time to see if the file has been modified, and if it does any
41 // succeeding read operations should fail with ERR_UPLOAD_FILE_CHANGED error.
42 FileSystemFileStreamReader(FileSystemContext* file_system_context,
43 const FileSystemURL& url,
44 int64 initial_offset,
45 const base::Time& expected_modification_time);
46 virtual ~FileSystemFileStreamReader();
48 // FileStreamReader overrides.
49 virtual int Read(net::IOBuffer* buf, int buf_len,
50 const net::CompletionCallback& callback) OVERRIDE;
51 virtual int64 GetLength(
52 const net::Int64CompletionCallback& callback) OVERRIDE;
54 private:
55 int CreateSnapshot(const base::Closure& callback,
56 const net::CompletionCallback& error_callback);
57 void DidCreateSnapshot(
58 const base::Closure& callback,
59 const net::CompletionCallback& error_callback,
60 base::PlatformFileError file_error,
61 const base::PlatformFileInfo& file_info,
62 const base::FilePath& platform_path,
63 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref);
65 scoped_refptr<FileSystemContext> file_system_context_;
66 FileSystemURL url_;
67 const int64 initial_offset_;
68 const base::Time expected_modification_time_;
69 scoped_ptr<webkit_blob::LocalFileStreamReader> local_file_reader_;
70 scoped_refptr<webkit_blob::ShareableFileReference> snapshot_ref_;
71 bool has_pending_create_snapshot_;
72 base::WeakPtrFactory<FileSystemFileStreamReader> weak_factory_;
74 DISALLOW_COPY_AND_ASSIGN(FileSystemFileStreamReader);
77 } // namespace fileapi
79 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_FILE_STREAM_READER_H_