| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "ios/chrome/browser/tabs/tab_model_synced_window_delegate_getter.h" | 5 #include "ios/chrome/browser/tabs/tab_model_synced_window_delegate_getter.h" |
| 6 | 6 |
| 7 #include "base/logging.h" |
| 8 #include "ios/chrome/browser/application_context.h" |
| 7 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 9 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 8 #include "ios/chrome/browser/tabs/tab_model.h" | 10 #include "ios/chrome/browser/browser_state/chrome_browser_state_manager.h" |
| 11 #import "ios/chrome/browser/tabs/tab_model.h" |
| 12 #import "ios/chrome/browser/tabs/tab_model_list.h" |
| 9 #import "ios/chrome/browser/tabs/tab_model_synced_window_delegate.h" | 13 #import "ios/chrome/browser/tabs/tab_model_synced_window_delegate.h" |
| 10 #import "ios/chrome/browser/ui/browser_list_ios.h" | |
| 11 | 14 |
| 12 TabModelSyncedWindowDelegatesGetter::TabModelSyncedWindowDelegatesGetter( | 15 TabModelSyncedWindowDelegatesGetter::TabModelSyncedWindowDelegatesGetter() {} |
| 13 ios::ChromeBrowserState* browser_state) | |
| 14 : browser_state_(browser_state) {} | |
| 15 | 16 |
| 16 TabModelSyncedWindowDelegatesGetter::~TabModelSyncedWindowDelegatesGetter() {} | 17 TabModelSyncedWindowDelegatesGetter::~TabModelSyncedWindowDelegatesGetter() {} |
| 17 | 18 |
| 18 std::set<const sync_sessions::SyncedWindowDelegate*> | 19 std::set<const sync_sessions::SyncedWindowDelegate*> |
| 19 TabModelSyncedWindowDelegatesGetter::GetSyncedWindowDelegates() { | 20 TabModelSyncedWindowDelegatesGetter::GetSyncedWindowDelegates() { |
| 20 std::set<const sync_sessions::SyncedWindowDelegate*> synced_window_delegates; | 21 std::set<const sync_sessions::SyncedWindowDelegate*> synced_window_delegates; |
| 21 | 22 |
| 22 for (BrowserListIOS::const_iterator iter = BrowserListIOS::begin(); | 23 std::vector<ios::ChromeBrowserState*> browser_states = |
| 23 iter != BrowserListIOS::end(); ++iter) { | 24 GetApplicationContext() |
| 24 id<BrowserIOS> browser = *iter; | 25 ->GetChromeBrowserStateManager() |
| 25 TabModel* tabModel = [browser tabModel]; | 26 ->GetLoadedBrowserStates(); |
| 26 // TODO(crbug.com/548612): BrowserState may be unnecessary as iOS does not | 27 |
| 27 // support multiple profiles starting with M47. There should still be a way | 28 for (auto* browser_state : browser_states) { |
| 28 // to filter out Incognito delegates, though. | 29 DCHECK(!browser_state->IsOffTheRecord()); |
| 29 if (tabModel.browserState != browser_state_) | 30 NSArray<TabModel*>* tabModels = |
| 30 continue; | 31 GetTabModelsForChromeBrowserState(browser_state); |
| 31 // Do not return windows without any tabs, to match desktop. | 32 for (TabModel* tabModel in tabModels) { |
| 32 if ([tabModel currentTab]) | 33 if (tabModel.currentTab) { |
| 33 synced_window_delegates.insert([tabModel syncedWindowDelegate]); | 34 synced_window_delegates.insert([tabModel syncedWindowDelegate]); |
| 35 } |
| 36 } |
| 34 } | 37 } |
| 35 | 38 |
| 36 return synced_window_delegates; | 39 return synced_window_delegates; |
| 37 } | 40 } |
| 38 | 41 |
| 39 const sync_sessions::SyncedWindowDelegate* | 42 const sync_sessions::SyncedWindowDelegate* |
| 40 TabModelSyncedWindowDelegatesGetter::FindById(SessionID::id_type session_id) { | 43 TabModelSyncedWindowDelegatesGetter::FindById(SessionID::id_type session_id) { |
| 41 for (const sync_sessions::SyncedWindowDelegate* delegate : | 44 for (const auto* delegate : GetSyncedWindowDelegates()) { |
| 42 GetSyncedWindowDelegates()) { | |
| 43 if (session_id == delegate->GetSessionId()) | 45 if (session_id == delegate->GetSessionId()) |
| 44 return delegate; | 46 return delegate; |
| 45 } | 47 } |
| 46 return nullptr; | 48 return nullptr; |
| 47 } | 49 } |
| OLD | NEW |