| 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/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" |
| 11 #include "chrome/browser/ui/intents/web_intent_picker_model_observer.h" | 11 #include "chrome/browser/ui/intents/web_intent_picker_model_observer.h" |
| 12 #include "grit/generated_resources.h" | 12 #include "grit/generated_resources.h" |
| 13 #include "grit/ui_resources.h" | 13 #include "grit/ui_resources.h" |
| 14 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
| 15 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
| 16 #include "ui/gfx/image/image.h" | 16 #include "ui/gfx/image/image.h" |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 const size_t kMaxSuggestionCount = 5; // Maximum number of visible suggestions. | 20 const size_t kMaxSuggestionCount = 5; // Maximum number of visible suggestions. |
| 21 | 21 |
| 22 } // namespace | 22 } // namespace |
| 23 | 23 |
| 24 WebIntentPickerModel::WebIntentPickerModel() | 24 WebIntentPickerModel::WebIntentPickerModel() |
| 25 : observer_(NULL), | 25 : observer_(NULL), |
| 26 waiting_for_suggestions_(true), | 26 waiting_for_suggestions_(true), |
| 27 default_service_hash_(0), | 27 default_service_hash_(0), |
| 28 pending_install_download_percent_(0) { | 28 pending_install_download_percent_(0), |
| 29 pending_install_prompt_(NULL) { |
| 29 } | 30 } |
| 30 | 31 |
| 31 WebIntentPickerModel::~WebIntentPickerModel() { | 32 WebIntentPickerModel::~WebIntentPickerModel() { |
| 32 DestroyAll(); | 33 DestroyAll(); |
| 33 } | 34 } |
| 34 | 35 |
| 35 void WebIntentPickerModel::AddInstalledService( | 36 void WebIntentPickerModel::AddInstalledService( |
| 36 const string16& title, | 37 const string16& title, |
| 37 const GURL& url, | 38 const GURL& url, |
| 38 webkit_glue::WebIntentServiceData::Disposition disposition) { | 39 webkit_glue::WebIntentServiceData::Disposition disposition) { |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 observer_->OnModelChanged(this); | 191 observer_->OnModelChanged(this); |
| 191 } | 192 } |
| 192 | 193 |
| 193 void WebIntentPickerModel::SetPendingInstallStatusString( | 194 void WebIntentPickerModel::SetPendingInstallStatusString( |
| 194 const string16& status) { | 195 const string16& status) { |
| 195 pending_install_status_string_ = status; | 196 pending_install_status_string_ = status; |
| 196 if (observer_) | 197 if (observer_) |
| 197 observer_->OnModelChanged(this); | 198 observer_->OnModelChanged(this); |
| 198 } | 199 } |
| 199 | 200 |
| 201 void WebIntentPickerModel::SetPendingInstallDelegate( |
| 202 ExtensionInstallPrompt::Delegate* delegate) { |
| 203 pending_install_delegate_ = delegate; |
| 204 if (observer_) |
| 205 observer_->OnModelChanged(this); |
| 206 } |
| 207 |
| 208 void WebIntentPickerModel::SetPendingInstallPrompt( |
| 209 const ExtensionInstallPrompt::Prompt& prompt) { |
| 210 pending_install_prompt_.reset(new ExtensionInstallPrompt::Prompt(prompt)); |
| 211 if (observer_) |
| 212 observer_->OnModelChanged(this); |
| 213 } |
| 214 |
| 200 void WebIntentPickerModel::ClearPendingInstall() { | 215 void WebIntentPickerModel::ClearPendingInstall() { |
| 201 pending_install_extension_id_.clear(); | 216 pending_install_extension_id_.clear(); |
| 202 pending_install_download_percent_ = 0; | 217 pending_install_download_percent_ = 0; |
| 203 pending_install_status_string_.clear(); | 218 pending_install_status_string_.clear(); |
| 219 pending_install_delegate_ = NULL; |
| 220 pending_install_prompt_.reset(); |
| 204 if (observer_) | 221 if (observer_) |
| 205 observer_->OnModelChanged(this); | 222 observer_->OnModelChanged(this); |
| 206 } | 223 } |
| 207 | 224 |
| 208 void WebIntentPickerModel::DestroyAll() { | 225 void WebIntentPickerModel::DestroyAll() { |
| 209 STLDeleteElements(&installed_services_); | 226 STLDeleteElements(&installed_services_); |
| 210 } | 227 } |
| 211 | 228 |
| 212 WebIntentPickerModel::InstalledService::InstalledService( | 229 WebIntentPickerModel::InstalledService::InstalledService( |
| 213 const string16& title, | 230 const string16& title, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 229 double average_rating) | 246 double average_rating) |
| 230 : title(title), | 247 : title(title), |
| 231 id(id), | 248 id(id), |
| 232 average_rating(average_rating), | 249 average_rating(average_rating), |
| 233 icon(ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( | 250 icon(ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( |
| 234 IDR_DEFAULT_FAVICON)) { | 251 IDR_DEFAULT_FAVICON)) { |
| 235 } | 252 } |
| 236 | 253 |
| 237 WebIntentPickerModel::SuggestedExtension::~SuggestedExtension() { | 254 WebIntentPickerModel::SuggestedExtension::~SuggestedExtension() { |
| 238 } | 255 } |
| OLD | NEW |