Home | History | Annotate | Download | only in app_list
      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 "ui/app_list/search_box_model.h"
      6 
      7 #include "base/metrics/histogram.h"
      8 #include "ui/app_list/search_box_model_observer.h"
      9 
     10 namespace app_list {
     11 
     12 SearchBoxModel::SearchBoxModel() {
     13 }
     14 
     15 SearchBoxModel::~SearchBoxModel() {
     16 }
     17 
     18 void SearchBoxModel::SetIcon(const gfx::ImageSkia& icon) {
     19   icon_ = icon;
     20   FOR_EACH_OBSERVER(SearchBoxModelObserver, observers_, IconChanged());
     21 }
     22 
     23 void SearchBoxModel::SetHintText(const base::string16& hint_text) {
     24   if (hint_text_ == hint_text)
     25     return;
     26 
     27   hint_text_ = hint_text;
     28   FOR_EACH_OBSERVER(SearchBoxModelObserver, observers_, HintTextChanged());
     29 }
     30 
     31 void SearchBoxModel::SetSelectionModel(const gfx::SelectionModel& sel) {
     32   if (selection_model_ == sel)
     33     return;
     34 
     35   selection_model_ = sel;
     36   FOR_EACH_OBSERVER(SearchBoxModelObserver,
     37                     observers_,
     38                     SelectionModelChanged());
     39 }
     40 
     41 void SearchBoxModel::SetText(const base::string16& text) {
     42   if (text_ == text)
     43     return;
     44 
     45   // Log that a new search has been commenced whenever the text box text
     46   // transitions from empty to non-empty.
     47   if (text_.empty() && !text.empty()) {
     48     UMA_HISTOGRAM_ENUMERATION("Apps.AppListSearchCommenced", 1, 2);
     49   }
     50   text_ = text;
     51   FOR_EACH_OBSERVER(SearchBoxModelObserver, observers_, TextChanged());
     52 }
     53 
     54 void SearchBoxModel::AddObserver(SearchBoxModelObserver* observer) {
     55   observers_.AddObserver(observer);
     56 }
     57 
     58 void SearchBoxModel::RemoveObserver(SearchBoxModelObserver* observer) {
     59   observers_.RemoveObserver(observer);
     60 }
     61 
     62 }  // namespace app_list
     63