| 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/shared/chrome/browser/ui/browser_list/browser_list.h" | 5 #import "ios/shared/chrome/browser/ui/browser_list/browser_list.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 browser_state->GetUserData(&kBrowserListKey); | 32 browser_state->GetUserData(&kBrowserListKey); |
| 33 if (!data) { | 33 if (!data) { |
| 34 browser_state->SetUserData(&kBrowserListKey, | 34 browser_state->SetUserData(&kBrowserListKey, |
| 35 base::MakeUnique<BrowserList>(browser_state)); | 35 base::MakeUnique<BrowserList>(browser_state)); |
| 36 data = browser_state->GetUserData(&kBrowserListKey); | 36 data = browser_state->GetUserData(&kBrowserListKey); |
| 37 } | 37 } |
| 38 DCHECK(data); | 38 DCHECK(data); |
| 39 return static_cast<BrowserList*>(data); | 39 return static_cast<BrowserList*>(data); |
| 40 } | 40 } |
| 41 | 41 |
| 42 int BrowserList::GetBrowserCount() const { | 42 int BrowserList::ContainsIndex(int index) const { |
| 43 DCHECK_LE(browsers_.size(), static_cast<size_t>(INT_MAX)); | 43 return 0 <= index && index < count(); |
| 44 return static_cast<int>(browsers_.size()); | |
| 45 } | 44 } |
| 46 | 45 |
| 47 int BrowserList::ContainsIndex(int index) const { | 46 Browser* BrowserList::GetBrowserAt(int index) const { |
| 48 return 0 <= index && index < GetBrowserCount(); | 47 DCHECK(ContainsIndex(index)); |
| 48 return browsers_[index].get(); |
| 49 } | 49 } |
| 50 | 50 |
| 51 Browser* BrowserList::GetBrowserAtIndex(int index) const { | 51 int BrowserList::GetIndexOfBrowser(const Browser* browser) const { |
| 52 DCHECK(ContainsIndex(index)); | 52 for (int index = 0; index < count(); ++index) { |
| 53 return browsers_[index].get(); | 53 if (browsers_[index].get() == browser) |
| 54 return index; |
| 55 } |
| 56 return kInvalidIndex; |
| 54 } | 57 } |
| 55 | 58 |
| 56 Browser* BrowserList::CreateNewBrowser() { | 59 Browser* BrowserList::CreateNewBrowser() { |
| 57 browsers_.push_back(base::MakeUnique<Browser>(browser_state_)); | 60 browsers_.push_back(base::MakeUnique<Browser>(browser_state_)); |
| 58 return browsers_.back().get(); | 61 return browsers_.back().get(); |
| 59 } | 62 } |
| 60 | 63 |
| 61 void BrowserList::CloseBrowserAtIndex(int index) { | 64 void BrowserList::CloseBrowserAtIndex(int index) { |
| 62 DCHECK(ContainsIndex(index)); | 65 DCHECK(ContainsIndex(index)); |
| 63 browsers_.erase(browsers_.begin() + index); | 66 browsers_.erase(browsers_.begin() + index); |
| 64 } | 67 } |
| 68 |
| 69 const int BrowserList::kInvalidIndex; |
| OLD | NEW |