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

Side by Side Diff: net/url_request/url_fetcher_response_writer.cc

Issue 189393002: net: Update FileStream to use base::File instead of PlatformFile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 9 months 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
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 #include "net/url_request/url_fetcher_response_writer.h" 5 #include "net/url_request/url_fetcher_response_writer.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/sequenced_task_runner.h" 9 #include "base/sequenced_task_runner.h"
10 #include "base/task_runner_util.h" 10 #include "base/task_runner_util.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 file_task_runner_.get(), 73 file_task_runner_.get(),
74 FROM_HERE, 74 FROM_HERE,
75 base::Bind(&base::CreateTemporaryFile, temp_file_path), 75 base::Bind(&base::CreateTemporaryFile, temp_file_path),
76 base::Bind(&URLFetcherFileWriter::DidCreateTempFile, 76 base::Bind(&URLFetcherFileWriter::DidCreateTempFile,
77 weak_factory_.GetWeakPtr(), 77 weak_factory_.GetWeakPtr(),
78 callback, 78 callback,
79 base::Owned(temp_file_path))); 79 base::Owned(temp_file_path)));
80 } else { 80 } else {
81 result = file_stream_->Open( 81 result = file_stream_->Open(
82 file_path_, 82 file_path_,
83 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_ASYNC | 83 base::File::FLAG_WRITE | base::File::FLAG_ASYNC |
84 base::PLATFORM_FILE_CREATE_ALWAYS, 84 base::File::FLAG_CREATE_ALWAYS,
85 base::Bind(&URLFetcherFileWriter::DidOpenFile, 85 base::Bind(&URLFetcherFileWriter::DidOpenFile,
86 weak_factory_.GetWeakPtr(), 86 weak_factory_.GetWeakPtr(),
87 callback)); 87 callback));
88 DCHECK_NE(OK, result); 88 DCHECK_NE(OK, result);
89 } 89 }
90 return result; 90 return result;
91 } 91 }
92 92
93 int URLFetcherFileWriter::Write(IOBuffer* buffer, 93 int URLFetcherFileWriter::Write(IOBuffer* buffer,
94 int num_bytes, 94 int num_bytes,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 base::FilePath* temp_file_path, 155 base::FilePath* temp_file_path,
156 bool success) { 156 bool success) {
157 if (!success) { 157 if (!success) {
158 callback.Run(ERR_FILE_NOT_FOUND); 158 callback.Run(ERR_FILE_NOT_FOUND);
159 return; 159 return;
160 } 160 }
161 file_path_ = *temp_file_path; 161 file_path_ = *temp_file_path;
162 owns_file_ = true; 162 owns_file_ = true;
163 const int result = file_stream_->Open( 163 const int result = file_stream_->Open(
164 file_path_, 164 file_path_,
165 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_ASYNC | 165 base::File::FLAG_WRITE | base::File::FLAG_ASYNC |
166 base::PLATFORM_FILE_OPEN, 166 base::File::FLAG_OPEN,
167 base::Bind(&URLFetcherFileWriter::DidOpenFile, 167 base::Bind(&URLFetcherFileWriter::DidOpenFile,
168 weak_factory_.GetWeakPtr(), 168 weak_factory_.GetWeakPtr(),
169 callback)); 169 callback));
170 if (result != ERR_IO_PENDING) 170 if (result != ERR_IO_PENDING)
171 DidOpenFile(callback, result); 171 DidOpenFile(callback, result);
172 } 172 }
173 173
174 void URLFetcherFileWriter::DidOpenFile(const CompletionCallback& callback, 174 void URLFetcherFileWriter::DidOpenFile(const CompletionCallback& callback,
175 int result) { 175 int result) {
176 if (result == OK) 176 if (result == OK)
177 owns_file_ = true; 177 owns_file_ = true;
178 else 178 else
179 CloseAndDeleteFile(); 179 CloseAndDeleteFile();
180 180
181 callback.Run(result); 181 callback.Run(result);
182 } 182 }
183 183
184 void URLFetcherFileWriter::CloseComplete(const CompletionCallback& callback, 184 void URLFetcherFileWriter::CloseComplete(const CompletionCallback& callback,
185 int result) { 185 int result) {
186 // Destroy |file_stream_| whether or not the close succeeded. 186 // Destroy |file_stream_| whether or not the close succeeded.
187 file_stream_.reset(); 187 file_stream_.reset();
188 callback.Run(result); 188 callback.Run(result);
189 } 189 }
190 190
191 } // namespace net 191 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698