- add sources.
[platform/framework/web/crosswalk.git] / src / webkit / browser / fileapi / upload_file_system_file_element_reader.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 WEBKIT_BROWSER_FILEAPI_UPLOAD_FILE_SYSTEM_FILE_ELEMENT_READER_H_
6 #define WEBKIT_BROWSER_FILEAPI_UPLOAD_FILE_SYSTEM_FILE_ELEMENT_READER_H_
7
8 #include "base/memory/weak_ptr.h"
9 #include "base/time/time.h"
10 #include "net/base/upload_element_reader.h"
11 #include "url/gurl.h"
12 #include "webkit/browser/webkit_storage_browser_export.h"
13
14 namespace webkit_blob {
15 class FileStreamReader;
16 }
17
18 namespace fileapi {
19
20 class FileSystemContext;
21
22 // An UploadElementReader implementation for filesystem file.
23 class WEBKIT_STORAGE_BROWSER_EXPORT UploadFileSystemFileElementReader
24     : public net::UploadElementReader {
25  public:
26   UploadFileSystemFileElementReader(
27       FileSystemContext* file_system_context,
28       const GURL& url,
29       uint64 range_offset,
30       uint64 range_length,
31       const base::Time& expected_modification_time);
32   virtual ~UploadFileSystemFileElementReader();
33
34   // UploadElementReader overrides:
35   virtual int Init(const net::CompletionCallback& callback) OVERRIDE;
36   virtual uint64 GetContentLength() const OVERRIDE;
37   virtual uint64 BytesRemaining() const OVERRIDE;
38   virtual int Read(net::IOBuffer* buf,
39                    int buf_length,
40                    const net::CompletionCallback& callback) OVERRIDE;
41
42  private:
43   void OnGetLength(const net::CompletionCallback& callback, int64 result);
44   void OnRead(const net::CompletionCallback& callback, int result);
45
46   scoped_refptr<FileSystemContext> file_system_context_;
47   const GURL url_;
48   const uint64 range_offset_;
49   const uint64 range_length_;
50   const base::Time expected_modification_time_;
51
52   scoped_ptr<webkit_blob::FileStreamReader> stream_reader_;
53
54   uint64 stream_length_;
55   uint64 position_;
56
57   base::WeakPtrFactory<UploadFileSystemFileElementReader> weak_ptr_factory_;
58
59   DISALLOW_COPY_AND_ASSIGN(UploadFileSystemFileElementReader);
60 };
61
62 }  // namespace fileapi
63
64 #endif  // WEBKIT_BROWSER_FILEAPI_UPLOAD_FILE_SYSTEM_FILE_ELEMENT_READER_H_