Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(588)

Side by Side Diff: ios/chrome/browser/tabs/tab_model_list.mm

Issue 2615003002: Use ChromeBrowserStateManager instead of BrowserListIOS. (Closed)
Patch Set: Fix ios_chrome_perftests. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
10 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" 11 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
12 #include "ios/chrome/browser/browser_state/chrome_browser_state_manager.h"
11 #import "ios/chrome/browser/tabs/tab_model.h" 13 #import "ios/chrome/browser/tabs/tab_model.h"
12 14
13 #if !defined(__has_feature) || !__has_feature(objc_arc) 15 #if !defined(__has_feature) || !__has_feature(objc_arc)
14 #error "This file requires ARC support." 16 #error "This file requires ARC support."
15 #endif 17 #endif
16 18
17 namespace { 19 namespace {
18 // Wrapper around a NSMutableArray<TabModel> allowing to bind it to a 20 // Wrapper around a NSMutableArray<TabModel> allowing to bind it to a
19 // base::SupportsUserData. Any base::SupportsUserData that owns this 21 // base::SupportsUserData. Any base::SupportsUserData that owns this
20 // wrapper will owns the reference to the TabModels. 22 // wrapper will owns the reference to the TabModels.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 DCHECK([tab_models containsObject:tab_model]); 80 DCHECK([tab_models containsObject:tab_model]);
79 [tab_models removeObject:tab_model]; 81 [tab_models removeObject:tab_model];
80 } 82 }
81 83
82 NSArray<TabModel*>* GetTabModelsForChromeBrowserState( 84 NSArray<TabModel*>* GetTabModelsForChromeBrowserState(
83 ios::ChromeBrowserState* browser_state) { 85 ios::ChromeBrowserState* browser_state) {
84 TabModelList* tab_model_list = 86 TabModelList* tab_model_list =
85 TabModelList::GetForBrowserState(browser_state, false); 87 TabModelList::GetForBrowserState(browser_state, false);
86 return tab_model_list ? [tab_model_list->tab_models() allObjects] : nil; 88 return tab_model_list ? [tab_model_list->tab_models() allObjects] : nil;
87 } 89 }
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 }
OLDNEW
« no previous file with comments | « ios/chrome/browser/tabs/tab_model_list.h ('k') | ios/chrome/browser/tabs/tab_model_synced_window_delegate.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698