| 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/clean/chrome/browser/model/browser_list.h" | 5 #import "ios/clean/chrome/browser/model/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/clean/chrome/browser/model/browser_web_state_list_delegate.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) |
| 22 : browser_state_(browser_state) { | 23 : browser_state_(browser_state), |
| 24 delegate_(base::MakeUnique<BrowserWebStateListDelegate>()) { |
| 23 DCHECK(browser_state_); | 25 DCHECK(browser_state_); |
| 24 } | 26 } |
| 25 | 27 |
| 26 BrowserList::~BrowserList() = default; | 28 BrowserList::~BrowserList() = default; |
| 27 | 29 |
| 28 // static | 30 // static |
| 29 BrowserList* BrowserList::FromBrowserState( | 31 BrowserList* BrowserList::FromBrowserState( |
| 30 ios::ChromeBrowserState* browser_state) { | 32 ios::ChromeBrowserState* browser_state) { |
| 31 base::SupportsUserData::Data* data = | 33 base::SupportsUserData::Data* data = |
| 32 browser_state->GetUserData(&kBrowserListKey); | 34 browser_state->GetUserData(&kBrowserListKey); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 47 int BrowserList::ContainsIndex(int index) const { | 49 int BrowserList::ContainsIndex(int index) const { |
| 48 return 0 <= index && index < GetBrowserCount(); | 50 return 0 <= index && index < GetBrowserCount(); |
| 49 } | 51 } |
| 50 | 52 |
| 51 Browser* BrowserList::GetBrowserAtIndex(int index) const { | 53 Browser* BrowserList::GetBrowserAtIndex(int index) const { |
| 52 DCHECK(ContainsIndex(index)); | 54 DCHECK(ContainsIndex(index)); |
| 53 return browsers_[index].get(); | 55 return browsers_[index].get(); |
| 54 } | 56 } |
| 55 | 57 |
| 56 Browser* BrowserList::CreateNewBrowser() { | 58 Browser* BrowserList::CreateNewBrowser() { |
| 57 browsers_.push_back(base::MakeUnique<Browser>(browser_state_)); | 59 browsers_.push_back( |
| 60 base::MakeUnique<Browser>(browser_state_, delegate_.get())); |
| 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 } |
| OLD | NEW |