| OLD | NEW |
| 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/bind.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 12 #include "base/file_util_proxy.h" | 12 #include "base/file_util_proxy.h" |
| 13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 14 #include "base/memory/scoped_callback_factory.h" | |
| 15 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 17 #include "base/message_loop_proxy.h" | 16 #include "base/message_loop_proxy.h" |
| 18 #include "base/platform_file.h" | 17 #include "base/platform_file.h" |
| 19 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
| 20 #include "base/string_util.h" | 19 #include "base/string_util.h" |
| 21 #include "base/threading/thread.h" | 20 #include "base/threading/thread.h" |
| 22 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
| 23 #include "net/base/host_port_pair.h" | 22 #include "net/base/host_port_pair.h" |
| 24 #include "net/base/io_buffer.h" | 23 #include "net/base/io_buffer.h" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 void DidCloseTempFile(base::PlatformFileError error); | 141 void DidCloseTempFile(base::PlatformFileError error); |
| 143 | 142 |
| 144 // The URLFetcher::Core which instantiated this class. | 143 // The URLFetcher::Core which instantiated this class. |
| 145 URLFetcher::Core* core_; | 144 URLFetcher::Core* core_; |
| 146 | 145 |
| 147 // The last error encountered on a file operation. base::PLATFORM_FILE_OK | 146 // The last error encountered on a file operation. base::PLATFORM_FILE_OK |
| 148 // if no error occurred. | 147 // if no error occurred. |
| 149 base::PlatformFileError error_code_; | 148 base::PlatformFileError error_code_; |
| 150 | 149 |
| 151 // Callbacks are created for use with base::FileUtilProxy. | 150 // Callbacks are created for use with base::FileUtilProxy. |
| 152 base::ScopedCallbackFactory<URLFetcher::Core::TempFileWriter> | |
| 153 callback_factory_; | |
| 154 base::WeakPtrFactory<URLFetcher::Core::TempFileWriter> weak_factory_; | 151 base::WeakPtrFactory<URLFetcher::Core::TempFileWriter> weak_factory_; |
| 155 | 152 |
| 156 // Message loop on which file opperations should happen. | 153 // Message loop on which file operations should happen. |
| 157 scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy_; | 154 scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy_; |
| 158 | 155 |
| 159 // Path to the temporary file. This path is empty when there | 156 // Path to the temporary file. This path is empty when there |
| 160 // is no temp file. | 157 // is no temp file. |
| 161 FilePath temp_file_; | 158 FilePath temp_file_; |
| 162 | 159 |
| 163 // Handle to the temp file. | 160 // Handle to the temp file. |
| 164 base::PlatformFile temp_file_handle_; | 161 base::PlatformFile temp_file_handle_; |
| 165 | 162 |
| 166 // We always append to the file. Track the total number of bytes | 163 // We always append to the file. Track the total number of bytes |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 | 314 |
| 318 // static | 315 // static |
| 319 base::LazyInstance<URLFetcher::Core::Registry> | 316 base::LazyInstance<URLFetcher::Core::Registry> |
| 320 URLFetcher::Core::g_registry(base::LINKER_INITIALIZED); | 317 URLFetcher::Core::g_registry(base::LINKER_INITIALIZED); |
| 321 | 318 |
| 322 URLFetcher::Core::TempFileWriter::TempFileWriter( | 319 URLFetcher::Core::TempFileWriter::TempFileWriter( |
| 323 URLFetcher::Core* core, | 320 URLFetcher::Core* core, |
| 324 scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy) | 321 scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy) |
| 325 : core_(core), | 322 : core_(core), |
| 326 error_code_(base::PLATFORM_FILE_OK), | 323 error_code_(base::PLATFORM_FILE_OK), |
| 327 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)), | |
| 328 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 324 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
| 329 file_message_loop_proxy_(file_message_loop_proxy), | 325 file_message_loop_proxy_(file_message_loop_proxy), |
| 330 temp_file_handle_(base::kInvalidPlatformFileValue) { | 326 temp_file_handle_(base::kInvalidPlatformFileValue) { |
| 331 } | 327 } |
| 332 | 328 |
| 333 URLFetcher::Core::TempFileWriter::~TempFileWriter() { | 329 URLFetcher::Core::TempFileWriter::~TempFileWriter() { |
| 334 RemoveTempFile(); | 330 RemoveTempFile(); |
| 335 } | 331 } |
| 336 | 332 |
| 337 void URLFetcher::Core::TempFileWriter::CreateTempFile() { | 333 void URLFetcher::Core::TempFileWriter::CreateTempFile() { |
| (...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1133 } | 1129 } |
| 1134 | 1130 |
| 1135 // static | 1131 // static |
| 1136 int URLFetcher::GetNumFetcherCores() { | 1132 int URLFetcher::GetNumFetcherCores() { |
| 1137 return Core::g_registry.Get().size(); | 1133 return Core::g_registry.Get().size(); |
| 1138 } | 1134 } |
| 1139 | 1135 |
| 1140 URLFetcher::Delegate* URLFetcher::delegate() const { | 1136 URLFetcher::Delegate* URLFetcher::delegate() const { |
| 1141 return core_->delegate(); | 1137 return core_->delegate(); |
| 1142 } | 1138 } |
| OLD | NEW |