OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "ios/chrome/browser/tabs/tab_model_list.h" | 5 #import "ios/chrome/browser/tabs/tab_model_list.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/supports_user_data.h" | 9 #include "base/supports_user_data.h" |
10 #include "ios/chrome/browser/application_context.h" | |
11 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 10 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
12 #include "ios/chrome/browser/browser_state/chrome_browser_state_manager.h" | |
13 #import "ios/chrome/browser/tabs/tab_model.h" | 11 #import "ios/chrome/browser/tabs/tab_model.h" |
14 | 12 |
15 #if !defined(__has_feature) || !__has_feature(objc_arc) | 13 #if !defined(__has_feature) || !__has_feature(objc_arc) |
16 #error "This file requires ARC support." | 14 #error "This file requires ARC support." |
17 #endif | 15 #endif |
18 | 16 |
19 namespace { | 17 namespace { |
20 // Wrapper around a NSMutableArray<TabModel> allowing to bind it to a | 18 // Wrapper around a NSMutableArray<TabModel> allowing to bind it to a |
21 // base::SupportsUserData. Any base::SupportsUserData that owns this | 19 // base::SupportsUserData. Any base::SupportsUserData that owns this |
22 // wrapper will owns the reference to the TabModels. | 20 // wrapper will owns the reference to the TabModels. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 DCHECK([tab_models containsObject:tab_model]); | 78 DCHECK([tab_models containsObject:tab_model]); |
81 [tab_models removeObject:tab_model]; | 79 [tab_models removeObject:tab_model]; |
82 } | 80 } |
83 | 81 |
84 NSArray<TabModel*>* GetTabModelsForChromeBrowserState( | 82 NSArray<TabModel*>* GetTabModelsForChromeBrowserState( |
85 ios::ChromeBrowserState* browser_state) { | 83 ios::ChromeBrowserState* browser_state) { |
86 TabModelList* tab_model_list = | 84 TabModelList* tab_model_list = |
87 TabModelList::GetForBrowserState(browser_state, false); | 85 TabModelList::GetForBrowserState(browser_state, false); |
88 return tab_model_list ? [tab_model_list->tab_models() allObjects] : nil; | 86 return tab_model_list ? [tab_model_list->tab_models() allObjects] : nil; |
89 } | 87 } |
90 | |
91 TabModel* GetLastActiveTabModelForChromeBrowserState( | |
92 ios::ChromeBrowserState* browser_state) { | |
93 TabModelList* tab_model_list = | |
94 TabModelList::GetForBrowserState(browser_state, false); | |
95 if (!tab_model_list || [tab_model_list->tab_models() count] == 0u) | |
96 return nil; | |
97 | |
98 // There is currently no way to mark a TabModel as active. Assert that there | |
99 // is only one TabModel associated with |browser_state| until it is possible | |
100 // to mark a TabModel as active. | |
101 DCHECK_EQ([tab_model_list->tab_models() count], 1u); | |
102 return [tab_model_list->tab_models() anyObject]; | |
103 } | |
104 | |
105 bool IsOffTheRecordSessionActive() { | |
106 std::vector<ios::ChromeBrowserState*> browser_states = | |
107 GetApplicationContext() | |
108 ->GetChromeBrowserStateManager() | |
109 ->GetLoadedBrowserStates(); | |
110 | |
111 for (ios::ChromeBrowserState* browser_state : browser_states) { | |
112 DCHECK(!browser_state->IsOffTheRecord()); | |
113 if (!browser_state->HasOffTheRecordChromeBrowserState()) | |
114 continue; | |
115 | |
116 ios::ChromeBrowserState* otr_browser_state = | |
117 browser_state->GetOffTheRecordChromeBrowserState(); | |
118 | |
119 TabModelList* tab_model_list = | |
120 TabModelList::GetForBrowserState(otr_browser_state, false); | |
121 if (!tab_model_list) | |
122 continue; | |
123 | |
124 for (TabModel* tab_model in tab_model_list->tab_models()) { | |
125 if (![tab_model isEmpty]) | |
126 return true; | |
127 } | |
128 } | |
129 | |
130 return false; | |
131 } | |
OLD | NEW |