OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_URL_REQUEST_URL_FETCHER_RESPONSE_WRITER_H_ | 5 #ifndef NET_URL_REQUEST_URL_FETCHER_RESPONSE_WRITER_H_ |
6 #define NET_URL_REQUEST_URL_FETCHER_RESPONSE_WRITER_H_ | 6 #define NET_URL_REQUEST_URL_FETCHER_RESPONSE_WRITER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "net/base/completion_callback.h" | 13 #include "net/base/completion_callback.h" |
14 #include "net/base/net_export.h" | 14 #include "net/base/net_export.h" |
15 | 15 |
16 namespace base { | 16 namespace base { |
17 class TaskRunner; | 17 class SequencedTaskRunner; |
18 } // namespace base | 18 } // namespace base |
19 | 19 |
20 namespace net { | 20 namespace net { |
21 | 21 |
22 class DrainableIOBuffer; | 22 class DrainableIOBuffer; |
23 class FileStream; | 23 class FileStream; |
24 class IOBuffer; | 24 class IOBuffer; |
25 class URLFetcherFileWriter; | 25 class URLFetcherFileWriter; |
26 class URLFetcherStringWriter; | 26 class URLFetcherStringWriter; |
27 | 27 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 std::string data_; | 74 std::string data_; |
75 | 75 |
76 DISALLOW_COPY_AND_ASSIGN(URLFetcherStringWriter); | 76 DISALLOW_COPY_AND_ASSIGN(URLFetcherStringWriter); |
77 }; | 77 }; |
78 | 78 |
79 // URLFetcherResponseWriter implementation for files. | 79 // URLFetcherResponseWriter implementation for files. |
80 class NET_EXPORT URLFetcherFileWriter : public URLFetcherResponseWriter { | 80 class NET_EXPORT URLFetcherFileWriter : public URLFetcherResponseWriter { |
81 public: | 81 public: |
82 // |file_path| is used as the destination path. If |file_path| is empty, | 82 // |file_path| is used as the destination path. If |file_path| is empty, |
83 // Initialize() will create a temporary file. | 83 // Initialize() will create a temporary file. |
84 URLFetcherFileWriter(scoped_refptr<base::TaskRunner> file_task_runner, | 84 URLFetcherFileWriter( |
85 const base::FilePath& file_path); | 85 scoped_refptr<base::SequencedTaskRunner> file_task_runner, |
| 86 const base::FilePath& file_path); |
86 virtual ~URLFetcherFileWriter(); | 87 virtual ~URLFetcherFileWriter(); |
87 | 88 |
88 const base::FilePath& file_path() const { return file_path_; } | 89 const base::FilePath& file_path() const { return file_path_; } |
89 | 90 |
90 // URLFetcherResponseWriter overrides: | 91 // URLFetcherResponseWriter overrides: |
91 virtual int Initialize(const CompletionCallback& callback) OVERRIDE; | 92 virtual int Initialize(const CompletionCallback& callback) OVERRIDE; |
92 virtual int Write(IOBuffer* buffer, | 93 virtual int Write(IOBuffer* buffer, |
93 int num_bytes, | 94 int num_bytes, |
94 const CompletionCallback& callback) OVERRIDE; | 95 const CompletionCallback& callback) OVERRIDE; |
95 virtual int Finish(const CompletionCallback& callback) OVERRIDE; | 96 virtual int Finish(const CompletionCallback& callback) OVERRIDE; |
(...skipping 19 matching lines...) Expand all Loading... |
115 void DidOpenFile(const CompletionCallback& callback, | 116 void DidOpenFile(const CompletionCallback& callback, |
116 int result); | 117 int result); |
117 | 118 |
118 // Callback which gets the result of closing a file. | 119 // Callback which gets the result of closing a file. |
119 void CloseComplete(const CompletionCallback& callback, int result); | 120 void CloseComplete(const CompletionCallback& callback, int result); |
120 | 121 |
121 // Callbacks are created for use with base::FileUtilProxy. | 122 // Callbacks are created for use with base::FileUtilProxy. |
122 base::WeakPtrFactory<URLFetcherFileWriter> weak_factory_; | 123 base::WeakPtrFactory<URLFetcherFileWriter> weak_factory_; |
123 | 124 |
124 // Task runner on which file operations should happen. | 125 // Task runner on which file operations should happen. |
125 scoped_refptr<base::TaskRunner> file_task_runner_; | 126 scoped_refptr<base::SequencedTaskRunner> file_task_runner_; |
126 | 127 |
127 // Destination file path. | 128 // Destination file path. |
128 // Initialize() creates a temporary file if this variable is empty. | 129 // Initialize() creates a temporary file if this variable is empty. |
129 base::FilePath file_path_; | 130 base::FilePath file_path_; |
130 | 131 |
131 // True when this instance is responsible to delete the file at |file_path_|. | 132 // True when this instance is responsible to delete the file at |file_path_|. |
132 bool owns_file_; | 133 bool owns_file_; |
133 | 134 |
134 scoped_ptr<FileStream> file_stream_; | 135 scoped_ptr<FileStream> file_stream_; |
135 | 136 |
136 DISALLOW_COPY_AND_ASSIGN(URLFetcherFileWriter); | 137 DISALLOW_COPY_AND_ASSIGN(URLFetcherFileWriter); |
137 }; | 138 }; |
138 | 139 |
139 } // namespace net | 140 } // namespace net |
140 | 141 |
141 #endif // NET_URL_REQUEST_URL_FETCHER_RESPONSE_WRITER_H_ | 142 #endif // NET_URL_REQUEST_URL_FETCHER_RESPONSE_WRITER_H_ |
OLD | NEW |