Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_apps_table.h" | 5 #include "chrome/browser/webdata/web_apps_table.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/history/history_database.h" | 8 #include "chrome/browser/history/history_database.h" |
| 9 #include "googleurl/src/gurl.h" | 9 #include "googleurl/src/gurl.h" |
| 10 #include "sql/statement.h" | 10 #include "sql/statement.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 } | 48 } |
| 49 return true; | 49 return true; |
| 50 } | 50 } |
| 51 | 51 |
| 52 bool WebAppsTable::SetWebAppImage(const GURL& url, const SkBitmap& image) { | 52 bool WebAppsTable::SetWebAppImage(const GURL& url, const SkBitmap& image) { |
| 53 // Don't bother with a cached statement since this will be a relatively | 53 // Don't bother with a cached statement since this will be a relatively |
| 54 // infrequent operation. | 54 // infrequent operation. |
| 55 sql::Statement s(db_->GetUniqueStatement( | 55 sql::Statement s(db_->GetUniqueStatement( |
| 56 "INSERT OR REPLACE INTO web_app_icons " | 56 "INSERT OR REPLACE INTO web_app_icons " |
| 57 "(url, width, height, image) VALUES (?, ?, ?, ?)")); | 57 "(url, width, height, image) VALUES (?, ?, ?, ?)")); |
| 58 if (!s) | |
| 59 return false; | |
| 60 | |
| 61 std::vector<unsigned char> image_data; | 58 std::vector<unsigned char> image_data; |
| 62 gfx::PNGCodec::EncodeBGRASkBitmap(image, false, &image_data); | 59 gfx::PNGCodec::EncodeBGRASkBitmap(image, false, &image_data); |
| 63 | |
| 64 s.BindString(0, history::HistoryDatabase::GURLToDatabaseURL(url)); | 60 s.BindString(0, history::HistoryDatabase::GURLToDatabaseURL(url)); |
| 65 s.BindInt(1, image.width()); | 61 s.BindInt(1, image.width()); |
| 66 s.BindInt(2, image.height()); | 62 s.BindInt(2, image.height()); |
| 67 s.BindBlob(3, &image_data.front(), static_cast<int>(image_data.size())); | 63 s.BindBlob(3, &image_data.front(), static_cast<int>(image_data.size())); |
| 64 | |
| 68 return s.Run(); | 65 return s.Run(); |
| 69 } | 66 } |
| 70 | 67 |
| 71 bool WebAppsTable::GetWebAppImages(const GURL& url, | 68 bool WebAppsTable::GetWebAppImages(const GURL& url, |
| 72 std::vector<SkBitmap>* images) { | 69 std::vector<SkBitmap>* images) { |
| 73 sql::Statement s(db_->GetUniqueStatement( | 70 sql::Statement s(db_->GetUniqueStatement( |
| 74 "SELECT image FROM web_app_icons WHERE url=?")); | 71 "SELECT image FROM web_app_icons WHERE url=?")); |
| 75 if (!s) { | |
| 76 NOTREACHED() << "Statement prepare failed"; | |
| 77 return false; | |
| 78 } | |
| 79 s.BindString(0, history::HistoryDatabase::GURLToDatabaseURL(url)); | 72 s.BindString(0, history::HistoryDatabase::GURLToDatabaseURL(url)); |
| 73 | |
| 80 while (s.Step()) { | 74 while (s.Step()) { |
| 81 SkBitmap image; | 75 SkBitmap image; |
| 82 int col_bytes = s.ColumnByteLength(0); | 76 int col_bytes = s.ColumnByteLength(0); |
| 83 if (col_bytes > 0) { | 77 if (col_bytes > 0) { |
| 84 if (gfx::PNGCodec::Decode( | 78 if (gfx::PNGCodec::Decode( |
| 85 reinterpret_cast<const unsigned char*>(s.ColumnBlob(0)), | 79 reinterpret_cast<const unsigned char*>(s.ColumnBlob(0)), |
| 86 col_bytes, &image)) { | 80 col_bytes, &image)) { |
| 87 images->push_back(image); | 81 images->push_back(image); |
| 88 } else { | 82 } else { |
| 89 // Should only have valid image data in the db. | 83 // Should only have valid image data in the db. |
| 90 NOTREACHED(); | 84 NOTREACHED(); |
| 91 } | 85 } |
| 92 } | 86 } |
| 93 } | 87 } |
| 94 return true; | 88 return s.Succeeded(); |
|
Scott Hess - ex-Googler
2011/12/16 22:37:09
I think this is right, even though there could be
Greg Billock
2011/12/21 21:43:03
I think in this particular case partially filling
| |
| 95 } | 89 } |
| 96 | 90 |
| 97 bool WebAppsTable::SetWebAppHasAllImages(const GURL& url, | 91 bool WebAppsTable::SetWebAppHasAllImages(const GURL& url, |
| 98 bool has_all_images) { | 92 bool has_all_images) { |
| 99 sql::Statement s(db_->GetUniqueStatement( | 93 sql::Statement s(db_->GetUniqueStatement( |
| 100 "INSERT OR REPLACE INTO web_apps (url, has_all_images) VALUES (?, ?)")); | 94 "INSERT OR REPLACE INTO web_apps (url, has_all_images) VALUES (?, ?)")); |
| 101 if (!s) { | |
| 102 NOTREACHED() << "Statement prepare failed"; | |
| 103 return false; | |
| 104 } | |
| 105 s.BindString(0, history::HistoryDatabase::GURLToDatabaseURL(url)); | 95 s.BindString(0, history::HistoryDatabase::GURLToDatabaseURL(url)); |
| 106 s.BindInt(1, has_all_images ? 1 : 0); | 96 s.BindInt(1, has_all_images ? 1 : 0); |
| 97 | |
| 107 return s.Run(); | 98 return s.Run(); |
| 108 } | 99 } |
| 109 | 100 |
| 110 bool WebAppsTable::GetWebAppHasAllImages(const GURL& url) { | 101 bool WebAppsTable::GetWebAppHasAllImages(const GURL& url) { |
| 111 sql::Statement s(db_->GetUniqueStatement( | 102 sql::Statement s(db_->GetUniqueStatement( |
| 112 "SELECT has_all_images FROM web_apps WHERE url=?")); | 103 "SELECT has_all_images FROM web_apps WHERE url=?")); |
| 113 if (!s) { | |
| 114 NOTREACHED() << "Statement prepare failed"; | |
| 115 return false; | |
| 116 } | |
| 117 s.BindString(0, history::HistoryDatabase::GURLToDatabaseURL(url)); | 104 s.BindString(0, history::HistoryDatabase::GURLToDatabaseURL(url)); |
| 105 | |
| 118 return (s.Step() && s.ColumnInt(0) == 1); | 106 return (s.Step() && s.ColumnInt(0) == 1); |
| 119 } | 107 } |
| 120 | 108 |
| 121 bool WebAppsTable::RemoveWebApp(const GURL& url) { | 109 bool WebAppsTable::RemoveWebApp(const GURL& url) { |
| 122 sql::Statement delete_s(db_->GetUniqueStatement( | 110 sql::Statement delete_s(db_->GetUniqueStatement( |
| 123 "DELETE FROM web_app_icons WHERE url = ?")); | 111 "DELETE FROM web_app_icons WHERE url = ?")); |
| 124 if (!delete_s) { | |
| 125 NOTREACHED() << "Statement prepare failed"; | |
| 126 return false; | |
| 127 } | |
| 128 delete_s.BindString(0, history::HistoryDatabase::GURLToDatabaseURL(url)); | 112 delete_s.BindString(0, history::HistoryDatabase::GURLToDatabaseURL(url)); |
| 113 | |
| 129 if (!delete_s.Run()) | 114 if (!delete_s.Run()) |
| 130 return false; | 115 return false; |
| 131 | 116 |
| 132 sql::Statement delete_s2(db_->GetUniqueStatement( | 117 sql::Statement delete_s2(db_->GetUniqueStatement( |
| 133 "DELETE FROM web_apps WHERE url = ?")); | 118 "DELETE FROM web_apps WHERE url = ?")); |
| 134 if (!delete_s2) { | |
| 135 NOTREACHED() << "Statement prepare failed"; | |
| 136 return false; | |
| 137 } | |
| 138 delete_s2.BindString(0, history::HistoryDatabase::GURLToDatabaseURL(url)); | 119 delete_s2.BindString(0, history::HistoryDatabase::GURLToDatabaseURL(url)); |
| 120 | |
| 139 return delete_s2.Run(); | 121 return delete_s2.Run(); |
| 140 } | 122 } |
| 141 | |
| OLD | NEW |