OLD | NEW |
---|---|
(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); | |
mmenke
2014/03/03 21:10:11
The old code seems to have handled deleting the fi
davidben
2014/03/03 23:20:18
The old code handled that? It didn't really check
mmenke
2014/03/04 18:06:52
The old code actually did handle that, in a round
| |
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 | |
OLD | NEW |