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

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: Rebase Created 6 years, 11 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::PlatformFileError error_code,
24 base::PassPlatformFile file_handle,
25 const base::FilePath& file_path) {
26 if (error_code != base::PLATFORM_FILE_OK) {
27 callback.Run(error_code, scoped_ptr<net::FileStream>(), NULL);
28 return;
29 }
30
31 // Cancelled or not, create the deletable_file so the temporary is cleaned up.
32 scoped_refptr<ShareableFileReference> deletable_file =
33 ShareableFileReference::GetOrCreate(
34 file_path,
35 ShareableFileReference::DELETE_ON_FINAL_RELEASE,
36 BrowserThread::GetMessageLoopProxyForThread(
37 BrowserThread::FILE).get());
38
39 scoped_ptr<net::FileStream> file_stream(new net::FileStream(
40 file_handle.ReleaseValue(),
41 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_ASYNC,
42 NULL));
43
44 callback.Run(error_code, file_stream.Pass(), deletable_file);
45 }
46
47 } // namespace
48
49 void CreateTemporaryFileStream(
50 const CreateTemporaryFileStreamCallback& callback) {
51 base::FileUtilProxy::CreateTemporary(
52 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE).get(),
53 base::PLATFORM_FILE_ASYNC,
54 base::Bind(&DidCreateTemporaryFile, callback));
55 }
56
57 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698