Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / android / tab_model / tab_model_list.cc
blob79aa098cc5560b34279b57da2cfc85ac7401b274
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"
12 namespace {
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;
21 } // namespace
23 void TabModelList::AddTabModel(TabModel* tab_model) {
24 DCHECK(tab_model);
25 tab_models().push_back(tab_model);
28 void TabModelList::RemoveTabModel(TabModel* tab_model) {
29 DCHECK(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@.
41 DCHECK(tab);
42 tab->HandlePopupNavigation(params);
46 TabModel* TabModelList::GetTabModelWithProfile(
47 Profile* profile) {
48 if (!profile)
49 return NULL;
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()) {
56 return *i;
60 return NULL;
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)
68 return *i;
71 return NULL;
74 bool TabModelList::IsOffTheRecordSessionActive() {
75 for (TabModelList::const_iterator i = TabModelList::begin();
76 i != TabModelList::end(); i++) {
77 if ((*i)->IsOffTheRecord() && (*i)->GetTabCount() > 0)
78 return true;
81 return false;
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();