Index: components/download/content/driver_entry.cc |
diff --git a/components/download/content/driver_entry.cc b/components/download/content/driver_entry.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..006c8d1602554dccccfc1aa0aa5d5a9109edf794 |
--- /dev/null |
+++ b/components/download/content/driver_entry.cc |
@@ -0,0 +1,63 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "components/download/content/driver_entry.h" |
+ |
+#include "content/public/browser/download_item.h" |
+#include "net/http/http_response_headers.h" |
+ |
+namespace download { |
+ |
+// Converts a content::DownloadItem::DownloadState to DriverEntry::State. |
+namespace { |
+ |
+DriverEntry::State ToDriverEntryState( |
+ content::DownloadItem::DownloadState state) { |
+ switch (state) { |
+ case content::DownloadItem::IN_PROGRESS: |
+ return DriverEntry::State::IN_PROGRESS; |
+ case content::DownloadItem::COMPLETE: |
+ return DriverEntry::State::COMPLETE; |
+ case content::DownloadItem::CANCELLED: |
+ return DriverEntry::State::CANCELLED; |
+ case content::DownloadItem::INTERRUPTED: |
+ return DriverEntry::State::INTERRUPTED; |
+ case content::DownloadItem::MAX_DOWNLOAD_STATE: |
+ return DriverEntry::State::UNKNOWN; |
David Trainor- moved to gerrit
2017/05/18 18:29:44
move the bottom two lines to default?
xingliu
2017/05/18 22:21:50
Done.
|
+ } |
+ NOTREACHED(); |
+ return DriverEntry::State::UNKNOWN; |
+} |
+ |
+} // namespace |
+ |
+// static |
+DriverEntry DriverEntry::Create(const content::DownloadItem* item) { |
David Trainor- moved to gerrit
2017/05/18 18:29:44
Move this to somewhere in content/. You'll have t
xingliu
2017/05/18 22:21:50
Done. This is now a static function in driver impl
|
+ DriverEntry entry; |
+ if (!item) |
+ return entry; |
+ entry.guid = item->GetGuid(); |
+ entry.state = ToDriverEntryState(item->GetState()); |
+ entry.paused = item->IsPaused(); |
+ entry.bytes_downloaded = item->GetReceivedBytes(); |
+ entry.expected_total_size = item->GetTotalBytes(); |
+ entry.response_headers = item->GetResponseHeaders(); |
+ return entry; |
+} |
+ |
+DriverEntry::DriverEntry() |
+ : state(State::UNKNOWN), |
+ paused(false), |
+ bytes_downloaded(0u), |
+ expected_total_size(0u) {} |
+ |
+DriverEntry::DriverEntry(const DriverEntry& other) = default; |
+ |
+DriverEntry::~DriverEntry() = default; |
+ |
+bool DriverEntry::empty() const { |
+ return state == State::UNKNOWN || guid.empty(); |
+} |
+ |
+} // namespace download |