Commit 51e854e5 authored by pkotwicz@chromium.org's avatar pkotwicz@chromium.org

Change HistoryAndBookmarkRow favicon_ field to be...

Change HistoryAndBookmarkRow favicon_ field to be scoped_refptr<base::RefCountedMemory> instead of std::vector<unsigned char>

Bug=138553
Test=Compiles

R=michaelbai
TBR=sky

Review URL: https://chromiumcodereview.appspot.com/10831341

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152193 0039d316-1c4b-4281-b951-d872f2087c98
parent 9a620e32
...@@ -117,14 +117,18 @@ class HistoryAndBookmarkRow { ...@@ -117,14 +117,18 @@ class HistoryAndBookmarkRow {
} }
// The favicon related to page if any. // The favicon related to page if any.
void set_favicon(const std::vector<unsigned char>& data) { void set_favicon(const scoped_refptr<base::RefCountedMemory>& data) {
set_value_explicitly(FAVICON); set_value_explicitly(FAVICON);
favicon_ = data; favicon_ = data;
} }
const std::vector<unsigned char>& favicon() const { const scoped_refptr<base::RefCountedMemory>& favicon() const {
return favicon_; return favicon_;
} }
bool favicon_valid() const {
return favicon_.get() && favicon_->size();
}
// The id of android url. // The id of android url.
void set_id(AndroidURLID id) { void set_id(AndroidURLID id) {
set_value_explicitly(ID); set_value_explicitly(ID);
...@@ -168,7 +172,7 @@ class HistoryAndBookmarkRow { ...@@ -168,7 +172,7 @@ class HistoryAndBookmarkRow {
string16 title_; string16 title_;
base::Time created_; base::Time created_;
base::Time last_visit_time_; base::Time last_visit_time_;
std::vector<unsigned char> favicon_; scoped_refptr<base::RefCountedMemory> favicon_;
int visit_count_; int visit_count_;
bool is_bookmark_; bool is_bookmark_;
int64 parent_id_; int64 parent_id_;
......
...@@ -385,7 +385,7 @@ AndroidURLID AndroidProviderBackend::InsertHistoryAndBookmark( ...@@ -385,7 +385,7 @@ AndroidURLID AndroidProviderBackend::InsertHistoryAndBookmark(
scoped_ptr<FaviconChangeDetails> favicon; scoped_ptr<FaviconChangeDetails> favicon;
if (row.is_value_set_explicitly(HistoryAndBookmarkRow::FAVICON) && if (row.is_value_set_explicitly(HistoryAndBookmarkRow::FAVICON) &&
!row.favicon().empty()) { row.favicon_valid()) {
favicon.reset(new FaviconChangeDetails); favicon.reset(new FaviconChangeDetails);
if (!favicon.get()) if (!favicon.get())
return false; return false;
...@@ -966,10 +966,11 @@ bool AndroidProviderBackend::SimulateUpdateURL( ...@@ -966,10 +966,11 @@ bool AndroidProviderBackend::SimulateUpdateURL(
FaviconID favicon_id = statement->statement()->ColumnInt64(4); FaviconID favicon_id = statement->statement()->ColumnInt64(4);
if (favicon_id) { if (favicon_id) {
std::vector<unsigned char> favicon; scoped_refptr<base::RefCountedBytes> favicon = new base::RefCountedBytes();
if (!thumbnail_db_->GetFavicon(favicon_id, NULL, &favicon, NULL, NULL)) if (!thumbnail_db_->GetFavicon(favicon_id, NULL, &favicon->data(), NULL,
NULL))
return false; return false;
if (!favicon.empty()) if (favicon->size())
new_row.set_favicon(favicon); new_row.set_favicon(favicon);
favicon_details->urls.insert(old_url_row.url()); favicon_details->urls.insert(old_url_row.url());
favicon_details->urls.insert(row.url()); favicon_details->urls.insert(row.url());
......
...@@ -497,7 +497,7 @@ TEST_F(AndroidProviderBackendTest, InsertHistoryAndBookmark) { ...@@ -497,7 +497,7 @@ TEST_F(AndroidProviderBackendTest, InsertHistoryAndBookmark) {
row2.set_title(UTF8ToUTF16("example")); row2.set_title(UTF8ToUTF16("example"));
std::vector<unsigned char> data; std::vector<unsigned char> data;
data.push_back('1'); data.push_back('1');
row2.set_favicon(data); row2.set_favicon(base::RefCountedBytes::TakeVector(&data));
ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_, bookmark_temp_)); ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_, bookmark_temp_));
ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_, NULL, ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_, NULL,
...@@ -606,7 +606,7 @@ TEST_F(AndroidProviderBackendTest, DeleteHistoryAndBookmarks) { ...@@ -606,7 +606,7 @@ TEST_F(AndroidProviderBackendTest, DeleteHistoryAndBookmarks) {
row2.set_title(UTF8ToUTF16("example")); row2.set_title(UTF8ToUTF16("example"));
std::vector<unsigned char> data; std::vector<unsigned char> data;
data.push_back('1'); data.push_back('1');
row2.set_favicon(data); row2.set_favicon(base::RefCountedBytes::TakeVector(&data));
ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_, bookmark_temp_)); ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_, bookmark_temp_));
ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_, NULL, ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_, NULL,
...@@ -795,7 +795,7 @@ TEST_F(AndroidProviderBackendTest, UpdateURL) { ...@@ -795,7 +795,7 @@ TEST_F(AndroidProviderBackendTest, UpdateURL) {
row2.set_title(UTF8ToUTF16("example")); row2.set_title(UTF8ToUTF16("example"));
std::vector<unsigned char> data; std::vector<unsigned char> data;
data.push_back('1'); data.push_back('1');
row2.set_favicon(data); row2.set_favicon(base::RefCountedBytes::TakeVector(&data));
ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_, bookmark_temp_)); ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_, bookmark_temp_));
ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_, NULL, ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_, NULL,
...@@ -975,7 +975,7 @@ TEST_F(AndroidProviderBackendTest, UpdateVisitCount) { ...@@ -975,7 +975,7 @@ TEST_F(AndroidProviderBackendTest, UpdateVisitCount) {
row2.set_title(UTF8ToUTF16("example")); row2.set_title(UTF8ToUTF16("example"));
std::vector<unsigned char> data; std::vector<unsigned char> data;
data.push_back('1'); data.push_back('1');
row2.set_favicon(data); row2.set_favicon(base::RefCountedBytes::TakeVector(&data));
ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_, bookmark_temp_)); ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_, bookmark_temp_));
ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_, NULL, ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_, NULL,
...@@ -1056,7 +1056,7 @@ TEST_F(AndroidProviderBackendTest, UpdateLastVisitTime) { ...@@ -1056,7 +1056,7 @@ TEST_F(AndroidProviderBackendTest, UpdateLastVisitTime) {
row2.set_title(UTF8ToUTF16("example")); row2.set_title(UTF8ToUTF16("example"));
std::vector<unsigned char> data; std::vector<unsigned char> data;
data.push_back('1'); data.push_back('1');
row2.set_favicon(data); row2.set_favicon(base::RefCountedBytes::TakeVector(&data));
ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_, bookmark_temp_)); ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_, bookmark_temp_));
ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_, NULL, ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_, NULL,
...@@ -1138,7 +1138,7 @@ TEST_F(AndroidProviderBackendTest, UpdateFavicon) { ...@@ -1138,7 +1138,7 @@ TEST_F(AndroidProviderBackendTest, UpdateFavicon) {
// Set favicon. // Set favicon.
std::vector<unsigned char> data; std::vector<unsigned char> data;
data.push_back('1'); data.push_back('1');
update_row1.set_favicon(data); update_row1.set_favicon(base::RefCountedBytes::TakeVector(&data));
update_args.push_back(UTF8ToUTF16(row1.raw_url())); update_args.push_back(UTF8ToUTF16(row1.raw_url()));
delegate_.ResetDetails(); delegate_.ResetDetails();
ASSERT_TRUE(backend->UpdateHistoryAndBookmarks(update_row1, "url = ?", ASSERT_TRUE(backend->UpdateHistoryAndBookmarks(update_row1, "url = ?",
...@@ -1164,7 +1164,7 @@ TEST_F(AndroidProviderBackendTest, UpdateFavicon) { ...@@ -1164,7 +1164,7 @@ TEST_F(AndroidProviderBackendTest, UpdateFavicon) {
HistoryAndBookmarkRow update_row2; HistoryAndBookmarkRow update_row2;
// Set favicon. // Set favicon.
update_row1.set_favicon(std::vector<unsigned char>()); update_row1.set_favicon(new base::RefCountedBytes());
update_args.clear(); update_args.clear();
update_args.push_back(UTF8ToUTF16(row1.raw_url())); update_args.push_back(UTF8ToUTF16(row1.raw_url()));
delegate_.ResetDetails(); delegate_.ResetDetails();
...@@ -1561,7 +1561,7 @@ TEST_F(AndroidProviderBackendTest, DeleteHistory) { ...@@ -1561,7 +1561,7 @@ TEST_F(AndroidProviderBackendTest, DeleteHistory) {
row2.set_title(UTF8ToUTF16("example")); row2.set_title(UTF8ToUTF16("example"));
std::vector<unsigned char> data; std::vector<unsigned char> data;
data.push_back('1'); data.push_back('1');
row2.set_favicon(data); row2.set_favicon(base::RefCountedBytes::TakeVector(&data));
ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_, bookmark_temp_)); ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_, bookmark_temp_));
ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_, NULL, ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_, NULL,
...@@ -1728,7 +1728,7 @@ TEST_F(AndroidProviderBackendTest, AndroidCTSComplianceFolderColumnExists) { ...@@ -1728,7 +1728,7 @@ TEST_F(AndroidProviderBackendTest, AndroidCTSComplianceFolderColumnExists) {
row2.set_title(UTF8ToUTF16("example")); row2.set_title(UTF8ToUTF16("example"));
std::vector<unsigned char> data; std::vector<unsigned char> data;
data.push_back('1'); data.push_back('1');
row2.set_favicon(data); row2.set_favicon(base::RefCountedBytes::TakeVector(&data));
AndroidURLID id1 = backend->InsertHistoryAndBookmark(row1); AndroidURLID id1 = backend->InsertHistoryAndBookmark(row1);
ASSERT_TRUE(id1); ASSERT_TRUE(id1);
......
...@@ -32,15 +32,14 @@ FaviconSQLHandler::~FaviconSQLHandler() { ...@@ -32,15 +32,14 @@ FaviconSQLHandler::~FaviconSQLHandler() {
bool FaviconSQLHandler::Update(const HistoryAndBookmarkRow& row, bool FaviconSQLHandler::Update(const HistoryAndBookmarkRow& row,
const TableIDRows& ids_set) { const TableIDRows& ids_set) {
FaviconID favicon_id = 0; FaviconID favicon_id = 0;
if (!row.favicon().empty()) { if (row.favicon_valid()) {
// If the image_data will be updated, it is not reasonable to find if the // If the image_data will be updated, it is not reasonable to find if the
// icon is already in database, just create a new favicon. // icon is already in database, just create a new favicon.
favicon_id = thumbnail_db_->AddFavicon(GURL(), history::FAVICON); favicon_id = thumbnail_db_->AddFavicon(GURL(), history::FAVICON);
if (!favicon_id) if (!favicon_id)
return false; return false;
scoped_refptr<base::RefCountedMemory> image_data = scoped_refptr<base::RefCountedMemory> image_data = row.favicon();
new base::RefCountedBytes(row.favicon());
if (!thumbnail_db_->SetFavicon(favicon_id, image_data, Time::Now())) if (!thumbnail_db_->SetFavicon(favicon_id, image_data, Time::Now()))
return false; return false;
} }
...@@ -105,7 +104,7 @@ bool FaviconSQLHandler::Delete(const TableIDRows& ids_set) { ...@@ -105,7 +104,7 @@ bool FaviconSQLHandler::Delete(const TableIDRows& ids_set) {
bool FaviconSQLHandler::Insert(HistoryAndBookmarkRow* row) { bool FaviconSQLHandler::Insert(HistoryAndBookmarkRow* row) {
if (!row->is_value_set_explicitly(HistoryAndBookmarkRow::FAVICON) || if (!row->is_value_set_explicitly(HistoryAndBookmarkRow::FAVICON) ||
row->favicon().empty()) !row->favicon_valid())
return true; return true;
DCHECK(row->is_value_set_explicitly(HistoryAndBookmarkRow::URL)); DCHECK(row->is_value_set_explicitly(HistoryAndBookmarkRow::URL));
...@@ -115,8 +114,7 @@ bool FaviconSQLHandler::Insert(HistoryAndBookmarkRow* row) { ...@@ -115,8 +114,7 @@ bool FaviconSQLHandler::Insert(HistoryAndBookmarkRow* row) {
if (!id) if (!id)
return false; return false;
scoped_refptr<base::RefCountedMemory> image_data = scoped_refptr<base::RefCountedMemory> image_data = row->favicon();
new base::RefCountedBytes(row->favicon());
if (!thumbnail_db_->SetFavicon(id, image_data, Time::Now())) if (!thumbnail_db_->SetFavicon(id, image_data, Time::Now()))
return false; return false;
return thumbnail_db_->AddIconMapping(row->url(), id); return thumbnail_db_->AddIconMapping(row->url(), id);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment