| OLD | NEW |
| 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> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <iomanip> | 9 #include <iomanip> |
| 10 | 10 |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "crypto/sha2.h" | 13 #include "crypto/sha2.h" |
| 14 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 14 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 15 | 15 |
| 16 using bookmarks::BookmarkModel; | 16 using bookmarks::BookmarkModel; |
| 17 using net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES; | 17 using net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES; |
| 18 using net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES; | 18 using net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES; |
| 19 using net::registry_controlled_domains::GetRegistryLength; | 19 using net::registry_controlled_domains::GetCanonicalHostRegistryLength; |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 const int kBookmarkScoreBonusMultiplier = 3; | 23 const int kBookmarkScoreBonusMultiplier = 3; |
| 24 const size_t kIdLengthLimit = 256; | 24 const size_t kIdLengthLimit = 256; |
| 25 const int kSHA256ByteSize = 32; | 25 const int kSHA256ByteSize = 32; |
| 26 const size_t kUrlLengthLimit = 20 * 1024 * 1024; // 20M | 26 const size_t kUrlLengthLimit = 20 * 1024 * 1024; // 20M |
| 27 const size_t kUrlLengthWidth = 8; | 27 const size_t kUrlLengthWidth = 8; |
| 28 | 28 |
| 29 void StripTopLevelDomain(std::string* host) { | 29 void StripTopLevelDomain(std::string* canonical_host) { |
| 30 size_t registry_length = GetRegistryLength( | 30 size_t registry_length = GetCanonicalHostRegistryLength( |
| 31 *host, EXCLUDE_UNKNOWN_REGISTRIES, EXCLUDE_PRIVATE_REGISTRIES); | 31 *canonical_host, EXCLUDE_UNKNOWN_REGISTRIES, EXCLUDE_PRIVATE_REGISTRIES); |
| 32 if (registry_length != 0 && registry_length != std::string::npos) | 32 if (registry_length != 0 && registry_length != std::string::npos) |
| 33 host->erase(host->length() - (registry_length + 1)); | 33 canonical_host->erase(canonical_host->length() - (registry_length + 1)); |
| 34 } | 34 } |
| 35 | 35 |
| 36 void StripCommonSubDomains(std::string* host) { | 36 void StripCommonSubDomains(std::string* host) { |
| 37 std::string www_prefix("www."); | 37 std::string www_prefix("www."); |
| 38 std::string ww2_prefix("ww2."); | 38 std::string ww2_prefix("ww2."); |
| 39 if (host->compare(0, www_prefix.size(), www_prefix) == 0) { | 39 if (host->compare(0, www_prefix.size(), www_prefix) == 0) { |
| 40 host->erase(0, www_prefix.size()); | 40 host->erase(0, www_prefix.size()); |
| 41 } else if (host->compare(0, ww2_prefix.size(), ww2_prefix) == 0) { | 41 } else if (host->compare(0, ww2_prefix.size(), ww2_prefix) == 0) { |
| 42 host->erase(0, ww2_prefix.size()); | 42 host->erase(0, ww2_prefix.size()); |
| 43 } | 43 } |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 is_bookmark_ = true; | 147 is_bookmark_ = true; |
| 148 bookmark_title_ = bookmark.title; | 148 bookmark_title_ = bookmark.title; |
| 149 } | 149 } |
| 150 | 150 |
| 151 // static | 151 // static |
| 152 bool DeltaFileEntryWithData::IsValidId(const std::string& url) { | 152 bool DeltaFileEntryWithData::IsValidId(const std::string& url) { |
| 153 return url.size() <= kIdLengthLimit; | 153 return url.size() <= kIdLengthLimit; |
| 154 } | 154 } |
| 155 | 155 |
| 156 } // namespace history_report | 156 } // namespace history_report |
| OLD | NEW |