1 // Copyright 2018 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 <sstream>
6 #include "base/strings/string_number_conversions.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "components/offline_pages/core/offline_store_utils.h"
9 #include "components/offline_pages/core/prefetch/prefetch_item.h"
10
11 namespace offline_pages {
12
ToString() const13 std::string PrefetchItem::ToString() const {
14 std::stringstream s;
15 s << "PrefetchItem(id=" << offline_id << ", guid=" << guid << ", "
16 << client_id << ", state=" << state
17 << ", url=" << url.possibly_invalid_spec()
18 << ", final_url=" << final_archived_url.possibly_invalid_spec()
19 << ", thumbnail_url=" << thumbnail_url.possibly_invalid_spec()
20 << ", favicon_url=" << favicon_url.possibly_invalid_spec()
21 << ", snippet=" << snippet << ", attribution=" << attribution
22 << ", gb_attempts=" << generate_bundle_attempts
23 << ", get_attempts=" << get_operation_attempts
24 << ", dl_attempts=" << download_initiation_attempts
25 << ", operation=" << operation_name << ", body_name=" << archive_body_name
26 << ", body_len=" << archive_body_length
27 << ", creation_time=" << store_utils::ToDatabaseTime(creation_time)
28 << ", freshness_time=" << store_utils::ToDatabaseTime(freshness_time)
29 << ", error=" << error_code << ", title=" << base::UTF16ToUTF8(title)
30 << ", file_path=" << file_path.AsUTF8Unsafe() << ", file_size=" << file_size
31 << ")";
32 return s.str();
33 }
34
operator <<(std::ostream & out,const PrefetchItem & pi)35 std::ostream& operator<<(std::ostream& out, const PrefetchItem& pi) {
36 return out << pi.ToString();
37 }
38
39 PrefetchItem::PrefetchItem(const PrefetchItem& other) = default;
40
41 PrefetchItem& PrefetchItem::operator=(const PrefetchItem& other) = default;
42
43 PrefetchItem& PrefetchItem::operator=(PrefetchItem&& other) = default;
44
operator ==(const PrefetchItem & other) const45 bool PrefetchItem::operator==(const PrefetchItem& other) const {
46 return offline_id == other.offline_id && guid == other.guid &&
47 client_id == other.client_id && state == other.state &&
48 url == other.url && final_archived_url == other.final_archived_url &&
49 thumbnail_url == other.thumbnail_url &&
50 favicon_url == other.favicon_url && snippet == other.snippet &&
51 attribution == other.attribution &&
52 generate_bundle_attempts == other.generate_bundle_attempts &&
53 get_operation_attempts == other.get_operation_attempts &&
54 download_initiation_attempts == other.download_initiation_attempts &&
55 operation_name == other.operation_name &&
56 archive_body_name == other.archive_body_name &&
57 archive_body_length == other.archive_body_length &&
58 creation_time == other.creation_time &&
59 freshness_time == other.freshness_time &&
60 error_code == other.error_code && title == other.title &&
61 file_path == other.file_path && file_size == other.file_size;
62 }
63
operator !=(const PrefetchItem & other) const64 bool PrefetchItem::operator!=(const PrefetchItem& other) const {
65 return !(*this == other);
66 }
67
operator <(const PrefetchItem & other) const68 bool PrefetchItem::operator<(const PrefetchItem& other) const {
69 return offline_id < other.offline_id;
70 }
71
72 } // namespace offline_pages
73