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

Unified Diff: components/download/content/driver_entry.cc

Issue 2880933002: Download driver for components/download. (Closed)
Patch Set: Work on feedbacks. Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698