Home | History | Annotate | Download | only in tab_model
      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/android/tab_model/tab_model_list.h"
      6 
      7 #include "chrome/browser/profiles/profile.h"
      8 #include "chrome/browser/ui/android/tab_model/tab_model.h"
      9 
     10 namespace {
     11 
     12 // Maintains and gives access to a static list of TabModel instances.
     13 static TabModelList::TabModelVector& tab_models() {
     14   CR_DEFINE_STATIC_LOCAL(TabModelList::TabModelVector,
     15                          tab_model_vector, ());
     16   return tab_model_vector;
     17 }
     18 
     19 }  // namespace
     20 
     21 void TabModelList::AddTabModel(TabModel* tab_model) {
     22   DCHECK(tab_model);
     23   tab_models().push_back(tab_model);
     24 }
     25 
     26 void TabModelList::RemoveTabModel(TabModel* tab_model) {
     27   DCHECK(tab_model);
     28   TabModelList::iterator remove_tab_model =
     29       std::find(tab_models().begin(), tab_models().end(), tab_model);
     30 
     31   if (remove_tab_model != tab_models().end())
     32     tab_models().erase(remove_tab_model);
     33 }
     34 
     35 TabModel* TabModelList::GetTabModelWithProfile(
     36     Profile* profile) {
     37   if (!profile)
     38     return NULL;
     39 
     40   for (TabModelList::const_iterator i = TabModelList::begin();
     41       i != TabModelList::end(); ++i) {
     42     if (profile->IsSameProfile((*i)->GetProfile()))
     43       return *i;
     44   }
     45 
     46   return NULL;
     47 }
     48 
     49 TabModel* TabModelList::FindTabModelWithId(
     50     SessionID::id_type desired_id) {
     51   for (TabModelList::const_iterator i = TabModelList::begin();
     52       i != TabModelList::end(); i++) {
     53     if ((*i)->GetSessionId() == desired_id)
     54       return *i;
     55   }
     56 
     57   return NULL;
     58 }
     59 
     60 bool TabModelList::IsOffTheRecordSessionActive() {
     61   for (TabModelList::const_iterator i = TabModelList::begin();
     62       i != TabModelList::end(); i++) {
     63     if ((*i)->IsOffTheRecord() && (*i)->GetTabCount() > 0)
     64       return true;
     65   }
     66 
     67   return false;
     68 }
     69 
     70 TabModelList::const_iterator TabModelList::begin() {
     71   return tab_models().begin();
     72 }
     73 
     74 TabModelList::const_iterator TabModelList::end() {
     75   return tab_models().end();
     76 }
     77 
     78 bool TabModelList::empty() {
     79   return tab_models().empty();
     80 }
     81 
     82 size_t TabModelList::size() {
     83   return tab_models().size();
     84 }
     85