OLD | NEW |
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/ui/search_engines/template_url_table_model.h" | 5 #include "chrome/browser/ui/search_engines/template_url_table_model.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/i18n/rtl.h" | 8 #include "base/i18n/rtl.h" |
9 #include "base/task/cancelable_task_tracker.h" | 9 #include "base/task/cancelable_task_tracker.h" |
10 #include "chrome/browser/favicon/favicon_service.h" | 10 #include "chrome/browser/favicon/favicon_service.h" |
11 #include "components/favicon_base/favicon_types.h" | 11 #include "components/favicon_base/favicon_types.h" |
12 #include "components/search_engines/template_url.h" | 12 #include "components/search_engines/template_url.h" |
13 #include "components/search_engines/template_url_service.h" | 13 #include "components/search_engines/template_url_service.h" |
14 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
15 #include "grit/ui_resources.h" | 15 #include "grit/ui_resources.h" |
16 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
17 #include "ui/base/models/table_model_observer.h" | 17 #include "ui/base/models/table_model_observer.h" |
18 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
19 #include "ui/gfx/favicon_size.h" | |
20 #include "ui/gfx/image/image_skia.h" | 19 #include "ui/gfx/image/image_skia.h" |
21 | 20 |
22 // Group IDs used by TemplateURLTableModel. | 21 // Group IDs used by TemplateURLTableModel. |
23 static const int kMainGroupID = 0; | 22 static const int kMainGroupID = 0; |
24 static const int kOtherGroupID = 1; | 23 static const int kOtherGroupID = 1; |
25 static const int kExtensionGroupID = 2; | 24 static const int kExtensionGroupID = 2; |
26 | 25 |
27 // ModelEntry ---------------------------------------------------- | 26 // ModelEntry ---------------------------------------------------- |
28 | 27 |
29 // ModelEntry wraps a TemplateURL as returned from the TemplateURL. | 28 // ModelEntry wraps a TemplateURL as returned from the TemplateURL. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 GURL url(template_url_->url()); | 82 GURL url(template_url_->url()); |
84 if (url.is_valid()) | 83 if (url.is_valid()) |
85 favicon_url = TemplateURL::GenerateFaviconURL(url); | 84 favicon_url = TemplateURL::GenerateFaviconURL(url); |
86 } | 85 } |
87 if (!favicon_url.is_valid()) | 86 if (!favicon_url.is_valid()) |
88 return; | 87 return; |
89 } | 88 } |
90 load_state_ = LOADING; | 89 load_state_ = LOADING; |
91 model_->favicon_service_->GetFaviconImage( | 90 model_->favicon_service_->GetFaviconImage( |
92 favicon_url, | 91 favicon_url, |
93 favicon_base::FAVICON, | |
94 gfx::kFaviconSize, | |
95 base::Bind(&ModelEntry::OnFaviconDataAvailable, base::Unretained(this)), | 92 base::Bind(&ModelEntry::OnFaviconDataAvailable, base::Unretained(this)), |
96 &tracker_); | 93 &tracker_); |
97 } | 94 } |
98 | 95 |
99 void OnFaviconDataAvailable( | 96 void OnFaviconDataAvailable( |
100 const favicon_base::FaviconImageResult& image_result) { | 97 const favicon_base::FaviconImageResult& image_result) { |
101 load_state_ = LOADED; | 98 load_state_ = LOADED; |
102 if (!image_result.image.IsEmpty()) { | 99 if (!image_result.image.IsEmpty()) { |
103 favicon_ = image_result.image.AsImageSkia(); | 100 favicon_ = image_result.image.AsImageSkia(); |
104 model_->FaviconAvailable(this); | 101 model_->FaviconAvailable(this); |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 return entry.Pass(); | 385 return entry.Pass(); |
389 } | 386 } |
390 | 387 |
391 void TemplateURLTableModel::AddEntry(int index, scoped_ptr<ModelEntry> entry) { | 388 void TemplateURLTableModel::AddEntry(int index, scoped_ptr<ModelEntry> entry) { |
392 entries_.insert(entries_.begin() + index, entry.release()); | 389 entries_.insert(entries_.begin() + index, entry.release()); |
393 if (index <= last_other_engine_index_) | 390 if (index <= last_other_engine_index_) |
394 ++last_other_engine_index_; | 391 ++last_other_engine_index_; |
395 if (observer_) | 392 if (observer_) |
396 observer_->OnItemsAdded(index, 1); | 393 observer_->OnItemsAdded(index, 1); |
397 } | 394 } |
OLD | NEW |