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 30 matching lines...) Expand all Loading... |
50 // Use SetPageThumbnail if it's not. | 51 // Use SetPageThumbnail if it's not. |
51 void UpdatePageRank(const MostVisitedURL& url, int new_rank); | 52 void UpdatePageRank(const MostVisitedURL& url, int new_rank); |
52 | 53 |
53 // Get a thumbnail for a given page. Returns true iff we have the thumbnail. | 54 // Get a thumbnail for a given page. Returns true iff we have the thumbnail. |
54 bool GetPageThumbnail(const GURL& url, Images* thumbnail); | 55 bool GetPageThumbnail(const GURL& url, Images* thumbnail); |
55 | 56 |
56 // Remove the record for this URL. Returns true iff removed successfully. | 57 // Remove the record for this URL. Returns true iff removed successfully. |
57 bool RemoveURL(const MostVisitedURL& url); | 58 bool RemoveURL(const MostVisitedURL& url); |
58 | 59 |
59 private: | 60 private: |
| 61 friend class TopSitesDatabaseTest; |
60 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, Version1); | 62 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, Version1); |
61 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, Version2); | 63 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, Version2); |
62 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, Version3); | 64 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, Version3); |
| 65 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, Version4); |
63 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, Recovery1); | 66 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, Recovery1); |
64 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, Recovery2); | 67 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, Recovery2); |
65 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, Recovery3); | 68 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, Recovery3); |
| 69 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, Recovery4); |
66 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, AddRemoveEditThumbnails); | 70 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, AddRemoveEditThumbnails); |
| 71 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, EncodeCSVString); |
| 72 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, DecodeCSVStringSucceed); |
| 73 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, DecodeCSVStringFail); |
| 74 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, EncodeRedirects); |
| 75 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, DecodeRedirects); |
| 76 FRIEND_TEST_ALL_PREFIXES(TopSitesDatabaseTest, DecodeRedirectsFallback); |
67 | 77 |
68 // Rank of all URLs that are forced and therefore cannot be automatically | 78 // Rank of all URLs that are forced and therefore cannot be automatically |
69 // evicted. | 79 // evicted. |
70 static const int kRankOfForcedURL; | 80 static const int kRankOfForcedURL; |
71 | 81 |
72 // Rank used to indicate that a URL is not stored in the database. | 82 // Rank used to indicate that a URL is not stored in the database. |
73 static const int kRankOfNonExistingURL; | 83 static const int kRankOfNonExistingURL; |
74 | 84 |
75 // Upgrades the thumbnail table to version 3, returning true if the | 85 // Upgrades the thumbnail table to version 3, returning true if successful. |
76 // upgrade was successful. | |
77 bool UpgradeToVersion3(); | 86 bool UpgradeToVersion3(); |
78 | 87 |
| 88 // Upgrades the thumbnail table to version 4, returning true if successful. |
| 89 bool UpgradeToVersion4(); |
| 90 |
79 // Adds a new URL to the database. | 91 // Adds a new URL to the database. |
80 void AddPageThumbnail(const MostVisitedURL& url, | 92 void AddPageThumbnail(const MostVisitedURL& url, |
81 int new_rank, | 93 int new_rank, |
82 const Images& thumbnail); | 94 const Images& thumbnail); |
83 | 95 |
| 96 // Encodes a vector of strings inside a single string, as a comma-separated |
| 97 // list of quoted strings. Quotes are escaped into two quotes. |
| 98 static std::string EncodeCSVString(const std::vector<std::string> str_list); |
| 99 |
| 100 // Decodes a string encoded by EncodeCSVString() as a vector of strings, |
| 101 // On success returns true, otherwise returns false and ignores |str_list|. |
| 102 static bool DecodeCSVString(const std::string csv, |
| 103 std::vector<std::string>* str_list); |
| 104 |
| 105 // Encodes |redirects| as string. |
| 106 static std::string EncodeRedirects(const RedirectList& redirects); |
| 107 |
| 108 // Decodes a redirects string, appends the result to |redirects|. |
| 109 static void DecodeRedirects(const std::string& encoded_redirects, |
| 110 RedirectList* redirects); |
| 111 |
84 // Sets the page rank. Should be called within an open transaction. | 112 // Sets the page rank. Should be called within an open transaction. |
85 void UpdatePageRankNoTransaction(const MostVisitedURL& url, int new_rank); | 113 void UpdatePageRankNoTransaction(const MostVisitedURL& url, int new_rank); |
86 | 114 |
87 // Updates thumbnail of a URL that's already in the database. | 115 // Updates thumbnail of a URL that's already in the database. |
88 // Returns true if the database query succeeds. | 116 // Returns true if the database query succeeds. |
89 bool UpdatePageThumbnail(const MostVisitedURL& url, | 117 bool UpdatePageThumbnail(const MostVisitedURL& url, |
90 const Images& thumbnail); | 118 const Images& thumbnail); |
91 | 119 |
92 // Returns |url|'s current rank or kRankOfNonExistingURL if not present. | 120 // Returns |url|'s current rank or kRankOfNonExistingURL if not present. |
93 int GetURLRank(const MostVisitedURL& url); | 121 int GetURLRank(const MostVisitedURL& url); |
94 | 122 |
95 // Helper function to implement internals of Init(). This allows | 123 // Helper function to implement internals of Init(). This allows |
96 // Init() to retry in case of failure, since some failures will | 124 // Init() to retry in case of failure, since some failures will |
97 // invoke recovery code. | 125 // invoke recovery code. |
98 bool InitImpl(const base::FilePath& db_name); | 126 bool InitImpl(const base::FilePath& db_name); |
99 | 127 |
100 sql::Connection* CreateDB(const base::FilePath& db_name); | 128 sql::Connection* CreateDB(const base::FilePath& db_name); |
101 | 129 |
102 scoped_ptr<sql::Connection> db_; | 130 scoped_ptr<sql::Connection> db_; |
103 sql::MetaTable meta_table_; | 131 sql::MetaTable meta_table_; |
104 | 132 |
105 DISALLOW_COPY_AND_ASSIGN(TopSitesDatabase); | 133 DISALLOW_COPY_AND_ASSIGN(TopSitesDatabase); |
106 }; | 134 }; |
107 | 135 |
108 } // namespace history | 136 } // namespace history |
109 | 137 |
110 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_DATABASE_H_ | 138 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_DATABASE_H_ |
OLD | NEW |