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 #ifndef CHROME_BROWSER_HISTORY_TOP_SITES_DATABASE_H_ | 5 #ifndef CHROME_BROWSER_HISTORY_TOP_SITES_DATABASE_H_ |
6 #define CHROME_BROWSER_HISTORY_TOP_SITES_DATABASE_H_ | 6 #define CHROME_BROWSER_HISTORY_TOP_SITES_DATABASE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | |
10 | 11 |
11 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
12 #include "chrome/browser/history/history_types.h" | 13 #include "chrome/browser/history/history_types.h" |
13 #include "sql/meta_table.h" | 14 #include "sql/meta_table.h" |
14 | 15 |
15 namespace base { | 16 namespace base { |
16 class FilePath; | 17 class FilePath; |
17 } | 18 } |
18 | 19 |
19 namespace sql { | 20 namespace sql { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 bool RemoveURL(const MostVisitedURL& url); | 58 bool RemoveURL(const MostVisitedURL& url); |
58 | 59 |
59 private: | 60 private: |
60 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, Version1); | 61 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, Version1); |
61 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, Version2); | 62 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, Version2); |
62 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, Version3); | 63 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, Version3); |
63 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, Recovery1); | 64 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, Recovery1); |
64 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, Recovery2); | 65 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, Recovery2); |
65 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, Recovery3); | 66 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, Recovery3); |
66 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, AddRemoveEditThumbnails); | 67 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, AddRemoveEditThumbnails); |
68 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, EncodeCSVString); | |
69 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, DecodeCSVStringSucceed); | |
70 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, DecodeCSVStringFail); | |
71 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, EncodeRedirects); | |
72 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, DecodeRedirects); | |
73 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, DecodeRedirectsFallback); | |
67 | 74 |
68 // Rank of all URLs that are forced and therefore cannot be automatically | 75 // Rank of all URLs that are forced and therefore cannot be automatically |
69 // evicted. | 76 // evicted. |
70 static const int kRankOfForcedURL; | 77 static const int kRankOfForcedURL; |
71 | 78 |
72 // Rank used to indicate that a URL is not stored in the database. | 79 // Rank used to indicate that a URL is not stored in the database. |
73 static const int kRankOfNonExistingURL; | 80 static const int kRankOfNonExistingURL; |
74 | 81 |
75 // Upgrades the thumbnail table to version 3, returning true if the | 82 // Upgrades the thumbnail table to version 3, returning true if the |
76 // upgrade was successful. | 83 // upgrade was successful. |
77 bool UpgradeToVersion3(); | 84 bool UpgradeToVersion3(); |
78 | 85 |
79 // Adds a new URL to the database. | 86 // Adds a new URL to the database. |
80 void AddPageThumbnail(const MostVisitedURL& url, | 87 void AddPageThumbnail(const MostVisitedURL& url, |
81 int new_rank, | 88 int new_rank, |
82 const Images& thumbnail); | 89 const Images& thumbnail); |
83 | 90 |
91 // Encodes a vector of strings as a single string, as a comma separated list | |
beaudoin
2014/09/09 21:32:27
as a single string --> inside a single string
huangs
2014/09/11 01:58:13
Done.
| |
92 // of quoted strings. Existing quotation marks are escaped as "\"\"". | |
beaudoin
2014/09/09 21:32:27
You mean existing quotation marks are escaped by p
huangs
2014/09/11 01:58:13
Backslash is not involved; we substituted '"' to '
| |
93 static std::string EncodeCSVString(const std::vector<std::string> str_list); | |
94 | |
95 // Decodes a string encoded by EncodeCSVString() as a vector of strings, | |
96 // On success returns true, otherwise returns false and ignores |str_list|. | |
97 static bool DecodeCSVString(const std::string csv, | |
98 std::vector<std::string>* str_list); | |
99 | |
100 // Encodes redirects in |url| as string. | |
beaudoin
2014/09/09 21:32:27
|url|?
huangs
2014/09/11 01:58:14
Done.
| |
101 static std::string EncodeRedirects(const RedirectList& redirects); | |
102 | |
103 // Decodes a redirects string, appends the result ot |redirects|. | |
beaudoin
2014/09/09 21:32:27
ot -> to
huangs
2014/09/11 01:58:14
Done.
| |
104 static void DecodeRedirects(const std::string& encoded_redirects, | |
105 RedirectList* redirects); | |
106 | |
84 // Sets the page rank. Should be called within an open transaction. | 107 // Sets the page rank. Should be called within an open transaction. |
85 void UpdatePageRankNoTransaction(const MostVisitedURL& url, int new_rank); | 108 void UpdatePageRankNoTransaction(const MostVisitedURL& url, int new_rank); |
86 | 109 |
87 // Updates thumbnail of a URL that's already in the database. | 110 // Updates thumbnail of a URL that's already in the database. |
88 // Returns true if the database query succeeds. | 111 // Returns true if the database query succeeds. |
89 bool UpdatePageThumbnail(const MostVisitedURL& url, | 112 bool UpdatePageThumbnail(const MostVisitedURL& url, |
90 const Images& thumbnail); | 113 const Images& thumbnail); |
91 | 114 |
92 // Returns |url|'s current rank or kRankOfNonExistingURL if not present. | 115 // Returns |url|'s current rank or kRankOfNonExistingURL if not present. |
93 int GetURLRank(const MostVisitedURL& url); | 116 int GetURLRank(const MostVisitedURL& url); |
94 | 117 |
95 // Helper function to implement internals of Init(). This allows | 118 // Helper function to implement internals of Init(). This allows |
96 // Init() to retry in case of failure, since some failures will | 119 // Init() to retry in case of failure, since some failures will |
97 // invoke recovery code. | 120 // invoke recovery code. |
98 bool InitImpl(const base::FilePath& db_name); | 121 bool InitImpl(const base::FilePath& db_name); |
99 | 122 |
100 sql::Connection* CreateDB(const base::FilePath& db_name); | 123 sql::Connection* CreateDB(const base::FilePath& db_name); |
101 | 124 |
102 scoped_ptr<sql::Connection> db_; | 125 scoped_ptr<sql::Connection> db_; |
103 sql::MetaTable meta_table_; | 126 sql::MetaTable meta_table_; |
104 | 127 |
105 DISALLOW_COPY_AND_ASSIGN(TopSitesDatabase); | 128 DISALLOW_COPY_AND_ASSIGN(TopSitesDatabase); |
106 }; | 129 }; |
107 | 130 |
108 } // namespace history | 131 } // namespace history |
109 | 132 |
110 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_DATABASE_H_ | 133 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_DATABASE_H_ |
OLD | NEW |