Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/intents/web_intent_picker_model.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/stl_util.h" | |
| 9 #include "chrome/browser/ui/intents/web_intent_picker_model_observer.h" | |
| 10 #include "ui/gfx/image/image.h" | |
| 11 | |
| 12 WebIntentPickerModel::WebIntentPickerModel() | |
| 13 : observer_(NULL), | |
| 14 inline_disposition_index_(std::string::npos) { | |
| 15 } | |
| 16 | |
| 17 WebIntentPickerModel::~WebIntentPickerModel() { | |
| 18 DestroyItems(); | |
| 19 } | |
| 20 | |
| 21 void WebIntentPickerModel::AddItem(const string16& title, | |
| 22 const GURL& url, | |
| 23 Disposition disposition) { | |
| 24 items_.push_back(new Item(title, url, disposition)); | |
| 25 if (observer_) | |
| 26 observer_->OnModelChanged(this); | |
| 27 } | |
| 28 | |
| 29 void WebIntentPickerModel::RemoveItemAt(size_t index) { | |
| 30 DCHECK(index < items_.size()); | |
| 31 std::vector<Item*>::iterator iter = items_.begin() + index; | |
| 32 delete *iter; | |
| 33 items_.erase(iter); | |
| 34 if (observer_) | |
| 35 observer_->OnModelChanged(this); | |
| 36 } | |
| 37 | |
| 38 void WebIntentPickerModel::Clear() { | |
| 39 DestroyItems(); | |
| 40 inline_disposition_index_ = std::string::npos; | |
| 41 if (observer_) | |
| 42 observer_->OnModelChanged(this); | |
| 43 } | |
| 44 | |
| 45 const WebIntentPickerModel::Item& WebIntentPickerModel::GetItemAt( | |
| 46 size_t index) const { | |
| 47 DCHECK(index < items_.size()); | |
| 48 return *items_[index]; | |
| 49 } | |
| 50 | |
| 51 size_t WebIntentPickerModel::GetItemCount() const { | |
| 52 return items_.size(); | |
| 53 } | |
| 54 | |
| 55 void WebIntentPickerModel::UpdateFaviconAt(size_t index, | |
| 56 const gfx::Image& image) { | |
| 57 DCHECK(index < items_.size()); | |
| 58 items_[index]->favicon.reset(new gfx::Image(image)); | |
| 59 if (observer_) | |
| 60 observer_->OnFaviconChanged(this, index); | |
| 61 } | |
| 62 | |
| 63 void WebIntentPickerModel::SetInlineDisposition(size_t index) { | |
| 64 DCHECK(index < items_.size()); | |
| 65 inline_disposition_index_ = index; | |
| 66 if (observer_) | |
| 67 observer_->OnInlineDisposition(this); | |
| 68 } | |
| 69 | |
| 70 bool WebIntentPickerModel::IsInlineDisposition() const { | |
| 71 return inline_disposition_index_ != std::string::npos; | |
| 72 } | |
| 73 | |
| 74 void WebIntentPickerModel::DestroyItems() { | |
| 75 STLDeleteElements(&items_); | |
| 76 items_.clear(); | |
|
groby-ooo-7-16
2012/01/25 22:03:13
Already invoked by STLDeleteElements
binji
2012/01/26 00:27:41
Done.
| |
| 77 } | |
| 78 | |
| 79 WebIntentPickerModel::Item::Item(const string16& title, | |
| 80 const GURL& url, | |
| 81 Disposition disposition) | |
| 82 : title(title), | |
| 83 url(url), | |
| 84 disposition(disposition) { | |
| 85 } | |
| 86 | |
| 87 WebIntentPickerModel::Item::~Item() { | |
| 88 } | |
| OLD | NEW |