Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Side by Side Diff: net/base/upload_content_url_element_reader_android.h

Issue 46303005: Fix chrome upload with content uri (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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 NET_BASE_UPLOAD_CONTENT_URL_ELEMENT_READER_H_
6 #define NET_BASE_UPLOAD_CONTENT_URL_ELEMENT_READER_H_
7
8 #include "base/compiler_specific.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/time/time.h"
13 #include "net/base/upload_element_reader.h"
14 #include "url/gurl.h"
15
16 namespace base {
17 class TaskRunner;
18 }
19
20 namespace net {
21
22 class FileStream;
23
24 // An UploadElementReader implementation for content url.
25 class NET_EXPORT UploadContentUrlElementReader : public UploadElementReader {
26 public:
27 // |task_runner| is used to perform file operations. It must not be NULL.
28 UploadContentUrlElementReader(base::TaskRunner* task_runner,
29 const GURL& content_url,
30 uint64 range_offset,
31 uint64 range_length,
32 const base::Time& expected_modification_time);
33 virtual ~UploadContentUrlElementReader();
34
35 const GURL& content_url() const { return content_url_; }
36 uint64 range_offset() const { return range_offset_; }
37 uint64 range_length() const { return range_length_; }
38 const base::Time& expected_modification_time() const {
39 return expected_modification_time_;
40 }
41
42 // UploadElementReader overrides:
43 virtual int Init(const CompletionCallback& callback) OVERRIDE;
44 virtual uint64 GetContentLength() const OVERRIDE;
45 virtual uint64 BytesRemaining() const OVERRIDE;
46 virtual int Read(IOBuffer* buf,
47 int buf_length,
48 const CompletionCallback& callback) OVERRIDE;
49
50 private:
51 // Deletes FileStream with |task_runner| to avoid blocking the IO thread.
52 // This class is used as a template argument of scoped_ptr.
53 class FileStreamDeleter {
54 public:
55 explicit FileStreamDeleter(base::TaskRunner* task_runner);
56 ~FileStreamDeleter();
57 void operator() (FileStream* file_stream) const;
58
59 private:
60 scoped_refptr<base::TaskRunner> task_runner_;
61 };
62
63 typedef scoped_ptr<FileStream, FileStreamDeleter> ScopedFileStreamPtr;
64
65 // Resets this instance to the uninitialized state.
66 void Reset();
67
68 // This method is used to implement Init().
69 void OnInitCompleted(ScopedFileStreamPtr* file_stream,
70 uint64* content_length,
71 const CompletionCallback& callback,
72 int result);
73
74 // This method is used to implement Read().
75 void OnReadCompleted(ScopedFileStreamPtr file_stream,
76 const CompletionCallback& callback,
77 int result);
78
79 scoped_refptr<base::TaskRunner> task_runner_;
80 const GURL& content_url_;
81 const uint64 range_offset_;
82 const uint64 range_length_;
83 const base::Time expected_modification_time_;
84 ScopedFileStreamPtr file_stream_;
85 uint64 content_length_;
86 uint64 bytes_remaining_;
87 base::WeakPtrFactory<UploadContentUrlElementReader> weak_ptr_factory_;
88
89 DISALLOW_COPY_AND_ASSIGN(UploadContentUrlElementReader);
90 };
91
92 } // namespace net
93
94 #endif // NET_BASE_UPLOAD_CONTENT_URL_ELEMENT_READER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698