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/internal/test/test_download_driver.h" | |
6 | |
7 #include "base/files/file_path.h" | |
8 #include "components/download/public/download_params.h" | |
9 #include "net/http/http_response_headers.h" | |
10 | |
11 namespace download { | |
12 | |
13 TestDownloadDriver::TestDownloadDriver() : is_ready_(false), client_(nullptr) {} | |
14 | |
15 TestDownloadDriver::~TestDownloadDriver() = default; | |
16 | |
17 void TestDownloadDriver::MakeReady() { | |
18 is_ready_ = true; | |
19 DCHECK(client_); | |
20 if (client_) | |
21 client_->OnDriverReady(is_ready_); | |
22 } | |
23 | |
24 void TestDownloadDriver::NotifyDownloadUpdate(const DriverEntry& entry) { | |
25 if (client_) { | |
26 entries_[entry.guid] = entry; | |
27 client_->OnDownloadUpdated(entry); | |
28 } | |
29 } | |
30 | |
31 void TestDownloadDriver::NotifyDownloadFailed(const DriverEntry& entry, | |
32 int reason) { | |
33 if (client_) { | |
34 entries_[entry.guid] = entry; | |
35 client_->OnDownloadFailed(entry, reason); | |
36 } | |
37 } | |
38 | |
39 void TestDownloadDriver::NotifyDownloadSucceeded(const DriverEntry& entry, | |
40 const base::FilePath& path) { | |
41 if (client_) { | |
42 entries_[entry.guid] = entry; | |
43 client_->OnDownloadSucceeded(entry, path); | |
44 } | |
45 } | |
46 | |
47 void TestDownloadDriver::Initialize(DownloadDriver::Client* client) { | |
48 DCHECK(!client_); | |
49 client_ = client; | |
50 } | |
51 | |
52 bool TestDownloadDriver::IsReady() const { | |
53 return is_ready_; | |
54 } | |
55 | |
56 void TestDownloadDriver::Start(const DownloadParams& params) { | |
57 DriverEntry entry; | |
58 entry.guid = params.guid; | |
59 entry.state = DriverEntry::State::IN_PROGRESS; | |
60 entry.paused = false; | |
61 entry.bytes_downloaded = 0; | |
62 entry.expected_total_size = 0; | |
63 entry.response_headers = | |
64 make_scoped_refptr(new net::HttpResponseHeaders("HTTP/1.1 200")); | |
dcheng
2017/05/23 05:35:08
Nit: consider using base::MakeRefCounted<net::Http
xingliu
2017/05/23 16:56:13
Done.
| |
65 entries_[params.guid] = entry; | |
66 | |
67 if (client_) | |
68 client_->OnDownloadCreated(entry); | |
69 } | |
70 | |
71 void TestDownloadDriver::Cancel(const std::string& guid) {} | |
72 | |
73 void TestDownloadDriver::Pause(const std::string& guid) {} | |
74 | |
75 void TestDownloadDriver::Resume(const std::string& guid) {} | |
76 | |
77 base::Optional<DriverEntry> TestDownloadDriver::Find(const std::string& guid) { | |
78 auto it = entries_.find(guid); | |
79 if (it == entries_.end()) | |
80 return base::nullopt; | |
81 return it->second; | |
82 } | |
83 | |
84 } // namespace downloads | |
OLD | NEW |