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

Side by Side Diff: content/browser/download/download_file_impl.cc

Issue 2315613002: Extracted NetLog class's inner enum types into their own enum classes and (Closed)
Patch Set: Ran "git cl format" on code. Much formatting ensued. Created 4 years, 3 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/download/download_file_impl.h" 5 #include "content/browser/download/download_file_impl.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "content/browser/byte_stream.h" 15 #include "content/browser/byte_stream.h"
16 #include "content/browser/download/download_create_info.h" 16 #include "content/browser/download/download_create_info.h"
17 #include "content/browser/download/download_destination_observer.h" 17 #include "content/browser/download/download_destination_observer.h"
18 #include "content/browser/download/download_interrupt_reasons_impl.h" 18 #include "content/browser/download/download_interrupt_reasons_impl.h"
19 #include "content/browser/download/download_net_log_parameters.h" 19 #include "content/browser/download/download_net_log_parameters.h"
20 #include "content/browser/download/download_stats.h" 20 #include "content/browser/download/download_stats.h"
21 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
22 #include "crypto/secure_hash.h" 22 #include "crypto/secure_hash.h"
23 #include "crypto/sha2.h" 23 #include "crypto/sha2.h"
24 #include "net/base/io_buffer.h" 24 #include "net/base/io_buffer.h"
25 #include "net/log/net_log_event_type.h"
26 #include "net/log/net_log_source_type.h"
25 27
26 namespace content { 28 namespace content {
27 29
28 const int kUpdatePeriodMs = 500; 30 const int kUpdatePeriodMs = 500;
29 const int kMaxTimeBlockingFileThreadMs = 1000; 31 const int kMaxTimeBlockingFileThreadMs = 1000;
30 32
31 // These constants control the default retry behavior for failing renames. Each 33 // These constants control the default retry behavior for failing renames. Each
32 // retry is performed after a delay that is twice the previous delay. The 34 // retry is performed after a delay that is twice the previous delay. The
33 // initial delay is specified by kInitialRenameRetryDelayMs. 35 // initial delay is specified by kInitialRenameRetryDelayMs.
34 const int kInitialRenameRetryDelayMs = 200; 36 const int kInitialRenameRetryDelayMs = 200;
35 37
36 // Number of times a failing rename is retried before giving up. 38 // Number of times a failing rename is retried before giving up.
37 const int kMaxRenameRetries = 3; 39 const int kMaxRenameRetries = 3;
38 40
39 DownloadFileImpl::DownloadFileImpl( 41 DownloadFileImpl::DownloadFileImpl(
40 std::unique_ptr<DownloadSaveInfo> save_info, 42 std::unique_ptr<DownloadSaveInfo> save_info,
41 const base::FilePath& default_download_directory, 43 const base::FilePath& default_download_directory,
42 std::unique_ptr<ByteStreamReader> stream, 44 std::unique_ptr<ByteStreamReader> stream,
43 const net::BoundNetLog& download_item_net_log, 45 const net::BoundNetLog& download_item_net_log,
44 base::WeakPtr<DownloadDestinationObserver> observer) 46 base::WeakPtr<DownloadDestinationObserver> observer)
45 : bound_net_log_(net::BoundNetLog::Make(download_item_net_log.net_log(), 47 : bound_net_log_(
46 net::NetLog::SOURCE_DOWNLOAD_FILE)), 48 net::BoundNetLog::Make(download_item_net_log.net_log(),
49 net::NetLogSourceType::DOWNLOAD_FILE)),
47 file_(bound_net_log_), 50 file_(bound_net_log_),
48 save_info_(std::move(save_info)), 51 save_info_(std::move(save_info)),
49 default_download_directory_(default_download_directory), 52 default_download_directory_(default_download_directory),
50 stream_reader_(std::move(stream)), 53 stream_reader_(std::move(stream)),
51 bytes_seen_(0), 54 bytes_seen_(0),
52 observer_(observer), 55 observer_(observer),
53 weak_factory_(this) { 56 weak_factory_(this) {
54 download_item_net_log.AddEvent( 57 download_item_net_log.AddEvent(
55 net::NetLog::TYPE_DOWNLOAD_FILE_CREATED, 58 net::NetLogEventType::DOWNLOAD_FILE_CREATED,
56 bound_net_log_.source().ToEventParametersCallback()); 59 bound_net_log_.source().ToEventParametersCallback());
57 bound_net_log_.BeginEvent( 60 bound_net_log_.BeginEvent(
58 net::NetLog::TYPE_DOWNLOAD_FILE_ACTIVE, 61 net::NetLogEventType::DOWNLOAD_FILE_ACTIVE,
59 download_item_net_log.source().ToEventParametersCallback()); 62 download_item_net_log.source().ToEventParametersCallback());
60 } 63 }
61 64
62 DownloadFileImpl::~DownloadFileImpl() { 65 DownloadFileImpl::~DownloadFileImpl() {
63 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 66 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
64 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_FILE_ACTIVE); 67 bound_net_log_.EndEvent(net::NetLogEventType::DOWNLOAD_FILE_ACTIVE);
65 } 68 }
66 69
67 void DownloadFileImpl::Initialize(const InitializeCallback& callback) { 70 void DownloadFileImpl::Initialize(const InitializeCallback& callback) {
68 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 71 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
69 72
70 update_timer_.reset(new base::RepeatingTimer()); 73 update_timer_.reset(new base::RepeatingTimer());
71 DownloadInterruptReason result = 74 DownloadInterruptReason result =
72 file_.Initialize(save_info_->file_path, 75 file_.Initialize(save_info_->file_path,
73 default_download_directory_, 76 default_download_directory_,
74 std::move(save_info_->file), 77 std::move(save_info_->file),
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 std::unique_ptr<crypto::SecureHash> hash_state = file_.Finish(); 328 std::unique_ptr<crypto::SecureHash> hash_state = file_.Finish();
326 BrowserThread::PostTask( 329 BrowserThread::PostTask(
327 BrowserThread::UI, 330 BrowserThread::UI,
328 FROM_HERE, 331 FROM_HERE,
329 base::Bind(&DownloadDestinationObserver::DestinationCompleted, 332 base::Bind(&DownloadDestinationObserver::DestinationCompleted,
330 observer_, 333 observer_,
331 file_.bytes_so_far(), 334 file_.bytes_so_far(),
332 base::Passed(&hash_state))); 335 base::Passed(&hash_state)));
333 } 336 }
334 if (bound_net_log_.IsCapturing()) { 337 if (bound_net_log_.IsCapturing()) {
335 bound_net_log_.AddEvent( 338 bound_net_log_.AddEvent(net::NetLogEventType::DOWNLOAD_STREAM_DRAINED,
336 net::NetLog::TYPE_DOWNLOAD_STREAM_DRAINED, 339 base::Bind(&FileStreamDrainedNetLogCallback,
337 base::Bind(&FileStreamDrainedNetLogCallback, total_incoming_data_size, 340 total_incoming_data_size, num_buffers));
338 num_buffers));
339 } 341 }
340 } 342 }
341 343
342 void DownloadFileImpl::SendUpdate() { 344 void DownloadFileImpl::SendUpdate() {
343 BrowserThread::PostTask( 345 BrowserThread::PostTask(
344 BrowserThread::UI, 346 BrowserThread::UI,
345 FROM_HERE, 347 FROM_HERE,
346 base::Bind(&DownloadDestinationObserver::DestinationUpdate, 348 base::Bind(&DownloadDestinationObserver::DestinationUpdate,
347 observer_, 349 observer_,
348 file_.bytes_so_far(), 350 file_.bytes_so_far(),
349 rate_estimator_.GetCountPerSecond())); 351 rate_estimator_.GetCountPerSecond()));
350 } 352 }
351 353
352 DownloadFileImpl::RenameParameters::RenameParameters( 354 DownloadFileImpl::RenameParameters::RenameParameters(
353 RenameOption option, 355 RenameOption option,
354 const base::FilePath& new_path, 356 const base::FilePath& new_path,
355 const RenameCompletionCallback& completion_callback) 357 const RenameCompletionCallback& completion_callback)
356 : option(option), 358 : option(option),
357 new_path(new_path), 359 new_path(new_path),
358 retries_left(kMaxRenameRetries), 360 retries_left(kMaxRenameRetries),
359 completion_callback(completion_callback) {} 361 completion_callback(completion_callback) {}
360 362
361 DownloadFileImpl::RenameParameters::~RenameParameters() {} 363 DownloadFileImpl::RenameParameters::~RenameParameters() {}
362 364
363 } // namespace content 365 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/base_file_win.cc ('k') | content/browser/download/download_item_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698