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

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

Issue 10831341: Change HistoryAndBookmarkRow favicon_ field to be scoped_refptr<base::RefCountedMemory> (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
« no previous file with comments | « chrome/browser/history/android/android_provider_backend_unittest.cc ('k') | no next file » | 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 14 matching lines...) Expand all
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().empty()) { 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 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 = 42 scoped_refptr<base::RefCountedMemory> image_data = row.favicon();
43 new base::RefCountedBytes(row.favicon());
44 if (!thumbnail_db_->SetFavicon(favicon_id, image_data, Time::Now())) 43 if (!thumbnail_db_->SetFavicon(favicon_id, image_data, Time::Now()))
45 return false; 44 return false;
46 } 45 }
47 46
48 std::vector<FaviconID> favicon_ids; 47 std::vector<FaviconID> favicon_ids;
49 for (TableIDRows::const_iterator i = ids_set.begin(); 48 for (TableIDRows::const_iterator i = ids_set.begin();
50 i != ids_set.end(); ++i) { 49 i != ids_set.end(); ++i) {
51 IconMapping icon_mapping; 50 IconMapping icon_mapping;
52 if (thumbnail_db_->GetIconMappingForPageURL(i->url, FAVICON, 51 if (thumbnail_db_->GetIconMappingForPageURL(i->url, FAVICON,
53 &icon_mapping)) { 52 &icon_mapping)) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 return true; 97 return true;
99 98
100 if (!DeleteUnusedFavicon(favicon_ids)) 99 if (!DeleteUnusedFavicon(favicon_ids))
101 return false; 100 return false;
102 101
103 return true; 102 return true;
104 } 103 }
105 104
106 bool FaviconSQLHandler::Insert(HistoryAndBookmarkRow* row) { 105 bool FaviconSQLHandler::Insert(HistoryAndBookmarkRow* row) {
107 if (!row->is_value_set_explicitly(HistoryAndBookmarkRow::FAVICON) || 106 if (!row->is_value_set_explicitly(HistoryAndBookmarkRow::FAVICON) ||
108 row->favicon().empty()) 107 !row->favicon_valid())
109 return true; 108 return true;
110 109
111 DCHECK(row->is_value_set_explicitly(HistoryAndBookmarkRow::URL)); 110 DCHECK(row->is_value_set_explicitly(HistoryAndBookmarkRow::URL));
112 111
113 // Is it a problem to give a empty URL? 112 // Is it a problem to give a empty URL?
114 FaviconID id = thumbnail_db_->AddFavicon(GURL(), history::FAVICON); 113 FaviconID id = thumbnail_db_->AddFavicon(GURL(), history::FAVICON);
115 if (!id) 114 if (!id)
116 return false; 115 return false;
117 116
118 scoped_refptr<base::RefCountedMemory> image_data = 117 scoped_refptr<base::RefCountedMemory> image_data = row->favicon();
119 new base::RefCountedBytes(row->favicon());
120 if (!thumbnail_db_->SetFavicon(id, image_data, Time::Now())) 118 if (!thumbnail_db_->SetFavicon(id, image_data, Time::Now()))
121 return false; 119 return false;
122 return thumbnail_db_->AddIconMapping(row->url(), id); 120 return thumbnail_db_->AddIconMapping(row->url(), id);
123 } 121 }
124 122
125 bool FaviconSQLHandler::DeleteUnusedFavicon(const std::vector<FaviconID>& ids) { 123 bool FaviconSQLHandler::DeleteUnusedFavicon(const std::vector<FaviconID>& ids) {
126 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();
127 ++i) { 125 ++i) {
128 if (!thumbnail_db_->HasMappingFor(*i) && !thumbnail_db_->DeleteFavicon(*i)) 126 if (!thumbnail_db_->HasMappingFor(*i) && !thumbnail_db_->DeleteFavicon(*i))
129 return false; 127 return false;
130 } 128 }
131 return true; 129 return true;
132 } 130 }
133 131
134 } // namespace history. 132 } // namespace history.
OLDNEW
« no previous file with comments | « chrome/browser/history/android/android_provider_backend_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698