OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "components/download/content/driver_entry.h" | |
6 | |
7 #include "content/public/browser/download_item.h" | |
8 #include "net/http/http_response_headers.h" | |
9 | |
10 namespace download { | |
11 | |
12 // Converts a content::DownloadItem::DownloadState to DriverEntry::State. | |
13 namespace { | |
14 | |
15 DriverEntry::State ToDriverEntryState( | |
16 content::DownloadItem::DownloadState state) { | |
17 switch (state) { | |
18 case content::DownloadItem::IN_PROGRESS: | |
19 return DriverEntry::State::IN_PROGRESS; | |
20 case content::DownloadItem::COMPLETE: | |
21 return DriverEntry::State::COMPLETE; | |
22 case content::DownloadItem::CANCELLED: | |
23 return DriverEntry::State::CANCELLED; | |
24 case content::DownloadItem::INTERRUPTED: | |
25 return DriverEntry::State::INTERRUPTED; | |
26 case content::DownloadItem::MAX_DOWNLOAD_STATE: | |
27 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.
| |
28 } | |
29 NOTREACHED(); | |
30 return DriverEntry::State::UNKNOWN; | |
31 } | |
32 | |
33 } // namespace | |
34 | |
35 // static | |
36 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
| |
37 DriverEntry entry; | |
38 if (!item) | |
39 return entry; | |
40 entry.guid = item->GetGuid(); | |
41 entry.state = ToDriverEntryState(item->GetState()); | |
42 entry.paused = item->IsPaused(); | |
43 entry.bytes_downloaded = item->GetReceivedBytes(); | |
44 entry.expected_total_size = item->GetTotalBytes(); | |
45 entry.response_headers = item->GetResponseHeaders(); | |
46 return entry; | |
47 } | |
48 | |
49 DriverEntry::DriverEntry() | |
50 : state(State::UNKNOWN), | |
51 paused(false), | |
52 bytes_downloaded(0u), | |
53 expected_total_size(0u) {} | |
54 | |
55 DriverEntry::DriverEntry(const DriverEntry& other) = default; | |
56 | |
57 DriverEntry::~DriverEntry() = default; | |
58 | |
59 bool DriverEntry::empty() const { | |
60 return state == State::UNKNOWN || guid.empty(); | |
61 } | |
62 | |
63 } // namespace download | |
OLD | NEW |