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

Side by Side Diff: content/common/net/url_fetcher.cc

Issue 8315011: base::Bind: Convert FileUtilProxy::CreateTemporaryCallback. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Newfangled pipelining. Created 9 years, 2 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
« no previous file with comments | « content/browser/renderer_host/redirect_to_file_resource_handler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/common/net/url_fetcher.h" 5 #include "content/common/net/url_fetcher.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h"
9 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
10 #include "base/file_path.h" 11 #include "base/file_path.h"
11 #include "base/file_util_proxy.h" 12 #include "base/file_util_proxy.h"
12 #include "base/lazy_instance.h" 13 #include "base/lazy_instance.h"
13 #include "base/memory/scoped_callback_factory.h" 14 #include "base/memory/scoped_callback_factory.h"
14 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/weak_ptr.h"
15 #include "base/message_loop_proxy.h" 17 #include "base/message_loop_proxy.h"
16 #include "base/platform_file.h" 18 #include "base/platform_file.h"
17 #include "base/stl_util.h" 19 #include "base/stl_util.h"
18 #include "base/string_util.h" 20 #include "base/string_util.h"
19 #include "base/threading/thread.h" 21 #include "base/threading/thread.h"
20 #include "googleurl/src/gurl.h" 22 #include "googleurl/src/gurl.h"
21 #include "net/base/host_port_pair.h" 23 #include "net/base/host_port_pair.h"
22 #include "net/base/io_buffer.h" 24 #include "net/base/io_buffer.h"
23 #include "net/base/load_flags.h" 25 #include "net/base/load_flags.h"
24 #include "net/base/net_errors.h" 26 #include "net/base/net_errors.h"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 // The URLFetcher::Core which instantiated this class. 144 // The URLFetcher::Core which instantiated this class.
143 URLFetcher::Core* core_; 145 URLFetcher::Core* core_;
144 146
145 // The last error encountered on a file operation. base::PLATFORM_FILE_OK 147 // The last error encountered on a file operation. base::PLATFORM_FILE_OK
146 // if no error occurred. 148 // if no error occurred.
147 base::PlatformFileError error_code_; 149 base::PlatformFileError error_code_;
148 150
149 // Callbacks are created for use with base::FileUtilProxy. 151 // Callbacks are created for use with base::FileUtilProxy.
150 base::ScopedCallbackFactory<URLFetcher::Core::TempFileWriter> 152 base::ScopedCallbackFactory<URLFetcher::Core::TempFileWriter>
151 callback_factory_; 153 callback_factory_;
154 base::WeakPtrFactory<URLFetcher::Core::TempFileWriter> weak_factory_;
152 155
153 // Message loop on which file opperations should happen. 156 // Message loop on which file opperations should happen.
154 scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy_; 157 scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy_;
155 158
156 // Path to the temporary file. This path is empty when there 159 // Path to the temporary file. This path is empty when there
157 // is no temp file. 160 // is no temp file.
158 FilePath temp_file_; 161 FilePath temp_file_;
159 162
160 // Handle to the temp file. 163 // Handle to the temp file.
161 base::PlatformFile temp_file_handle_; 164 base::PlatformFile temp_file_handle_;
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 317
315 // static 318 // static
316 base::LazyInstance<URLFetcher::Core::Registry> 319 base::LazyInstance<URLFetcher::Core::Registry>
317 URLFetcher::Core::g_registry(base::LINKER_INITIALIZED); 320 URLFetcher::Core::g_registry(base::LINKER_INITIALIZED);
318 321
319 URLFetcher::Core::TempFileWriter::TempFileWriter( 322 URLFetcher::Core::TempFileWriter::TempFileWriter(
320 URLFetcher::Core* core, 323 URLFetcher::Core* core,
321 scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy) 324 scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy)
322 : core_(core), 325 : core_(core),
323 error_code_(base::PLATFORM_FILE_OK), 326 error_code_(base::PLATFORM_FILE_OK),
324 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 327 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)),
328 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
325 file_message_loop_proxy_(file_message_loop_proxy), 329 file_message_loop_proxy_(file_message_loop_proxy),
326 temp_file_handle_(base::kInvalidPlatformFileValue) { 330 temp_file_handle_(base::kInvalidPlatformFileValue) {
327 } 331 }
328 332
329 URLFetcher::Core::TempFileWriter::~TempFileWriter() { 333 URLFetcher::Core::TempFileWriter::~TempFileWriter() {
330 RemoveTempFile(); 334 RemoveTempFile();
331 } 335 }
332 336
333 void URLFetcher::Core::TempFileWriter::CreateTempFile() { 337 void URLFetcher::Core::TempFileWriter::CreateTempFile() {
334 DCHECK(core_->io_message_loop_proxy_->BelongsToCurrentThread()); 338 DCHECK(core_->io_message_loop_proxy_->BelongsToCurrentThread());
335 CHECK(file_message_loop_proxy_.get()); 339 CHECK(file_message_loop_proxy_.get());
336 base::FileUtilProxy::CreateTemporary( 340 base::FileUtilProxy::CreateTemporary(
337 file_message_loop_proxy_, 341 file_message_loop_proxy_,
338 0, // No additional file flags. 342 0, // No additional file flags.
339 callback_factory_.NewCallback( 343 base::Bind(&URLFetcher::Core::TempFileWriter::DidCreateTempFile,
340 &URLFetcher::Core::TempFileWriter::DidCreateTempFile)); 344 weak_factory_.GetWeakPtr()));
341 } 345 }
342 346
343 void URLFetcher::Core::TempFileWriter::DidCreateTempFile( 347 void URLFetcher::Core::TempFileWriter::DidCreateTempFile(
344 base::PlatformFileError error_code, 348 base::PlatformFileError error_code,
345 base::PassPlatformFile file_handle, 349 base::PassPlatformFile file_handle,
346 FilePath file_path) { 350 FilePath file_path) {
347 DCHECK(core_->io_message_loop_proxy_->BelongsToCurrentThread()); 351 DCHECK(core_->io_message_loop_proxy_->BelongsToCurrentThread());
348 352
349 if (base::PLATFORM_FILE_OK != error_code) { 353 if (base::PLATFORM_FILE_OK != error_code) {
350 error_code_ = error_code; 354 error_code_ = error_code;
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after
1134 } 1138 }
1135 1139
1136 // static 1140 // static
1137 int URLFetcher::GetNumFetcherCores() { 1141 int URLFetcher::GetNumFetcherCores() {
1138 return Core::g_registry.Get().size(); 1142 return Core::g_registry.Get().size();
1139 } 1143 }
1140 1144
1141 URLFetcher::Delegate* URLFetcher::delegate() const { 1145 URLFetcher::Delegate* URLFetcher::delegate() const {
1142 return core_->delegate(); 1146 return core_->delegate();
1143 } 1147 }
OLDNEW
« no previous file with comments | « content/browser/renderer_host/redirect_to_file_resource_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698