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

Side by Side Diff: chrome/browser/webdata/web_database.cc

Issue 243076: Move the JPEG and PNG codecs from base/gfx to app/gfx/codec. Move the classes... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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
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 "chrome/browser/webdata/web_database.h" 5 #include "chrome/browser/webdata/web_database.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <vector> 9 #include <vector>
10 10
11 #include "app/gfx/codec/png_codec.h"
11 #include "app/l10n_util.h" 12 #include "app/l10n_util.h"
12 #include "app/sql/statement.h" 13 #include "app/sql/statement.h"
13 #include "app/sql/transaction.h" 14 #include "app/sql/transaction.h"
14 #include "base/gfx/png_decoder.h"
15 #include "base/gfx/png_encoder.h"
16 #include "base/string_util.h" 15 #include "base/string_util.h"
17 #include "base/time.h" 16 #include "base/time.h"
18 #include "chrome/browser/history/history_database.h" 17 #include "chrome/browser/history/history_database.h"
19 #include "chrome/browser/search_engines/template_url.h" 18 #include "chrome/browser/search_engines/template_url.h"
20 #include "webkit/glue/password_form.h" 19 #include "webkit/glue/password_form.h"
21 20
22 // Encryptor is the *wrong* way of doing things; we need to turn it into a 21 // Encryptor is the *wrong* way of doing things; we need to turn it into a
23 // bottleneck to use the platform methods (e.g. Keychain on the Mac, Gnome 22 // bottleneck to use the platform methods (e.g. Keychain on the Mac, Gnome
24 // Keyring / KWallet on Linux). That's going to take a massive change in its 23 // Keyring / KWallet on Linux). That's going to take a massive change in its
25 // API... see: 24 // API... see:
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 bool WebDatabase::SetWebAppImage(const GURL& url, const SkBitmap& image) { 179 bool WebDatabase::SetWebAppImage(const GURL& url, const SkBitmap& image) {
181 // Don't bother with a cached statement since this will be a relatively 180 // Don't bother with a cached statement since this will be a relatively
182 // infrequent operation. 181 // infrequent operation.
183 sql::Statement s(db_.GetUniqueStatement( 182 sql::Statement s(db_.GetUniqueStatement(
184 "INSERT OR REPLACE INTO web_app_icons " 183 "INSERT OR REPLACE INTO web_app_icons "
185 "(url, width, height, image) VALUES (?, ?, ?, ?)")); 184 "(url, width, height, image) VALUES (?, ?, ?, ?)"));
186 if (!s) 185 if (!s)
187 return false; 186 return false;
188 187
189 std::vector<unsigned char> image_data; 188 std::vector<unsigned char> image_data;
190 PNGEncoder::EncodeBGRASkBitmap(image, false, &image_data); 189 gfx::PNGCodec::EncodeBGRASkBitmap(image, false, &image_data);
191 190
192 s.BindString(0, history::HistoryDatabase::GURLToDatabaseURL(url)); 191 s.BindString(0, history::HistoryDatabase::GURLToDatabaseURL(url));
193 s.BindInt(1, image.width()); 192 s.BindInt(1, image.width());
194 s.BindInt(2, image.height()); 193 s.BindInt(2, image.height());
195 s.BindBlob(3, &image_data.front(), static_cast<int>(image_data.size())); 194 s.BindBlob(3, &image_data.front(), static_cast<int>(image_data.size()));
196 return s.Run(); 195 return s.Run();
197 } 196 }
198 197
199 bool WebDatabase::GetWebAppImages(const GURL& url, 198 bool WebDatabase::GetWebAppImages(const GURL& url,
200 std::vector<SkBitmap>* images) { 199 std::vector<SkBitmap>* images) {
201 sql::Statement s(db_.GetUniqueStatement( 200 sql::Statement s(db_.GetUniqueStatement(
202 "SELECT image FROM web_app_icons WHERE url=?")); 201 "SELECT image FROM web_app_icons WHERE url=?"));
203 if (!s) { 202 if (!s) {
204 NOTREACHED() << "Statement prepare failed"; 203 NOTREACHED() << "Statement prepare failed";
205 return false; 204 return false;
206 } 205 }
207 s.BindString(0, history::HistoryDatabase::GURLToDatabaseURL(url)); 206 s.BindString(0, history::HistoryDatabase::GURLToDatabaseURL(url));
208 while (s.Step()) { 207 while (s.Step()) {
209 SkBitmap image; 208 SkBitmap image;
210 std::vector<unsigned char> image_data; 209 std::vector<unsigned char> image_data;
211 int col_bytes = s.ColumnByteLength(0); 210 int col_bytes = s.ColumnByteLength(0);
212 if (col_bytes > 0) { 211 if (col_bytes > 0) {
213 image_data.resize(col_bytes); 212 image_data.resize(col_bytes);
214 memcpy(&image_data[0], s.ColumnBlob(0), col_bytes); 213 memcpy(&image_data[0], s.ColumnBlob(0), col_bytes);
215 if (PNGDecoder::Decode(&image_data, &image)) { 214 if (gfx::PNGCodec::Decode(&image_data, &image)) {
216 images->push_back(image); 215 images->push_back(image);
217 } else { 216 } else {
218 // Should only have valid image data in the db. 217 // Should only have valid image data in the db.
219 NOTREACHED(); 218 NOTREACHED();
220 } 219 }
221 } 220 }
222 } 221 }
223 return true; 222 return true;
224 } 223 }
225 224
(...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 1149
1151 // Add successive versions here. Each should set the version number and 1150 // Add successive versions here. Each should set the version number and
1152 // compatible version number as appropriate, then fall through to the next 1151 // compatible version number as appropriate, then fall through to the next
1153 // case. 1152 // case.
1154 1153
1155 case kCurrentVersionNumber: 1154 case kCurrentVersionNumber:
1156 // No migration needed. 1155 // No migration needed.
1157 return; 1156 return;
1158 } 1157 }
1159 } 1158 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698