| 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" | 7 #include "base/logging.h" |
| 8 #include "ios/chrome/browser/application_context.h" | 8 #include "ios/chrome/browser/application_context.h" |
| 9 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 9 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 10 #include "ios/chrome/browser/browser_state/chrome_browser_state_manager.h" | 10 #include "ios/chrome/browser/browser_state/chrome_browser_state_manager.h" |
| 11 #import "ios/chrome/browser/tabs/tab_model.h" | 11 #import "ios/chrome/browser/tabs/tab_model.h" |
| 12 #import "ios/chrome/browser/tabs/tab_model_list.h" | 12 #import "ios/chrome/browser/tabs/tab_model_list.h" |
| 13 #import "ios/chrome/browser/tabs/tab_model_synced_window_delegate.h" | 13 #import "ios/chrome/browser/tabs/tab_model_synced_window_delegate.h" |
| 14 | 14 |
| 15 TabModelSyncedWindowDelegatesGetter::TabModelSyncedWindowDelegatesGetter() {} | 15 TabModelSyncedWindowDelegatesGetter::TabModelSyncedWindowDelegatesGetter() {} |
| 16 | 16 |
| 17 TabModelSyncedWindowDelegatesGetter::~TabModelSyncedWindowDelegatesGetter() {} | 17 TabModelSyncedWindowDelegatesGetter::~TabModelSyncedWindowDelegatesGetter() {} |
| 18 | 18 |
| 19 std::set<const sync_sessions::SyncedWindowDelegate*> | 19 std::set<const sync_sessions::SyncedWindowDelegate*> |
| 20 TabModelSyncedWindowDelegatesGetter::GetSyncedWindowDelegates() { | 20 TabModelSyncedWindowDelegatesGetter::GetSyncedWindowDelegates() { |
| 21 std::set<const sync_sessions::SyncedWindowDelegate*> synced_window_delegates; | 21 SyncedWindowDelegateMap synced_window_delegates; |
| 22 | 22 |
| 23 std::vector<ios::ChromeBrowserState*> browser_states = | 23 std::vector<ios::ChromeBrowserState*> browser_states = |
| 24 GetApplicationContext() | 24 GetApplicationContext() |
| 25 ->GetChromeBrowserStateManager() | 25 ->GetChromeBrowserStateManager() |
| 26 ->GetLoadedBrowserStates(); | 26 ->GetLoadedBrowserStates(); |
| 27 | 27 |
| 28 for (auto* browser_state : browser_states) { | 28 for (auto* browser_state : browser_states) { |
| 29 DCHECK(!browser_state->IsOffTheRecord()); | 29 DCHECK(!browser_state->IsOffTheRecord()); |
| 30 NSArray<TabModel*>* tabModels = | 30 NSArray<TabModel*>* tabModels = |
| 31 GetTabModelsForChromeBrowserState(browser_state); | 31 GetTabModelsForChromeBrowserState(browser_state); |
| 32 for (TabModel* tabModel in tabModels) { | 32 for (TabModel* tabModel in tabModels) { |
| 33 if (tabModel.currentTab) { | 33 if (tabModel.currentTab) { |
| 34 synced_window_delegates.insert([tabModel syncedWindowDelegate]); | 34 synced_window_delegates[tabModel->GetSessionId()] = |
| 35 [tabModel syncedWindowDelegate]; |
| 35 } | 36 } |
| 36 } | 37 } |
| 37 } | 38 } |
| 38 | 39 |
| 39 return synced_window_delegates; | 40 return synced_window_delegates; |
| 40 } | 41 } |
| 41 | 42 |
| 42 const sync_sessions::SyncedWindowDelegate* | 43 const sync_sessions::SyncedWindowDelegate* |
| 43 TabModelSyncedWindowDelegatesGetter::FindById(SessionID::id_type session_id) { | 44 TabModelSyncedWindowDelegatesGetter::FindById(SessionID::id_type session_id) { |
| 44 for (const auto* delegate : GetSyncedWindowDelegates()) { | 45 for (const auto* delegate : GetSyncedWindowDelegates()) { |
| 45 if (session_id == delegate->GetSessionId()) | 46 if (session_id == delegate->GetSessionId()) |
| 46 return delegate; | 47 return delegate; |
| 47 } | 48 } |
| 48 return nullptr; | 49 return nullptr; |
| 49 } | 50 } |
| OLD | NEW |