OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "components/history/core/browser/top_sites_database.h" | 5 #include "components/history/core/browser/top_sites_database.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/strings/string_piece.h" |
15 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
16 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
17 #include "components/history/core/browser/history_types.h" | 18 #include "components/history/core/browser/history_types.h" |
18 #include "components/history/core/browser/top_sites.h" | 19 #include "components/history/core/browser/top_sites.h" |
19 #include "components/history/core/common/thumbnail_score.h" | 20 #include "components/history/core/common/thumbnail_score.h" |
20 #include "sql/connection.h" | 21 #include "sql/connection.h" |
21 #include "sql/recovery.h" | 22 #include "sql/recovery.h" |
22 #include "sql/statement.h" | 23 #include "sql/statement.h" |
23 #include "sql/transaction.h" | 24 #include "sql/transaction.h" |
24 #include "third_party/sqlite/sqlite3.h" | 25 #include "third_party/sqlite/sqlite3.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 "good_clipping INTEGER DEFAULT 0," | 81 "good_clipping INTEGER DEFAULT 0," |
81 "at_top INTEGER DEFAULT 0," | 82 "at_top INTEGER DEFAULT 0," |
82 "last_updated INTEGER DEFAULT 0," | 83 "last_updated INTEGER DEFAULT 0," |
83 "load_completed INTEGER DEFAULT 0," | 84 "load_completed INTEGER DEFAULT 0," |
84 "last_forced INTEGER DEFAULT 0)"; | 85 "last_forced INTEGER DEFAULT 0)"; |
85 return db->Execute(kThumbnailsSql); | 86 return db->Execute(kThumbnailsSql); |
86 } | 87 } |
87 | 88 |
88 // Encodes redirects into a string. | 89 // Encodes redirects into a string. |
89 std::string GetRedirects(const MostVisitedURL& url) { | 90 std::string GetRedirects(const MostVisitedURL& url) { |
90 std::vector<std::string> redirects; | 91 std::vector<base::StringPiece> redirects; |
91 for (size_t i = 0; i < url.redirects.size(); i++) | 92 for (const auto& redirect : url.redirects) |
92 redirects.push_back(url.redirects[i].spec()); | 93 redirects.push_back(redirect.spec()); |
93 return base::JoinString(redirects, " "); | 94 return base::JoinString(redirects, " "); |
94 } | 95 } |
95 | 96 |
96 // Decodes redirects from a string and sets them for the url. | 97 // Decodes redirects from a string and sets them for the url. |
97 void SetRedirects(const std::string& redirects, MostVisitedURL* url) { | 98 void SetRedirects(const std::string& redirects, MostVisitedURL* url) { |
98 for (const std::string& redirect : base::SplitString( | 99 for (const std::string& redirect : base::SplitString( |
99 redirects, base::kWhitespaceASCII, | 100 redirects, base::kWhitespaceASCII, |
100 base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) { | 101 base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) { |
101 GURL redirect_url(redirect); | 102 GURL redirect_url(redirect); |
102 if (redirect_url.is_valid()) | 103 if (redirect_url.is_valid()) |
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 db->set_error_callback(base::Bind(&DatabaseErrorCallback, db.get(), db_name)); | 728 db->set_error_callback(base::Bind(&DatabaseErrorCallback, db.get(), db_name)); |
728 db->set_page_size(4096); | 729 db->set_page_size(4096); |
729 db->set_cache_size(32); | 730 db->set_cache_size(32); |
730 | 731 |
731 if (!db->Open(db_name)) | 732 if (!db->Open(db_name)) |
732 return NULL; | 733 return NULL; |
733 return db.release(); | 734 return db.release(); |
734 } | 735 } |
735 | 736 |
736 } // namespace history | 737 } // namespace history |
OLD | NEW |