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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/loader/temporary_file_stream.cc
diff --git a/content/browser/loader/temporary_file_stream.cc b/content/browser/loader/temporary_file_stream.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7f04f4dc5acbc6f7f61d704409f1c45f83213100
--- /dev/null
+++ b/content/browser/loader/temporary_file_stream.cc
@@ -0,0 +1,61 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/loader/temporary_file_stream.h"
+
+#include "base/bind.h"
+#include "base/callback.h"
+#include "base/files/file_util_proxy.h"
+#include "base/memory/ref_counted.h"
+#include "content/public/browser/browser_thread.h"
+#include "net/base/file_stream.h"
+#include "webkit/common/blob/shareable_file_reference.h"
+
+using webkit_blob::ShareableFileReference;
+
+namespace content {
+
+namespace {
+
+void DidCreateTemporaryFile(
+ const CreateTemporaryFileStreamCallback& callback,
+ base::File::Error error_code,
+ base::PassPlatformFile file_handle,
+ const base::FilePath& file_path) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+
+ if (error_code != base::File::FILE_OK) {
+ callback.Run(error_code, scoped_ptr<net::FileStream>(), NULL);
+ return;
+ }
+
+ // Cancelled or not, create the deletable_file so the temporary is cleaned up.
+ scoped_refptr<ShareableFileReference> deletable_file =
+ ShareableFileReference::GetOrCreate(
+ file_path,
+ ShareableFileReference::DELETE_ON_FINAL_RELEASE,
+ BrowserThread::GetMessageLoopProxyForThread(
+ BrowserThread::FILE).get());
+
+ scoped_ptr<net::FileStream> file_stream(new net::FileStream(
+ file_handle.ReleaseValue(),
+ base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_ASYNC,
+ NULL));
+
+ callback.Run(error_code, file_stream.Pass(), deletable_file);
+}
+
+} // namespace
+
+void CreateTemporaryFileStream(
+ const CreateTemporaryFileStreamCallback& callback) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+
+ base::FileUtilProxy::CreateTemporary(
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE).get(),
+ base::PLATFORM_FILE_ASYNC,
+ base::Bind(&DidCreateTemporaryFile, callback));
+}
+
+} // namespace content
« 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