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

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

Issue 10917041: Cleanup FaviconSQLHandler::Update (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 8 years, 3 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
« no previous file with comments | « no previous file | chrome/browser/history/expire_history_backend_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // Remove existing icon mappings.
54 std::vector<IconMapping> icon_mappings; 55 std::vector<IconMapping> icon_mappings;
55 if (thumbnail_db_->GetIconMappingsForPageURL(i->url, FAVICON, 56 thumbnail_db_->GetIconMappingsForPageURL(i->url, FAVICON,
56 &icon_mappings)) { 57 &icon_mappings);
57 if (favicon_id) { 58 for (std::vector<IconMapping>::const_iterator m = icon_mappings.begin();
58 if (!thumbnail_db_->UpdateIconMapping(icon_mappings[0].mapping_id, 59 m != icon_mappings.end(); ++m) {
59 favicon_id))
60 return false;
61 } else {
62 // Require to delete the icon mapping.
63 if (!thumbnail_db_->DeleteIconMappings(i->url))
64 return false;
65 }
66 // Keep the old icon for deleting it later if possible. 60 // Keep the old icon for deleting it later if possible.
67 favicon_ids.push_back(icon_mappings[0].icon_id); 61 favicon_ids.push_back(m->icon_id);
68 } else if (favicon_id) { 62 }
69 // The URL doesn't have icon before, add the icon mapping. 63 if (!thumbnail_db_->DeleteIconMappings(i->url))
michaelbai 2012/09/07 00:29:59 This not right, you will delete all the mappings o
pkotwicz 2012/09/07 01:07:04 Is it the case, that in the case of favicon_id !=
64 return false;
65 if (favicon_id) {
66 // Add the icon mapping.
70 if (!thumbnail_db_->AddIconMapping(i->url, favicon_id)) 67 if (!thumbnail_db_->AddIconMapping(i->url, favicon_id))
71 return false; 68 return false;
72 } 69 }
73 } 70 }
74 // As we update the favicon, Let's remove unused favicons if any. 71 // As we update the favicon, Let's remove unused favicons if any.
75 if (!favicon_ids.empty() && !DeleteUnusedFavicon(favicon_ids)) 72 if (!favicon_ids.empty() && !DeleteUnusedFavicon(favicon_ids))
76 return false; 73 return false;
77 74
78 return true; 75 return true;
79 } 76 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 bool FaviconSQLHandler::DeleteUnusedFavicon(const std::vector<FaviconID>& ids) { 123 bool FaviconSQLHandler::DeleteUnusedFavicon(const std::vector<FaviconID>& ids) {
127 for (std::vector<FaviconID>::const_iterator i = ids.begin(); i != ids.end(); 124 for (std::vector<FaviconID>::const_iterator i = ids.begin(); i != ids.end();
128 ++i) { 125 ++i) {
129 if (!thumbnail_db_->HasMappingFor(*i) && !thumbnail_db_->DeleteFavicon(*i)) 126 if (!thumbnail_db_->HasMappingFor(*i) && !thumbnail_db_->DeleteFavicon(*i))
130 return false; 127 return false;
131 } 128 }
132 return true; 129 return true;
133 } 130 }
134 131
135 } // namespace history. 132 } // namespace history.
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/history/expire_history_backend_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698