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

Side by Side Diff: chrome/browser/android/history_report/delta_file_commons.cc

Issue 1542413002: Switch to standard integer types in chrome/browser/, part 1 of 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/android/history_report/delta_file_commons.h" 5 #include "chrome/browser/android/history_report/delta_file_commons.h"
6 6
7 #include <stddef.h>
8
7 #include <iomanip> 9 #include <iomanip>
8 10
9 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
11 #include "crypto/sha2.h" 13 #include "crypto/sha2.h"
12 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 14 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
13 15
14 using bookmarks::BookmarkModel; 16 using bookmarks::BookmarkModel;
15 using net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES; 17 using net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES;
16 using net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES; 18 using net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES;
(...skipping 28 matching lines...) Expand all
45 47
46 namespace history_report { 48 namespace history_report {
47 49
48 DeltaFileEntryWithData::DeltaFileEntryWithData(DeltaFileEntry entry) 50 DeltaFileEntryWithData::DeltaFileEntryWithData(DeltaFileEntry entry)
49 : entry_(entry), 51 : entry_(entry),
50 data_set_(false), 52 data_set_(false),
51 is_bookmark_(false) {} 53 is_bookmark_(false) {}
52 54
53 DeltaFileEntryWithData::~DeltaFileEntryWithData() {} 55 DeltaFileEntryWithData::~DeltaFileEntryWithData() {}
54 56
55 int64 DeltaFileEntryWithData::SeqNo() const { 57 int64_t DeltaFileEntryWithData::SeqNo() const {
56 return entry_.seq_no(); 58 return entry_.seq_no();
57 } 59 }
58 60
59 std::string DeltaFileEntryWithData::Type() const { 61 std::string DeltaFileEntryWithData::Type() const {
60 // If deletion entry has data then it's not a real deletion entry 62 // If deletion entry has data then it's not a real deletion entry
61 // but an update entry. Real deletion entry never has data. 63 // but an update entry. Real deletion entry never has data.
62 if (data_set_) return "add"; 64 if (data_set_) return "add";
63 return entry_.type(); 65 return entry_.type();
64 } 66 }
65 67
(...skipping 13 matching lines...) Expand all
79 if (IsValidId(url)) { 81 if (IsValidId(url)) {
80 return url; 82 return url;
81 } 83 }
82 84
83 std::stringstream id; 85 std::stringstream id;
84 86
85 // 1. Zero-padded URL length to width |kUrlLengthWidth|. 87 // 1. Zero-padded URL length to width |kUrlLengthWidth|.
86 id << std::setfill('0') << std::setw(kUrlLengthWidth) << url.size(); 88 id << std::setfill('0') << std::setw(kUrlLengthWidth) << url.size();
87 89
88 // 2. SHA-256 of URL. 90 // 2. SHA-256 of URL.
89 uint8 hash[kSHA256ByteSize]; 91 uint8_t hash[kSHA256ByteSize];
90 crypto::SHA256HashString(url, hash, sizeof(hash)); 92 crypto::SHA256HashString(url, hash, sizeof(hash));
91 id << base::HexEncode(hash, sizeof(hash)); 93 id << base::HexEncode(hash, sizeof(hash));
92 94
93 // 3. Prefix of URL to fill rest of the space. 95 // 3. Prefix of URL to fill rest of the space.
94 id << url.substr(0, kIdLengthLimit - 2 * kSHA256ByteSize - kUrlLengthWidth); 96 id << url.substr(0, kIdLengthLimit - 2 * kSHA256ByteSize - kUrlLengthWidth);
95 97
96 return id.str(); 98 return id.str();
97 } 99 }
98 100
99 // ID which identifies URL of this entry. 101 // ID which identifies URL of this entry.
100 std::string DeltaFileEntryWithData::Id() const { 102 std::string DeltaFileEntryWithData::Id() const {
101 return UrlToId(entry_.url()); 103 return UrlToId(entry_.url());
102 } 104 }
103 105
104 std::string DeltaFileEntryWithData::Url() const { 106 std::string DeltaFileEntryWithData::Url() const {
105 return entry_.url(); 107 return entry_.url();
106 } 108 }
107 109
108 base::string16 DeltaFileEntryWithData::Title() const { 110 base::string16 DeltaFileEntryWithData::Title() const {
109 if (!Valid()) return base::UTF8ToUTF16(""); 111 if (!Valid()) return base::UTF8ToUTF16("");
110 if (is_bookmark_ && !bookmark_title_.empty()) return bookmark_title_; 112 if (is_bookmark_ && !bookmark_title_.empty()) return bookmark_title_;
111 if (data_.title().empty()) return base::UTF8ToUTF16(data_.url().host()); 113 if (data_.title().empty()) return base::UTF8ToUTF16(data_.url().host());
112 return data_.title(); 114 return data_.title();
113 } 115 }
114 116
115 int32 DeltaFileEntryWithData::Score() const { 117 int32_t DeltaFileEntryWithData::Score() const {
116 if (!Valid()) return 0; 118 if (!Valid()) return 0;
117 int32 score = data_.visit_count() + data_.typed_count(); 119 int32_t score = data_.visit_count() + data_.typed_count();
118 if (is_bookmark_) score = (score + 1) * kBookmarkScoreBonusMultiplier; 120 if (is_bookmark_) score = (score + 1) * kBookmarkScoreBonusMultiplier;
119 return score; 121 return score;
120 } 122 }
121 123
122 std::string DeltaFileEntryWithData::IndexedUrl() const { 124 std::string DeltaFileEntryWithData::IndexedUrl() const {
123 if (!Valid()) return ""; 125 if (!Valid()) return "";
124 std::string indexed_url = data_.url().host(); 126 std::string indexed_url = data_.url().host();
125 StripTopLevelDomain(&indexed_url); 127 StripTopLevelDomain(&indexed_url);
126 StripCommonSubDomains(&indexed_url); 128 StripCommonSubDomains(&indexed_url);
127 return indexed_url; 129 return indexed_url;
(...skipping 14 matching lines...) Expand all
142 is_bookmark_ = true; 144 is_bookmark_ = true;
143 bookmark_title_ = bookmark.title; 145 bookmark_title_ = bookmark.title;
144 } 146 }
145 147
146 // static 148 // static
147 bool DeltaFileEntryWithData::IsValidId(const std::string& url) { 149 bool DeltaFileEntryWithData::IsValidId(const std::string& url) {
148 return url.size() <= kIdLengthLimit; 150 return url.size() <= kIdLengthLimit;
149 } 151 }
150 152
151 } // namespace history_report 153 } // namespace history_report
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698