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

Side by Side Diff: content/browser/loader/temporary_file_stream.cc

Issue 82273002: Fix various issues in RedirectToFileResourceHandler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rename test fixture 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
(Empty)
1 // Copyright 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 #include "content/browser/loader/temporary_file_stream.h"
6
7 #include "base/bind.h"
8 #include "base/callback.h"
9 #include "base/files/file_util_proxy.h"
10 #include "base/memory/ref_counted.h"
11 #include "content/public/browser/browser_thread.h"
12 #include "net/base/file_stream.h"
13 #include "webkit/common/blob/shareable_file_reference.h"
14
15 using webkit_blob::ShareableFileReference;
16
17 namespace content {
18
19 namespace {
20
21 void DidCreateTemporaryFile(
22 const CreateTemporaryFileStreamCallback& callback,
23 base::File::Error error_code,
24 base::PassPlatformFile file_handle,
25 const base::FilePath& file_path) {
26 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
27
28 if (error_code != base::File::FILE_OK) {
29 callback.Run(error_code, scoped_ptr<net::FileStream>(), NULL);
30 return;
31 }
32
33 // Cancelled or not, create the deletable_file so the temporary is cleaned up.
34 scoped_refptr<ShareableFileReference> deletable_file =
35 ShareableFileReference::GetOrCreate(
36 file_path,
37 ShareableFileReference::DELETE_ON_FINAL_RELEASE,
38 BrowserThread::GetMessageLoopProxyForThread(
39 BrowserThread::FILE).get());
40
41 scoped_ptr<net::FileStream> file_stream(new net::FileStream(
42 file_handle.ReleaseValue(),
43 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_ASYNC,
44 NULL));
45
46 callback.Run(error_code, file_stream.Pass(), deletable_file);
47 }
48
49 } // namespace
50
51 void CreateTemporaryFileStream(
52 const CreateTemporaryFileStreamCallback& callback) {
53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
54
55 base::FileUtilProxy::CreateTemporary(
56 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE).get(),
57 base::PLATFORM_FILE_ASYNC,
58 base::Bind(&DidCreateTemporaryFile, callback));
59 }
60
61 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/temporary_file_stream.h ('k') | content/browser/loader/temporary_file_stream_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698