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

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

Issue 8966003: Update webdata files to take advantage of DLOG(FATAL) in (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years 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) 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
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) { 72 s.BindString(0, history::HistoryDatabase::GURLToDatabaseURL(url));
76 NOTREACHED() << "Statement prepare failed"; 73
74 if (!s.is_valid()) {
77 return false; 75 return false;
78 } 76 }
79 s.BindString(0, history::HistoryDatabase::GURLToDatabaseURL(url)); 77
80 while (s.Step()) { 78 while (s.Step()) {
81 SkBitmap image; 79 SkBitmap image;
82 int col_bytes = s.ColumnByteLength(0); 80 int col_bytes = s.ColumnByteLength(0);
83 if (col_bytes > 0) { 81 if (col_bytes > 0) {
84 if (gfx::PNGCodec::Decode( 82 if (gfx::PNGCodec::Decode(
85 reinterpret_cast<const unsigned char*>(s.ColumnBlob(0)), 83 reinterpret_cast<const unsigned char*>(s.ColumnBlob(0)),
86 col_bytes, &image)) { 84 col_bytes, &image)) {
87 images->push_back(image); 85 images->push_back(image);
88 } else { 86 } else {
89 // Should only have valid image data in the db. 87 // Should only have valid image data in the db.
90 NOTREACHED(); 88 NOTREACHED();
91 } 89 }
92 } 90 }
93 } 91 }
94 return true; 92 return true;
95 } 93 }
96 94
97 bool WebAppsTable::SetWebAppHasAllImages(const GURL& url, 95 bool WebAppsTable::SetWebAppHasAllImages(const GURL& url,
98 bool has_all_images) { 96 bool has_all_images) {
99 sql::Statement s(db_->GetUniqueStatement( 97 sql::Statement s(db_->GetUniqueStatement(
100 "INSERT OR REPLACE INTO web_apps (url, has_all_images) VALUES (?, ?)")); 98 "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)); 99 s.BindString(0, history::HistoryDatabase::GURLToDatabaseURL(url));
106 s.BindInt(1, has_all_images ? 1 : 0); 100 s.BindInt(1, has_all_images ? 1 : 0);
101
107 return s.Run(); 102 return s.Run();
108 } 103 }
109 104
110 bool WebAppsTable::GetWebAppHasAllImages(const GURL& url) { 105 bool WebAppsTable::GetWebAppHasAllImages(const GURL& url) {
111 sql::Statement s(db_->GetUniqueStatement( 106 sql::Statement s(db_->GetUniqueStatement(
112 "SELECT has_all_images FROM web_apps WHERE url=?")); 107 "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)); 108 s.BindString(0, history::HistoryDatabase::GURLToDatabaseURL(url));
109
118 return (s.Step() && s.ColumnInt(0) == 1); 110 return (s.Step() && s.ColumnInt(0) == 1);
119 } 111 }
120 112
121 bool WebAppsTable::RemoveWebApp(const GURL& url) { 113 bool WebAppsTable::RemoveWebApp(const GURL& url) {
122 sql::Statement delete_s(db_->GetUniqueStatement( 114 sql::Statement delete_s(db_->GetUniqueStatement(
123 "DELETE FROM web_app_icons WHERE url = ?")); 115 "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)); 116 delete_s.BindString(0, history::HistoryDatabase::GURLToDatabaseURL(url));
117
129 if (!delete_s.Run()) 118 if (!delete_s.Run())
130 return false; 119 return false;
131 120
132 sql::Statement delete_s2(db_->GetUniqueStatement( 121 sql::Statement delete_s2(db_->GetUniqueStatement(
133 "DELETE FROM web_apps WHERE url = ?")); 122 "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)); 123 delete_s2.BindString(0, history::HistoryDatabase::GURLToDatabaseURL(url));
124
139 return delete_s2.Run(); 125 return delete_s2.Run();
140 } 126 }
141
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698