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

Side by Side Diff: components/component_updater/background_downloader_win.cc

Issue 590333002: Replace usage of basictypes.h with a combination of stdint.h and base/macros.h. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Created 6 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 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 "components/component_updater/background_downloader_win.h" 5 #include "components/component_updater/background_downloader_win.h"
6 6
7 #include <atlbase.h> 7 #include <atlbase.h>
8 #include <atlcom.h> 8 #include <atlcom.h>
9 9
10 #include <stdint.h>
10 #include <functional> 11 #include <functional>
11 #include <iomanip> 12 #include <iomanip>
13 #include <limits>
12 #include <vector> 14 #include <vector>
13 15
16 #include "base/bind.h"
17 #include "base/bind_helpers.h"
14 #include "base/files/file_util.h" 18 #include "base/files/file_util.h"
15 #include "base/message_loop/message_loop_proxy.h" 19 #include "base/message_loop/message_loop_proxy.h"
16 #include "base/single_thread_task_runner.h" 20 #include "base/single_thread_task_runner.h"
17 #include "base/strings/sys_string_conversions.h" 21 #include "base/strings/sys_string_conversions.h"
18 #include "base/win/scoped_co_mem.h" 22 #include "base/win/scoped_co_mem.h"
19 #include "components/component_updater/component_updater_utils.h" 23 #include "components/component_updater/component_updater_utils.h"
20 #include "ui/base/win/atl_module.h" 24 #include "ui/base/win/atl_module.h"
21 #include "url/gurl.h" 25 #include "url/gurl.h"
22 26
23 using base::win::ScopedCoMem; 27 using base::win::ScopedCoMem;
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 *progress = bg_file_progress; 196 *progress = bg_file_progress;
193 } 197 }
194 198
195 return hr; 199 return hr;
196 } 200 }
197 201
198 // Returns the number of bytes downloaded and bytes to download for all files 202 // Returns the number of bytes downloaded and bytes to download for all files
199 // in the job. If the values are not known or if an error has occurred, 203 // in the job. If the values are not known or if an error has occurred,
200 // a value of -1 is reported. 204 // a value of -1 is reported.
201 HRESULT GetJobByteCount(IBackgroundCopyJob* job, 205 HRESULT GetJobByteCount(IBackgroundCopyJob* job,
202 int64* downloaded_bytes, 206 int64_t* downloaded_bytes,
203 int64* total_bytes) { 207 int64_t* total_bytes) {
204 *downloaded_bytes = -1; 208 *downloaded_bytes = -1;
205 *total_bytes = -1; 209 *total_bytes = -1;
206 210
207 if (!job) 211 if (!job)
208 return E_FAIL; 212 return E_FAIL;
209 213
210 BG_JOB_PROGRESS job_progress = {0}; 214 BG_JOB_PROGRESS job_progress = {0};
211 HRESULT hr = job->GetProgress(&job_progress); 215 HRESULT hr = job->GetProgress(&job_progress);
212 if (FAILED(hr)) 216 if (FAILED(hr))
213 return hr; 217 return hr;
214 218
215 if (job_progress.BytesTransferred <= kint64max) 219 const uint64_t kMaxNumBytes =
220 static_cast<uint64_t>(std::numeric_limits<int64_t>::max());
221 if (job_progress.BytesTransferred <= kMaxNumBytes)
216 *downloaded_bytes = job_progress.BytesTransferred; 222 *downloaded_bytes = job_progress.BytesTransferred;
217 223
218 if (job_progress.BytesTotal <= kint64max && 224 if (job_progress.BytesTotal <= kMaxNumBytes &&
219 job_progress.BytesTotal != BG_SIZE_UNKNOWN) 225 job_progress.BytesTotal != BG_SIZE_UNKNOWN)
220 *total_bytes = job_progress.BytesTotal; 226 *total_bytes = job_progress.BytesTotal;
221 227
222 return S_OK; 228 return S_OK;
223 } 229 }
224 230
225 HRESULT GetJobDescription(IBackgroundCopyJob* job, const base::string16* name) { 231 HRESULT GetJobDescription(IBackgroundCopyJob* job, const base::string16* name) {
226 ScopedCoMem<base::char16> description; 232 ScopedCoMem<base::char16> description;
227 return job->GetDescription(&description); 233 return job->GetDescription(&description);
228 } 234 }
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 is_completed_ = true; 515 is_completed_ = true;
510 516
511 timer_.reset(); 517 timer_.reset();
512 518
513 const base::Time download_end_time(base::Time::Now()); 519 const base::Time download_end_time(base::Time::Now());
514 const base::TimeDelta download_time = 520 const base::TimeDelta download_time =
515 download_end_time >= download_start_time_ 521 download_end_time >= download_start_time_
516 ? download_end_time - download_start_time_ 522 ? download_end_time - download_start_time_
517 : base::TimeDelta(); 523 : base::TimeDelta();
518 524
519 int64 downloaded_bytes = -1; 525 int64_t downloaded_bytes = -1;
520 int64 total_bytes = -1; 526 int64_t total_bytes = -1;
521 GetJobByteCount(job_, &downloaded_bytes, &total_bytes); 527 GetJobByteCount(job_, &downloaded_bytes, &total_bytes);
522 528
523 if (FAILED(error) && job_) { 529 if (FAILED(error) && job_) {
524 job_->Cancel(); 530 job_->Cancel();
525 CleanupJobFiles(job_); 531 CleanupJobFiles(job_);
526 } 532 }
527 533
528 job_ = NULL; 534 job_ = NULL;
529 535
530 CleanupStaleJobs(bits_manager_); 536 CleanupStaleJobs(bits_manager_);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 void BackgroundDownloader::OnStateQueued() { 612 void BackgroundDownloader::OnStateQueued() {
607 if (IsStuck()) 613 if (IsStuck())
608 EndDownload(E_ABORT); // Return a generic error for now. 614 EndDownload(E_ABORT); // Return a generic error for now.
609 } 615 }
610 616
611 void BackgroundDownloader::OnStateTransferring() { 617 void BackgroundDownloader::OnStateTransferring() {
612 // Resets the baseline for detecting a stuck job since the job is transferring 618 // Resets the baseline for detecting a stuck job since the job is transferring
613 // data and it is making progress. 619 // data and it is making progress.
614 job_stuck_begin_time_ = base::Time::Now(); 620 job_stuck_begin_time_ = base::Time::Now();
615 621
616 int64 downloaded_bytes = -1; 622 int64_t downloaded_bytes = -1;
617 int64 total_bytes = -1; 623 int64_t total_bytes = -1;
618 HRESULT hr = GetJobByteCount(job_, &downloaded_bytes, &total_bytes); 624 HRESULT hr = GetJobByteCount(job_, &downloaded_bytes, &total_bytes);
619 if (FAILED(hr)) 625 if (FAILED(hr))
620 return; 626 return;
621 627
622 Result result; 628 Result result;
623 result.downloaded_bytes = downloaded_bytes; 629 result.downloaded_bytes = downloaded_bytes;
624 result.total_bytes = total_bytes; 630 result.total_bytes = total_bytes;
625 631
626 main_task_runner_->PostTask( 632 main_task_runner_->PostTask(
627 FROM_HERE, 633 FROM_HERE,
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 // must match as a job only contains one file. 763 // must match as a job only contains one file.
758 DCHECK(progress.Completed); 764 DCHECK(progress.Completed);
759 DCHECK_EQ(progress.BytesTotal, progress.BytesTransferred); 765 DCHECK_EQ(progress.BytesTotal, progress.BytesTransferred);
760 766
761 response_ = base::FilePath(local_name); 767 response_ = base::FilePath(local_name);
762 768
763 return S_OK; 769 return S_OK;
764 } 770 }
765 771
766 } // namespace component_updater 772 } // namespace component_updater
OLDNEW
« no previous file with comments | « components/component_updater/background_downloader_win.h ('k') | components/component_updater/component_patcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698