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" |
11 | 11 |
12 using base::Time; | 12 using base::Time; |
13 | 13 |
14 namespace history { | 14 namespace history { |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 // The interesting columns of this handler. | 18 // The interesting columns of this handler. |
19 const HistoryAndBookmarkRow::ColumnID kInterestingColumns[] = { | 19 const HistoryAndBookmarkRow::ColumnID kInterestingColumns[] = { |
20 HistoryAndBookmarkRow::FAVICON}; | 20 HistoryAndBookmarkRow::FAVICON}; |
21 | 21 |
22 } // namespace | 22 } // namespace |
23 | 23 |
24 FaviconSQLHandler::FaviconSQLHandler(ThumbnailDatabase* thumbnail_db) | 24 FaviconSQLHandler::FaviconSQLHandler(ThumbnailDatabase* thumbnail_db) |
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_valid()) { |
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 // TODO(pkotwicz): Pass in real pixel size. |
| 39 favicon_id = thumbnail_db_->AddFavicon( |
| 40 GURL(), |
| 41 history::FAVICON, |
| 42 std::string("0 0"), |
| 43 row.favicon(), |
| 44 Time::Now(), |
| 45 gfx::Size()); |
| 46 |
39 if (!favicon_id) | 47 if (!favicon_id) |
40 return false; | 48 return false; |
41 | |
42 scoped_refptr<base::RefCountedMemory> image_data = row.favicon(); | |
43 if (!thumbnail_db_->SetFavicon(favicon_id, image_data, Time::Now())) | |
44 return false; | |
45 } | 49 } |
46 | 50 |
47 std::vector<FaviconID> favicon_ids; | 51 std::vector<FaviconID> favicon_ids; |
48 for (TableIDRows::const_iterator i = ids_set.begin(); | 52 for (TableIDRows::const_iterator i = ids_set.begin(); |
49 i != ids_set.end(); ++i) { | 53 i != ids_set.end(); ++i) { |
50 IconMapping icon_mapping; | 54 IconMapping icon_mapping; |
51 if (thumbnail_db_->GetIconMappingForPageURL(i->url, FAVICON, | 55 if (thumbnail_db_->GetIconMappingForPageURL(i->url, FAVICON, |
52 &icon_mapping)) { | 56 &icon_mapping)) { |
53 if (favicon_id) { | 57 if (favicon_id) { |
54 if (!thumbnail_db_->UpdateIconMapping(icon_mapping.mapping_id, | 58 if (!thumbnail_db_->UpdateIconMapping(icon_mapping.mapping_id, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 } | 107 } |
104 | 108 |
105 bool FaviconSQLHandler::Insert(HistoryAndBookmarkRow* row) { | 109 bool FaviconSQLHandler::Insert(HistoryAndBookmarkRow* row) { |
106 if (!row->is_value_set_explicitly(HistoryAndBookmarkRow::FAVICON) || | 110 if (!row->is_value_set_explicitly(HistoryAndBookmarkRow::FAVICON) || |
107 !row->favicon_valid()) | 111 !row->favicon_valid()) |
108 return true; | 112 return true; |
109 | 113 |
110 DCHECK(row->is_value_set_explicitly(HistoryAndBookmarkRow::URL)); | 114 DCHECK(row->is_value_set_explicitly(HistoryAndBookmarkRow::URL)); |
111 | 115 |
112 // Is it a problem to give a empty URL? | 116 // Is it a problem to give a empty URL? |
113 FaviconID id = thumbnail_db_->AddFavicon(GURL(), history::FAVICON); | 117 // TODO(pkotwicz): Pass in real pixel size. |
| 118 FaviconID id = thumbnail_db_->AddFavicon( |
| 119 GURL(), |
| 120 history::FAVICON, |
| 121 std::string("0 0"), |
| 122 row->favicon(), |
| 123 Time::Now(), |
| 124 gfx::Size()); |
114 if (!id) | 125 if (!id) |
115 return false; | 126 return false; |
116 | |
117 scoped_refptr<base::RefCountedMemory> image_data = row->favicon(); | |
118 if (!thumbnail_db_->SetFavicon(id, image_data, Time::Now())) | |
119 return false; | |
120 return thumbnail_db_->AddIconMapping(row->url(), id); | 127 return thumbnail_db_->AddIconMapping(row->url(), id); |
121 } | 128 } |
122 | 129 |
123 bool FaviconSQLHandler::DeleteUnusedFavicon(const std::vector<FaviconID>& ids) { | 130 bool FaviconSQLHandler::DeleteUnusedFavicon(const std::vector<FaviconID>& ids) { |
124 for (std::vector<FaviconID>::const_iterator i = ids.begin(); i != ids.end(); | 131 for (std::vector<FaviconID>::const_iterator i = ids.begin(); i != ids.end(); |
125 ++i) { | 132 ++i) { |
126 if (!thumbnail_db_->HasMappingFor(*i) && !thumbnail_db_->DeleteFavicon(*i)) | 133 if (!thumbnail_db_->HasMappingFor(*i) && !thumbnail_db_->DeleteFavicon(*i)) |
127 return false; | 134 return false; |
128 } | 135 } |
129 return true; | 136 return true; |
130 } | 137 } |
131 | 138 |
132 } // namespace history. | 139 } // namespace history. |
OLD | NEW |