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

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: 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 if (m->icon_id != favicon_id) {
61 } else { 61 // Keep the old icon for deleting it later if possible.
62 // Require to delete the icon mapping. 62 favicon_ids.push_back(m->icon_id);
63 if (!thumbnail_db_->DeleteIconMappings(i->url)) 63 }
64 return false;
65 } 64 }
66 // Keep the old icon for deleting it later if possible. 65 if (!thumbnail_db_->DeleteIconMappings(i->url))
67 favicon_ids.push_back(icon_mapping.icon_id); 66 return false;
68 } else if (favicon_id) { 67 }
69 // The URL doesn't have icon before, add the icon mapping. 68 if (favicon_id) {
69 // Add the icon mapping.
70 if (!thumbnail_db_->AddIconMapping(i->url, favicon_id)) 70 if (!thumbnail_db_->AddIconMapping(i->url, favicon_id))
71 return false; 71 return false;
72 } 72 }
73 } 73 }
74 // As we update the favicon, Let's remove unused favicons if any. 74 // As we update the favicon, Let's remove unused favicons if any.
75 if (!favicon_ids.empty() && !DeleteUnusedFavicon(favicon_ids)) 75 if (!favicon_ids.empty() && !DeleteUnusedFavicon(favicon_ids))
76 return false; 76 return false;
77 77
78 return true; 78 return true;
79 } 79 }
80 80
81 bool FaviconSQLHandler::Delete(const TableIDRows& ids_set) { 81 bool FaviconSQLHandler::Delete(const TableIDRows& ids_set) {
82 std::vector<FaviconID> favicon_ids; 82 std::vector<FaviconID> favicon_ids;
83 for (TableIDRows::const_iterator i = ids_set.begin(); 83 for (TableIDRows::const_iterator i = ids_set.begin();
84 i != ids_set.end(); ++i) { 84 i != ids_set.end(); ++i) {
85 // Since the URL was delete, we delete all type of icon mapping. 85 // Since the URL was deleted, we delete all types of icon mappings.
86 IconMapping icon_mapping; 86 std::vector<IconMapping> icon_mappings;
87 if (thumbnail_db_->GetIconMappingForPageURL(i->url, FAVICON, 87 if (thumbnail_db_->GetIconMappingsForPageURL(i->url, &icon_mappings)) {
88 &icon_mapping)) 88 for (std::vector<IconMapping>::const_iterator m = icon_mappings.begin();
89 favicon_ids.push_back(icon_mapping.icon_id); 89 m != icon_mappings.end(); ++m) {
90 if (thumbnail_db_->GetIconMappingForPageURL(i->url, TOUCH_ICON, 90 favicon_ids.push_back(m->icon_id);
91 &icon_mapping)) 91 }
92 favicon_ids.push_back(icon_mapping.icon_id); 92 }
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)) 93 if (!thumbnail_db_->DeleteIconMappings(i->url))
97 return false; 94 return false;
98 } 95 }
99 96
100 if (favicon_ids.empty()) 97 if (favicon_ids.empty())
101 return true; 98 return true;
102 99
103 if (!DeleteUnusedFavicon(favicon_ids)) 100 if (!DeleteUnusedFavicon(favicon_ids))
104 return false; 101 return false;
105 102
(...skipping 24 matching lines...) Expand all
130 bool FaviconSQLHandler::DeleteUnusedFavicon(const std::vector<FaviconID>& ids) { 127 bool FaviconSQLHandler::DeleteUnusedFavicon(const std::vector<FaviconID>& ids) {
131 for (std::vector<FaviconID>::const_iterator i = ids.begin(); i != ids.end(); 128 for (std::vector<FaviconID>::const_iterator i = ids.begin(); i != ids.end();
132 ++i) { 129 ++i) {
133 if (!thumbnail_db_->HasMappingFor(*i) && !thumbnail_db_->DeleteFavicon(*i)) 130 if (!thumbnail_db_->HasMappingFor(*i) && !thumbnail_db_->DeleteFavicon(*i))
134 return false; 131 return false;
135 } 132 }
136 return true; 133 return true;
137 } 134 }
138 135
139 } // namespace history. 136 } // namespace history.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698