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.
5 #include "chrome/browser/ui/android/tab_model/tab_model_list.h"
7 #include "chrome/browser/android/tab_android.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/android/tab_model/tab_model.h"
10 #include "chrome/browser/ui/browser_navigator.h"
14 // Maintains and gives access to a static list of TabModel instances.
15 static TabModelList::TabModelVector
& tab_models() {
16 CR_DEFINE_STATIC_LOCAL(TabModelList::TabModelVector
,
17 tab_model_vector
, ());
18 return tab_model_vector
;
23 void TabModelList::AddTabModel(TabModel
* tab_model
) {
25 tab_models().push_back(tab_model
);
28 void TabModelList::RemoveTabModel(TabModel
* tab_model
) {
30 TabModelList::iterator remove_tab_model
=
31 std::find(tab_models().begin(), tab_models().end(), tab_model
);
33 if (remove_tab_model
!= tab_models().end())
34 tab_models().erase(remove_tab_model
);
37 void TabModelList::HandlePopupNavigation(chrome::NavigateParams
* params
) {
38 TabAndroid
* tab
= TabAndroid::FromWebContents(params
->source_contents
);
40 // NOTE: If this fails contact dtrainor@.
42 tab
->HandlePopupNavigation(params
);
46 TabModel
* TabModelList::GetTabModelWithProfile(
51 for (TabModelList::const_iterator i
= TabModelList::begin();
52 i
!= TabModelList::end(); ++i
) {
53 Profile
* model_profile
= (*i
)->GetProfile();
54 if (profile
->IsSameProfile(model_profile
) &&
55 profile
->IsOffTheRecord() == model_profile
->IsOffTheRecord()) {
63 TabModel
* TabModelList::FindTabModelWithId(
64 SessionID::id_type desired_id
) {
65 for (TabModelList::const_iterator i
= TabModelList::begin();
66 i
!= TabModelList::end(); i
++) {
67 if ((*i
)->GetSessionId() == desired_id
)
74 bool TabModelList::IsOffTheRecordSessionActive() {
75 for (TabModelList::const_iterator i
= TabModelList::begin();
76 i
!= TabModelList::end(); i
++) {
77 if ((*i
)->IsOffTheRecord() && (*i
)->GetTabCount() > 0)
84 TabModelList::const_iterator
TabModelList::begin() {
85 return tab_models().begin();
88 TabModelList::const_iterator
TabModelList::end() {
89 return tab_models().end();
92 bool TabModelList::empty() {
93 return tab_models().empty();
96 size_t TabModelList::size() {
97 return tab_models().size();