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

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

Issue 2785523002: Reduce/remove usage of BrowserThread in content/browser/loader. (Closed)
Patch Set: Fix unittests redness Created 3 years, 8 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/browser/loader/temporary_file_stream.h" 5 #include "content/browser/loader/temporary_file_stream.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/files/file_proxy.h" 11 #include "base/files/file_proxy.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "content/browser/loader/loader_globals.h"
13 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
14 #include "net/base/file_stream.h" 15 #include "net/base/file_stream.h"
15 #include "storage/browser/blob/shareable_file_reference.h" 16 #include "storage/browser/blob/shareable_file_reference.h"
16 17
17 using storage::ShareableFileReference; 18 using storage::ShareableFileReference;
18 19
19 namespace content { 20 namespace content {
20 21
21 namespace { 22 namespace {
22 23
23 void DidCreateTemporaryFile(const CreateTemporaryFileStreamCallback& callback, 24 void DidCreateTemporaryFile(const CreateTemporaryFileStreamCallback& callback,
24 std::unique_ptr<base::FileProxy> file_proxy, 25 std::unique_ptr<base::FileProxy> file_proxy,
25 base::File::Error error_code, 26 base::File::Error error_code,
26 const base::FilePath& file_path) { 27 const base::FilePath& file_path) {
27 DCHECK_CURRENTLY_ON(BrowserThread::IO); 28 DCHECK(
29 LoaderGlobals::Get()->io_thread_task_runner()->BelongsToCurrentThread());
28 30
29 if (!file_proxy->IsValid()) { 31 if (!file_proxy->IsValid()) {
30 callback.Run(error_code, std::unique_ptr<net::FileStream>(), NULL); 32 callback.Run(error_code, std::unique_ptr<net::FileStream>(), NULL);
31 return; 33 return;
32 } 34 }
33 35
34 scoped_refptr<base::TaskRunner> task_runner = 36 scoped_refptr<base::TaskRunner> task_runner =
35 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE); 37 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE);
36 38
37 // Cancelled or not, create the deletable_file so the temporary is cleaned up. 39 // Cancelled or not, create the deletable_file so the temporary is cleaned up.
38 scoped_refptr<ShareableFileReference> deletable_file = 40 scoped_refptr<ShareableFileReference> deletable_file =
39 ShareableFileReference::GetOrCreate( 41 ShareableFileReference::GetOrCreate(
40 file_path, 42 file_path,
41 ShareableFileReference::DELETE_ON_FINAL_RELEASE, 43 ShareableFileReference::DELETE_ON_FINAL_RELEASE,
42 task_runner.get()); 44 task_runner.get());
43 45
44 std::unique_ptr<net::FileStream> file_stream( 46 std::unique_ptr<net::FileStream> file_stream(
45 new net::FileStream(file_proxy->TakeFile(), task_runner)); 47 new net::FileStream(file_proxy->TakeFile(), task_runner));
46 48
47 callback.Run(error_code, std::move(file_stream), deletable_file.get()); 49 callback.Run(error_code, std::move(file_stream), deletable_file.get());
48 } 50 }
49 51
50 } // namespace 52 } // namespace
51 53
52 void CreateTemporaryFileStream( 54 void CreateTemporaryFileStream(
53 const CreateTemporaryFileStreamCallback& callback) { 55 const CreateTemporaryFileStreamCallback& callback) {
54 DCHECK_CURRENTLY_ON(BrowserThread::IO); 56 DCHECK(
57 LoaderGlobals::Get()->io_thread_task_runner()->BelongsToCurrentThread());
jam 2017/03/29 15:44:33 this is only called by redirect_to_file_resource_h
ananta 2017/03/29 19:41:04 Done.
55 58
56 std::unique_ptr<base::FileProxy> file_proxy(new base::FileProxy( 59 std::unique_ptr<base::FileProxy> file_proxy(new base::FileProxy(
57 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE).get())); 60 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE).get()));
58 base::FileProxy* proxy = file_proxy.get(); 61 base::FileProxy* proxy = file_proxy.get();
59 proxy->CreateTemporary( 62 proxy->CreateTemporary(
60 base::File::FLAG_ASYNC, 63 base::File::FLAG_ASYNC,
61 base::Bind(&DidCreateTemporaryFile, callback, Passed(&file_proxy))); 64 base::Bind(&DidCreateTemporaryFile, callback, Passed(&file_proxy)));
62 } 65 }
63 66
64 } // namespace content 67 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698