| 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" |
| 11 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 11 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 12 #import "ios/shared/chrome/browser/ui/browser_list/browser_list_observer.h" |
| 12 | 13 |
| 13 #if !defined(__has_feature) || !__has_feature(objc_arc) | 14 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 14 #error "This file requires ARC support." | 15 #error "This file requires ARC support." |
| 15 #endif | 16 #endif |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 const char kBrowserListKey = 0; | 19 const char kBrowserListKey = 0; |
| 19 } | 20 } |
| 20 | 21 |
| 21 BrowserList::BrowserList(ios::ChromeBrowserState* browser_state) | 22 BrowserList::BrowserList(ios::ChromeBrowserState* browser_state) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 51 int BrowserList::GetIndexOfBrowser(const Browser* browser) const { | 52 int BrowserList::GetIndexOfBrowser(const Browser* browser) const { |
| 52 for (int index = 0; index < count(); ++index) { | 53 for (int index = 0; index < count(); ++index) { |
| 53 if (browsers_[index].get() == browser) | 54 if (browsers_[index].get() == browser) |
| 54 return index; | 55 return index; |
| 55 } | 56 } |
| 56 return kInvalidIndex; | 57 return kInvalidIndex; |
| 57 } | 58 } |
| 58 | 59 |
| 59 Browser* BrowserList::CreateNewBrowser() { | 60 Browser* BrowserList::CreateNewBrowser() { |
| 60 browsers_.push_back(base::MakeUnique<Browser>(browser_state_)); | 61 browsers_.push_back(base::MakeUnique<Browser>(browser_state_)); |
| 61 return browsers_.back().get(); | 62 Browser* browser_created = browsers_.back().get(); |
| 63 for (BrowserListObserver& observer : observers_) |
| 64 observer.OnBrowserCreated(this, browser_created); |
| 65 return browser_created; |
| 62 } | 66 } |
| 63 | 67 |
| 64 void BrowserList::CloseBrowserAtIndex(int index) { | 68 void BrowserList::CloseBrowserAtIndex(int index) { |
| 65 DCHECK(ContainsIndex(index)); | 69 Browser* browser_removed = GetBrowserAtIndex(index); |
| 70 for (BrowserListObserver& observer : observers_) |
| 71 observer.OnBrowserRemoved(this, browser_removed); |
| 66 browsers_.erase(browsers_.begin() + index); | 72 browsers_.erase(browsers_.begin() + index); |
| 67 } | 73 } |
| 68 | 74 |
| 75 void BrowserList::AddObserver(BrowserListObserver* observer) { |
| 76 observers_.AddObserver(observer); |
| 77 } |
| 78 |
| 79 void BrowserList::RemoveObserver(BrowserListObserver* observer) { |
| 80 observers_.RemoveObserver(observer); |
| 81 } |
| 82 |
| 69 const int BrowserList::kInvalidIndex; | 83 const int BrowserList::kInvalidIndex; |
| OLD | NEW |