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

Side by Side Diff: chrome/browser/history/top_sites_database.cc

Issue 2499003: Write thumbnail to the database on SetPageThumbnail.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/history/top_sites.cc ('k') | chrome/browser/history/top_sites_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "app/sql/transaction.h" 5 #include "app/sql/transaction.h"
6 #include "base/string_util.h" 6 #include "base/string_util.h"
7 #include "chrome/browser/diagnostics/sqlite_diagnostics.h" 7 #include "chrome/browser/diagnostics/sqlite_diagnostics.h"
8 #include "chrome/browser/history/top_sites.h" 8 #include "chrome/browser/history/top_sites.h"
9 #include "chrome/browser/history/top_sites_database.h" 9 #include "chrome/browser/history/top_sites_database.h"
10 10
(...skipping 16 matching lines...) Expand all
27 return InitThumbnailTable(); 27 return InitThumbnailTable();
28 } 28 }
29 29
30 bool TopSitesDatabaseImpl::InitThumbnailTable() { 30 bool TopSitesDatabaseImpl::InitThumbnailTable() {
31 if (!db_.DoesTableExist("thumbnails")) { 31 if (!db_.DoesTableExist("thumbnails")) {
32 if (!db_.Execute("CREATE TABLE thumbnails (" 32 if (!db_.Execute("CREATE TABLE thumbnails ("
33 "url LONGVARCHAR PRIMARY KEY," 33 "url LONGVARCHAR PRIMARY KEY,"
34 "url_rank INTEGER ," 34 "url_rank INTEGER ,"
35 "title LONGVARCHAR," 35 "title LONGVARCHAR,"
36 "thumbnail BLOB," 36 "thumbnail BLOB,"
37 "redirects LONGVARCHAR)")) { 37 "redirects LONGVARCHAR,"
38 "boring_score DOUBLE DEFAULT 1.0, "
39 "good_clipping INTEGER DEFAULT 0, "
40 "at_top INTEGER DEFAULT 0, "
41 "last_updated INTEGER DEFAULT 0) ")) {
38 LOG(WARNING) << db_.GetErrorMessage(); 42 LOG(WARNING) << db_.GetErrorMessage();
39 return false; 43 return false;
40 } 44 }
41 } 45 }
42 return true; 46 return true;
43 } 47 }
44 48
45 MostVisitedURLList TopSitesDatabaseImpl::GetTopURLs() { 49 MostVisitedURLList TopSitesDatabaseImpl::GetTopURLs() {
46 MostVisitedURLList result; 50 MostVisitedURLList result;
47 sql::Statement select_statement(db_.GetCachedStatement( 51 sql::Statement select_statement(db_.GetCachedStatement(
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 int new_rank, 98 int new_rank,
95 const TopSites::Images& thumbnail) { 99 const TopSites::Images& thumbnail) {
96 sql::Transaction transaction(&db_); 100 sql::Transaction transaction(&db_);
97 transaction.Begin(); 101 transaction.Begin();
98 102
99 int prev_rank = GetURLRank(url); 103 int prev_rank = GetURLRank(url);
100 104
101 sql::Statement statement(db_.GetCachedStatement( 105 sql::Statement statement(db_.GetCachedStatement(
102 SQL_FROM_HERE, 106 SQL_FROM_HERE,
103 "INSERT OR REPLACE INTO thumbnails " 107 "INSERT OR REPLACE INTO thumbnails "
104 "(url, url_rank, title, thumbnail, redirects) " 108 "(url, url_rank, title, thumbnail, redirects, "
105 "VALUES (?, ?, ?, ?, ?)")); // TODO(Nik): add the rest of the schema. 109 "boring_score, good_clipping, at_top, last_updated) "
110 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"));
106 if (!statement) 111 if (!statement)
107 return; 112 return;
108 113
109 statement.BindString(0, url.url.spec()); 114 statement.BindString(0, url.url.spec());
110 statement.BindInt(1, -1); // Temporary value 115 statement.BindInt(1, -1); // Temporary value
111 statement.BindString16(2, url.title); 116 statement.BindString16(2, url.title);
112 if (thumbnail.thumbnail.get()) { 117 if (thumbnail.thumbnail.get()) {
113 statement.BindBlob(3, &thumbnail.thumbnail->data.front(), 118 statement.BindBlob(3, &thumbnail.thumbnail->data.front(),
114 static_cast<int>(thumbnail.thumbnail->data.size())); 119 static_cast<int>(thumbnail.thumbnail->data.size()));
115 } 120 }
116 statement.BindString(4, GetRedirects(url)); 121 statement.BindString(4, GetRedirects(url));
122 const ThumbnailScore& score = thumbnail.thumbnail_score;
123 statement.BindDouble(5, score.boring_score);
124 statement.BindBool(6, score.good_clipping);
125 statement.BindBool(7, score.at_top);
126 statement.BindInt64(8, score.time_at_snapshot.ToInternalValue());
117 127
118 if (!statement.Run()) 128 if (!statement.Run())
119 NOTREACHED() << db_.GetErrorMessage(); 129 NOTREACHED() << db_.GetErrorMessage();
120 130
121 // Shift the ranks. 131 // Shift the ranks.
122 if (prev_rank == -1) { 132 if (prev_rank == -1) {
123 // Shift up 133 // Shift up
124 sql::Statement shift_statement(db_.GetCachedStatement( 134 sql::Statement shift_statement(db_.GetCachedStatement(
125 SQL_FROM_HERE, 135 SQL_FROM_HERE,
126 "UPDATE thumbnails " 136 "UPDATE thumbnails "
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 "SET url_rank = ? " 169 "SET url_rank = ? "
160 "WHERE url_rank == -1")); 170 "WHERE url_rank == -1"));
161 set_statement.BindInt(0, new_rank); 171 set_statement.BindInt(0, new_rank);
162 if (set_statement) 172 if (set_statement)
163 set_statement.Run(); 173 set_statement.Run();
164 transaction.Commit(); 174 transaction.Commit();
165 } 175 }
166 176
167 bool TopSitesDatabaseImpl::GetPageThumbnail(const MostVisitedURL& url, 177 bool TopSitesDatabaseImpl::GetPageThumbnail(const MostVisitedURL& url,
168 TopSites::Images* thumbnail) { 178 TopSites::Images* thumbnail) {
169 sql::Statement select_statement(db_.GetCachedStatement( 179 sql::Statement statement(db_.GetCachedStatement(
170 SQL_FROM_HERE, 180 SQL_FROM_HERE,
171 "SELECT thumbnail " 181 "SELECT thumbnail, boring_score, good_clipping, at_top, last_updated "
172 "FROM thumbnails WHERE url=?")); 182 "FROM thumbnails WHERE url=?"));
173 183
174 if (!select_statement) { 184 if (!statement) {
175 LOG(WARNING) << db_.GetErrorMessage(); 185 LOG(WARNING) << db_.GetErrorMessage();
176 return false; 186 return false;
177 } 187 }
178 188
179 select_statement.BindString(0, url.url.spec()); 189 statement.BindString(0, url.url.spec());
180 if (!select_statement.Step()) 190 if (!statement.Step())
181 return false; 191 return false;
182 192
183 std::vector<unsigned char> data; 193 std::vector<unsigned char> data;
184 select_statement.ColumnBlobAsVector(0, &data); 194 statement.ColumnBlobAsVector(0, &data);
185 thumbnail->thumbnail = RefCountedBytes::TakeVector(&data); 195 thumbnail->thumbnail = RefCountedBytes::TakeVector(&data);
196 thumbnail->thumbnail_score.boring_score = statement.ColumnDouble(1);
197 thumbnail->thumbnail_score.good_clipping = statement.ColumnBool(2);
198 thumbnail->thumbnail_score.at_top = statement.ColumnBool(3);
199 thumbnail->thumbnail_score.time_at_snapshot =
200 base::Time::FromInternalValue(statement.ColumnInt64(4));
186 return true; 201 return true;
187 } 202 }
188 203
189 int TopSitesDatabaseImpl::GetURLRank(const MostVisitedURL& url) { 204 int TopSitesDatabaseImpl::GetURLRank(const MostVisitedURL& url) {
190 int result = -1; 205 int result = -1;
191 sql::Statement select_statement(db_.GetCachedStatement( 206 sql::Statement select_statement(db_.GetCachedStatement(
192 SQL_FROM_HERE, 207 SQL_FROM_HERE,
193 "SELECT url_rank " 208 "SELECT url_rank "
194 "FROM thumbnails WHERE url=?")); 209 "FROM thumbnails WHERE url=?"));
195 if (!select_statement) { 210 if (!select_statement) {
(...skipping 29 matching lines...) Expand all
225 "DELETE FROM thumbnails WHERE url = ?")); 240 "DELETE FROM thumbnails WHERE url = ?"));
226 if (!delete_statement) 241 if (!delete_statement)
227 return false; 242 return false;
228 delete_statement.BindString(0, url.url.spec()); 243 delete_statement.BindString(0, url.url.spec());
229 delete_statement.Run(); 244 delete_statement.Run();
230 245
231 return transaction.Commit(); 246 return transaction.Commit();
232 } 247 }
233 248
234 } // namespace history 249 } // namespace history
235
OLDNEW
« no previous file with comments | « chrome/browser/history/top_sites.cc ('k') | chrome/browser/history/top_sites_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698