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

Side by Side Diff: chrome/browser/ui/intents/web_intent_picker_model.cc

Issue 10825352: Change picker model API to allow less notification messages (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/ui/intents/web_intent_picker_model.h" 5 #include "chrome/browser/ui/intents/web_intent_picker_model.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 } 83 }
84 84
85 void WebIntentPickerModel::UpdateFaviconAt(size_t index, 85 void WebIntentPickerModel::UpdateFaviconAt(size_t index,
86 const gfx::Image& image) { 86 const gfx::Image& image) {
87 DCHECK_LT(index, installed_services_.size()); 87 DCHECK_LT(index, installed_services_.size());
88 installed_services_[index]->favicon = image; 88 installed_services_[index]->favicon = image;
89 if (observer_) 89 if (observer_)
90 observer_->OnFaviconChanged(this, index); 90 observer_->OnFaviconChanged(this, index);
91 } 91 }
92 92
93 void WebIntentPickerModel::AddSuggestedExtension(const string16& title, 93 void WebIntentPickerModel::AddSuggestedExtensions(
94 const string16& id, 94 const std::vector<SuggestedExtension>& suggestions) {
95 double average_rating) { 95 suggested_extensions_.insert(suggested_extensions_.end(),
Greg Billock 2012/08/15 17:05:07 Should we call it "set" and just replace them?
96 suggested_extensions_.push_back( 96 suggestions.begin(),
97 new SuggestedExtension(title, id, average_rating)); 97 suggestions.end());
98 if (observer_) 98 if (observer_)
99 observer_->OnModelChanged(this); 99 observer_->OnModelChanged(this);
100 } 100 }
101
102 void WebIntentPickerModel::RemoveSuggestedExtensionAt(size_t index) {
103 DCHECK_LT(index, suggested_extensions_.size());
104 SuggestedExtension* extension = suggested_extensions_[index];
105 suggested_extensions_.erase(suggested_extensions_.begin() + index);
106 delete extension;
107 if (observer_)
108 observer_->OnModelChanged(this);
109 }
110 101
111 const WebIntentPickerModel::SuggestedExtension& 102 const WebIntentPickerModel::SuggestedExtension&
112 WebIntentPickerModel::GetSuggestedExtensionAt(size_t index) const { 103 WebIntentPickerModel::GetSuggestedExtensionAt(size_t index) const {
113 DCHECK_LT(index, suggested_extensions_.size()); 104 DCHECK_LT(index, suggested_extensions_.size());
114 return *suggested_extensions_[index]; 105 return suggested_extensions_[index];
115 } 106 }
116 107
117 size_t WebIntentPickerModel::GetSuggestedExtensionCount() const { 108 size_t WebIntentPickerModel::GetSuggestedExtensionCount() const {
118 return std::min(suggested_extensions_.size(), kMaxSuggestionCount); 109 return std::min(suggested_extensions_.size(), kMaxSuggestionCount);
119 } 110 }
120 111
121 string16 WebIntentPickerModel::GetSuggestionsLinkText() const { 112 string16 WebIntentPickerModel::GetSuggestionsLinkText() const {
122 if (suggested_extensions_.size() <= kMaxSuggestionCount) 113 if (suggested_extensions_.size() <= kMaxSuggestionCount)
123 return string16(); 114 return string16();
124 115
125 return l10n_util::GetStringUTF16(GetInstalledServiceCount() == 0 ? 116 return l10n_util::GetStringUTF16(GetInstalledServiceCount() == 0 ?
126 IDS_INTENT_PICKER_GET_MORE_SERVICES_NONE_INSTALLED : 117 IDS_INTENT_PICKER_GET_MORE_SERVICES_NONE_INSTALLED :
127 IDS_INTENT_PICKER_GET_MORE_SERVICES); 118 IDS_INTENT_PICKER_GET_MORE_SERVICES);
128 } 119 }
129 120
130 void WebIntentPickerModel::SetSuggestedExtensionIconWithId( 121 void WebIntentPickerModel::SetSuggestedExtensionIconWithId(
131 const string16& id, 122 const string16& id,
132 const gfx::Image& image) { 123 const gfx::Image& image) {
133 for (size_t i = 0; i < suggested_extensions_.size(); ++i) { 124 for (size_t i = 0; i < suggested_extensions_.size(); ++i) {
134 SuggestedExtension* extension = suggested_extensions_[i]; 125 SuggestedExtension& extension = suggested_extensions_[i];
135 if (extension->id == id) { 126 if (extension.id == id) {
136 extension->icon = image; 127 extension.icon = image;
137 128
138 if (observer_) 129 if (observer_)
139 observer_->OnExtensionIconChanged(this, extension->id); 130 observer_->OnExtensionIconChanged(this, extension.id);
140 break; 131 break;
141 } 132 }
142 } 133 }
143 } 134 }
144 135
145 void WebIntentPickerModel::SetInlineDisposition(const GURL& url) { 136 void WebIntentPickerModel::SetInlineDisposition(const GURL& url) {
146 inline_disposition_url_ = url; 137 inline_disposition_url_ = url;
147 if (observer_) { 138 if (observer_) {
148 const InstalledService* service = GetInstalledServiceWithURL(url); 139 const InstalledService* service = GetInstalledServiceWithURL(url);
149 DCHECK(service); 140 DCHECK(service);
150 observer_->OnInlineDisposition(service->title, url); 141 observer_->OnInlineDisposition(service->title, url);
151 } 142 }
152 } 143 }
153 144
154 bool WebIntentPickerModel::IsInlineDisposition() const { 145 bool WebIntentPickerModel::IsInlineDisposition() const {
155 return !inline_disposition_url_.is_empty(); 146 return !inline_disposition_url_.is_empty();
156 } 147 }
157 148
158 void WebIntentPickerModel::DestroyAll() { 149 void WebIntentPickerModel::DestroyAll() {
159 STLDeleteElements(&installed_services_); 150 STLDeleteElements(&installed_services_);
160 STLDeleteElements(&suggested_extensions_);
161 } 151 }
162 152
163 WebIntentPickerModel::InstalledService::InstalledService( 153 WebIntentPickerModel::InstalledService::InstalledService(
164 const string16& title, 154 const string16& title,
165 const GURL& url, 155 const GURL& url,
166 Disposition disposition) 156 Disposition disposition)
167 : title(title), 157 : title(title),
168 url(url), 158 url(url),
169 favicon(ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( 159 favicon(ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(
170 IDR_DEFAULT_FAVICON)), 160 IDR_DEFAULT_FAVICON)),
171 disposition(disposition) { 161 disposition(disposition) {
172 } 162 }
173 163
174 WebIntentPickerModel::InstalledService::~InstalledService() { 164 WebIntentPickerModel::InstalledService::~InstalledService() {
175 } 165 }
176 166
177 WebIntentPickerModel::SuggestedExtension::SuggestedExtension( 167 WebIntentPickerModel::SuggestedExtension::SuggestedExtension(
178 const string16& title, 168 const string16& title,
179 const string16& id, 169 const string16& id,
180 double average_rating) 170 double average_rating)
181 : title(title), 171 : title(title),
182 id(id), 172 id(id),
183 average_rating(average_rating), 173 average_rating(average_rating),
184 icon(ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( 174 icon(ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(
185 IDR_DEFAULT_FAVICON)) { 175 IDR_DEFAULT_FAVICON)) {
186 } 176 }
187 177
188 WebIntentPickerModel::SuggestedExtension::~SuggestedExtension() { 178 WebIntentPickerModel::SuggestedExtension::~SuggestedExtension() {
189 } 179 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/intents/web_intent_picker_model.h ('k') | chrome/browser/ui/intents/web_intent_picker_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698