OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/history/android/favicon_sql_handler.h" | 5 #include "chrome/browser/history/android/favicon_sql_handler.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/ref_counted_memory.h" | 9 #include "base/memory/ref_counted_memory.h" |
10 #include "chrome/browser/history/thumbnail_database.h" | 10 #include "chrome/browser/history/thumbnail_database.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 : SQLHandler(kInterestingColumns, arraysize(kInterestingColumns)), | 25 : SQLHandler(kInterestingColumns, arraysize(kInterestingColumns)), |
26 thumbnail_db_(thumbnail_db) { | 26 thumbnail_db_(thumbnail_db) { |
27 } | 27 } |
28 | 28 |
29 FaviconSQLHandler::~FaviconSQLHandler() { | 29 FaviconSQLHandler::~FaviconSQLHandler() { |
30 } | 30 } |
31 | 31 |
32 bool FaviconSQLHandler::Update(const HistoryAndBookmarkRow& row, | 32 bool FaviconSQLHandler::Update(const HistoryAndBookmarkRow& row, |
33 const TableIDRows& ids_set) { | 33 const TableIDRows& ids_set) { |
34 FaviconID favicon_id = 0; | 34 FaviconID favicon_id = 0; |
35 if (row.favicon_valid()) { | 35 if (!row.favicon().empty()) { |
36 // If the image_data will be updated, it is not reasonable to find if the | 36 // If the image_data will be updated, it is not reasonable to find if the |
37 // icon is already in database, just create a new favicon. | 37 // icon is already in database, just create a new favicon. |
38 favicon_id = thumbnail_db_->AddFavicon(GURL(), history::FAVICON); | 38 favicon_id = thumbnail_db_->AddFavicon(GURL(), history::FAVICON); |
39 if (!favicon_id) | 39 if (!favicon_id) |
40 return false; | 40 return false; |
41 | 41 |
42 scoped_refptr<base::RefCountedMemory> image_data = row.favicon(); | 42 scoped_refptr<base::RefCountedMemory> image_data = |
| 43 new base::RefCountedBytes(row.favicon()); |
43 if (!thumbnail_db_->SetFavicon(favicon_id, image_data, Time::Now())) | 44 if (!thumbnail_db_->SetFavicon(favicon_id, image_data, Time::Now())) |
44 return false; | 45 return false; |
45 } | 46 } |
46 | 47 |
47 std::vector<FaviconID> favicon_ids; | 48 std::vector<FaviconID> favicon_ids; |
48 for (TableIDRows::const_iterator i = ids_set.begin(); | 49 for (TableIDRows::const_iterator i = ids_set.begin(); |
49 i != ids_set.end(); ++i) { | 50 i != ids_set.end(); ++i) { |
50 IconMapping icon_mapping; | 51 IconMapping icon_mapping; |
51 if (thumbnail_db_->GetIconMappingForPageURL(i->url, FAVICON, | 52 if (thumbnail_db_->GetIconMappingForPageURL(i->url, FAVICON, |
52 &icon_mapping)) { | 53 &icon_mapping)) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 return true; | 98 return true; |
98 | 99 |
99 if (!DeleteUnusedFavicon(favicon_ids)) | 100 if (!DeleteUnusedFavicon(favicon_ids)) |
100 return false; | 101 return false; |
101 | 102 |
102 return true; | 103 return true; |
103 } | 104 } |
104 | 105 |
105 bool FaviconSQLHandler::Insert(HistoryAndBookmarkRow* row) { | 106 bool FaviconSQLHandler::Insert(HistoryAndBookmarkRow* row) { |
106 if (!row->is_value_set_explicitly(HistoryAndBookmarkRow::FAVICON) || | 107 if (!row->is_value_set_explicitly(HistoryAndBookmarkRow::FAVICON) || |
107 !row->favicon_valid()) | 108 row->favicon().empty()) |
108 return true; | 109 return true; |
109 | 110 |
110 DCHECK(row->is_value_set_explicitly(HistoryAndBookmarkRow::URL)); | 111 DCHECK(row->is_value_set_explicitly(HistoryAndBookmarkRow::URL)); |
111 | 112 |
112 // Is it a problem to give a empty URL? | 113 // Is it a problem to give a empty URL? |
113 FaviconID id = thumbnail_db_->AddFavicon(GURL(), history::FAVICON); | 114 FaviconID id = thumbnail_db_->AddFavicon(GURL(), history::FAVICON); |
114 if (!id) | 115 if (!id) |
115 return false; | 116 return false; |
116 | 117 |
117 scoped_refptr<base::RefCountedMemory> image_data = row->favicon(); | 118 scoped_refptr<base::RefCountedMemory> image_data = |
| 119 new base::RefCountedBytes(row->favicon()); |
118 if (!thumbnail_db_->SetFavicon(id, image_data, Time::Now())) | 120 if (!thumbnail_db_->SetFavicon(id, image_data, Time::Now())) |
119 return false; | 121 return false; |
120 return thumbnail_db_->AddIconMapping(row->url(), id); | 122 return thumbnail_db_->AddIconMapping(row->url(), id); |
121 } | 123 } |
122 | 124 |
123 bool FaviconSQLHandler::DeleteUnusedFavicon(const std::vector<FaviconID>& ids) { | 125 bool FaviconSQLHandler::DeleteUnusedFavicon(const std::vector<FaviconID>& ids) { |
124 for (std::vector<FaviconID>::const_iterator i = ids.begin(); i != ids.end(); | 126 for (std::vector<FaviconID>::const_iterator i = ids.begin(); i != ids.end(); |
125 ++i) { | 127 ++i) { |
126 if (!thumbnail_db_->HasMappingFor(*i) && !thumbnail_db_->DeleteFavicon(*i)) | 128 if (!thumbnail_db_->HasMappingFor(*i) && !thumbnail_db_->DeleteFavicon(*i)) |
127 return false; | 129 return false; |
128 } | 130 } |
129 return true; | 131 return true; |
130 } | 132 } |
131 | 133 |
132 } // namespace history. | 134 } // namespace history. |
OLD | NEW |