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

Side by Side Diff: chrome/browser/custom_home_pages_table_model.cc

Issue 6044007: Remove wstring from TableModel.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 12 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/custom_home_pages_table_model.h" 5 #include "chrome/browser/custom_home_pages_table_model.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "app/table_model_observer.h" 9 #include "app/table_model_observer.h"
10 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
(...skipping 12 matching lines...) Expand all
23 #include "net/base/net_util.h" 23 #include "net/base/net_util.h"
24 #include "third_party/skia/include/core/SkBitmap.h" 24 #include "third_party/skia/include/core/SkBitmap.h"
25 25
26 struct CustomHomePagesTableModel::Entry { 26 struct CustomHomePagesTableModel::Entry {
27 Entry() : title_handle(0), fav_icon_handle(0) {} 27 Entry() : title_handle(0), fav_icon_handle(0) {}
28 28
29 // URL of the page. 29 // URL of the page.
30 GURL url; 30 GURL url;
31 31
32 // Page title. If this is empty, we'll display the URL as the entry. 32 // Page title. If this is empty, we'll display the URL as the entry.
33 std::wstring title; 33 string16 title;
34 34
35 // Icon for the page. 35 // Icon for the page.
36 SkBitmap icon; 36 SkBitmap icon;
37 37
38 // If non-zero, indicates we're loading the title for the page. 38 // If non-zero, indicates we're loading the title for the page.
39 HistoryService::Handle title_handle; 39 HistoryService::Handle title_handle;
40 40
41 // If non-zero, indicates we're loading the favicon for the page. 41 // If non-zero, indicates we're loading the favicon for the page.
42 FaviconService::Handle fav_icon_handle; 42 FaviconService::Handle fav_icon_handle;
43 }; 43 };
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 std::vector<GURL> urls(entries_.size()); 123 std::vector<GURL> urls(entries_.size());
124 for (size_t i = 0; i < entries_.size(); ++i) 124 for (size_t i = 0; i < entries_.size(); ++i)
125 urls[i] = entries_[i].url; 125 urls[i] = entries_[i].url;
126 return urls; 126 return urls;
127 } 127 }
128 128
129 int CustomHomePagesTableModel::RowCount() { 129 int CustomHomePagesTableModel::RowCount() {
130 return static_cast<int>(entries_.size()); 130 return static_cast<int>(entries_.size());
131 } 131 }
132 132
133 std::wstring CustomHomePagesTableModel::GetText(int row, int column_id) { 133 string16 CustomHomePagesTableModel::GetText(int row, int column_id) {
134 DCHECK(column_id == 0); 134 DCHECK(column_id == 0);
135 DCHECK(row >= 0 && row < RowCount()); 135 DCHECK(row >= 0 && row < RowCount());
136 return entries_[row].title.empty() ? FormattedURL(row) : entries_[row].title; 136 return entries_[row].title.empty() ? FormattedURL(row) : entries_[row].title;
137 } 137 }
138 138
139 SkBitmap CustomHomePagesTableModel::GetIcon(int row) { 139 SkBitmap CustomHomePagesTableModel::GetIcon(int row) {
140 DCHECK(row >= 0 && row < RowCount()); 140 DCHECK(row >= 0 && row < RowCount());
141 return entries_[row].icon.isNull() ? *default_favicon_ : entries_[row].icon; 141 return entries_[row].icon.isNull() ? *default_favicon_ : entries_[row].icon;
142 } 142 }
143 143
144 std::wstring CustomHomePagesTableModel::GetTooltip(int row) { 144 string16 CustomHomePagesTableModel::GetTooltip(int row) {
145 return entries_[row].title.empty() ? std::wstring() : UTF16ToWideHack( 145 return entries_[row].title.empty() ? string16() :
146 l10n_util::GetStringFUTF16(IDS_OPTIONS_STARTUP_PAGE_TOOLTIP, 146 l10n_util::GetStringFUTF16(IDS_OPTIONS_STARTUP_PAGE_TOOLTIP,
147 WideToUTF16Hack(entries_[row].title), 147 entries_[row].title, FormattedURL(row));
148 WideToUTF16Hack(FormattedURL(row))));
149 } 148 }
150 149
151 void CustomHomePagesTableModel::SetObserver(TableModelObserver* observer) { 150 void CustomHomePagesTableModel::SetObserver(TableModelObserver* observer) {
152 observer_ = observer; 151 observer_ = observer;
153 } 152 }
154 153
155 void CustomHomePagesTableModel::LoadTitleAndFavIcon(Entry* entry) { 154 void CustomHomePagesTableModel::LoadTitleAndFavIcon(Entry* entry) {
156 HistoryService* history_service = 155 HistoryService* history_service =
157 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); 156 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
158 if (history_service) { 157 if (history_service) {
(...skipping 16 matching lines...) Expand all
175 history::VisitVector* visits) { 174 history::VisitVector* visits) {
176 int entry_index; 175 int entry_index;
177 Entry* entry = 176 Entry* entry =
178 GetEntryByLoadHandle(&Entry::title_handle, handle, &entry_index); 177 GetEntryByLoadHandle(&Entry::title_handle, handle, &entry_index);
179 if (!entry) { 178 if (!entry) {
180 // The URLs changed before we were called back. 179 // The URLs changed before we were called back.
181 return; 180 return;
182 } 181 }
183 entry->title_handle = 0; 182 entry->title_handle = 0;
184 if (found_url && !row->title().empty()) { 183 if (found_url && !row->title().empty()) {
185 entry->title = UTF16ToWide(row->title()); 184 entry->title = row->title();
186 if (observer_) 185 if (observer_)
187 observer_->OnItemsChanged(static_cast<int>(entry_index), 1); 186 observer_->OnItemsChanged(static_cast<int>(entry_index), 1);
188 } 187 }
189 } 188 }
190 189
191 void CustomHomePagesTableModel::OnGotFavIcon( 190 void CustomHomePagesTableModel::OnGotFavIcon(
192 FaviconService::Handle handle, 191 FaviconService::Handle handle,
193 bool know_fav_icon, 192 bool know_fav_icon,
194 scoped_refptr<RefCountedMemory> image_data, 193 scoped_refptr<RefCountedMemory> image_data,
195 bool is_expired, 194 bool is_expired,
(...skipping 30 matching lines...) Expand all
226 int* index) { 225 int* index) {
227 for (size_t i = 0; i < entries_.size(); ++i) { 226 for (size_t i = 0; i < entries_.size(); ++i) {
228 if (entries_[i].*member == handle) { 227 if (entries_[i].*member == handle) {
229 *index = static_cast<int>(i); 228 *index = static_cast<int>(i);
230 return &entries_[i]; 229 return &entries_[i];
231 } 230 }
232 } 231 }
233 return NULL; 232 return NULL;
234 } 233 }
235 234
236 std::wstring CustomHomePagesTableModel::FormattedURL(int row) const { 235 string16 CustomHomePagesTableModel::FormattedURL(int row) const {
237 std::string languages = 236 std::string languages =
238 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages); 237 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages);
239 string16 url = net::FormatUrl(entries_[row].url, languages); 238 string16 url = net::FormatUrl(entries_[row].url, languages);
240 url = base::i18n::GetDisplayStringInLTRDirectionality(url); 239 url = base::i18n::GetDisplayStringInLTRDirectionality(url);
241 return UTF16ToWide(url); 240 return url;
242 } 241 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698