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

Side by Side Diff: chrome/browser/history/android/favicon_sql_handler.cc

Issue 10802066: Adds support for saving favicon size into history database. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changes as requested by Sky and stevenjb Created 8 years, 4 months 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) 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 Time::Now(), 44 Time::Now(),
45 gfx::Size()); 45 gfx::Size());
46 46
47 if (!favicon_id) 47 if (!favicon_id)
48 return false; 48 return false;
49 } 49 }
50 50
51 std::vector<FaviconID> favicon_ids; 51 std::vector<FaviconID> favicon_ids;
52 for (TableIDRows::const_iterator i = ids_set.begin(); 52 for (TableIDRows::const_iterator i = ids_set.begin();
53 i != ids_set.end(); ++i) { 53 i != ids_set.end(); ++i) {
54 IconMapping icon_mapping; 54 // Remove existing icon mappings.
55 if (thumbnail_db_->GetIconMappingForPageURL(i->url, FAVICON, 55 std::vector<IconMapping> icon_mappings;
56 &icon_mapping)) { 56 if (thumbnail_db_->GetIconMappingsForPageURL(i->url, FAVICON,
57 if (favicon_id) { 57 &icon_mappings)) {
58 if (!thumbnail_db_->UpdateIconMapping(icon_mapping.mapping_id, 58 for (std::vector<IconMapping>::const_iterator m = icon_mappings.begin();
59 favicon_id)) 59 m != icon_mappings.end(); ++m) {
60 return false; 60 // Keep the old icon for deleting it later if possible.
61 } else { 61 favicon_ids.push_back(m->icon_id);
62 // Require to delete the icon mapping.
63 if (!thumbnail_db_->DeleteIconMappings(i->url))
64 return false;
65 } 62 }
66 // Keep the old icon for deleting it later if possible. 63 if (!thumbnail_db_->DeleteIconMappings(i->url))
67 favicon_ids.push_back(icon_mapping.icon_id); 64 return false;
68 } else if (favicon_id) { 65 }
69 // The URL doesn't have icon before, add the icon mapping. 66 if (favicon_id) {
67 // Add the icon mapping.
70 if (!thumbnail_db_->AddIconMapping(i->url, favicon_id)) 68 if (!thumbnail_db_->AddIconMapping(i->url, favicon_id))
71 return false; 69 return false;
72 } 70 }
73 } 71 }
74 // As we update the favicon, Let's remove unused favicons if any. 72 // As we update the favicon, Let's remove unused favicons if any.
75 if (!favicon_ids.empty() && !DeleteUnusedFavicon(favicon_ids)) 73 if (!favicon_ids.empty() && !DeleteUnusedFavicon(favicon_ids))
76 return false; 74 return false;
77 75
78 return true; 76 return true;
79 } 77 }
80 78
81 bool FaviconSQLHandler::Delete(const TableIDRows& ids_set) { 79 bool FaviconSQLHandler::Delete(const TableIDRows& ids_set) {
82 std::vector<FaviconID> favicon_ids; 80 std::vector<FaviconID> favicon_ids;
83 for (TableIDRows::const_iterator i = ids_set.begin(); 81 for (TableIDRows::const_iterator i = ids_set.begin();
84 i != ids_set.end(); ++i) { 82 i != ids_set.end(); ++i) {
85 // Since the URL was delete, we delete all type of icon mapping. 83 // Since the URL was delete, we delete all types of icon mappings.
stevenjb 2012/08/15 22:59:18 nit: was deleted
86 IconMapping icon_mapping; 84 std::vector<IconMapping> icon_mappings;
87 if (thumbnail_db_->GetIconMappingForPageURL(i->url, FAVICON, 85 if (thumbnail_db_->GetIconMappingsForPageURL(i->url, &icon_mappings)) {
88 &icon_mapping)) 86 for (std::vector<IconMapping>::const_iterator m = icon_mappings.begin();
89 favicon_ids.push_back(icon_mapping.icon_id); 87 m != icon_mappings.end(); ++m) {
90 if (thumbnail_db_->GetIconMappingForPageURL(i->url, TOUCH_ICON, 88 favicon_ids.push_back(m->icon_id);
91 &icon_mapping)) 89 }
92 favicon_ids.push_back(icon_mapping.icon_id); 90 }
93 if (thumbnail_db_->GetIconMappingForPageURL(i->url,
94 TOUCH_PRECOMPOSED_ICON, &icon_mapping))
95 favicon_ids.push_back(icon_mapping.icon_id);
96 if (!thumbnail_db_->DeleteIconMappings(i->url)) 91 if (!thumbnail_db_->DeleteIconMappings(i->url))
97 return false; 92 return false;
98 } 93 }
99 94
100 if (favicon_ids.empty()) 95 if (favicon_ids.empty())
101 return true; 96 return true;
102 97
103 if (!DeleteUnusedFavicon(favicon_ids)) 98 if (!DeleteUnusedFavicon(favicon_ids))
104 return false; 99 return false;
105 100
(...skipping 24 matching lines...) Expand all
130 bool FaviconSQLHandler::DeleteUnusedFavicon(const std::vector<FaviconID>& ids) { 125 bool FaviconSQLHandler::DeleteUnusedFavicon(const std::vector<FaviconID>& ids) {
131 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();
132 ++i) { 127 ++i) {
133 if (!thumbnail_db_->HasMappingFor(*i) && !thumbnail_db_->DeleteFavicon(*i)) 128 if (!thumbnail_db_->HasMappingFor(*i) && !thumbnail_db_->DeleteFavicon(*i))
134 return false; 129 return false;
135 } 130 }
136 return true; 131 return true;
137 } 132 }
138 133
139 } // namespace history. 134 } // namespace history.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698