Index: ios/clean/chrome/browser/model/browser_list.mm |
diff --git a/ios/clean/chrome/browser/model/browser_list.mm b/ios/clean/chrome/browser/model/browser_list.mm |
new file mode 100644 |
index 0000000000000000000000000000000000000000..fc133b2eb2236577619cdfbead5848d203f84c44 |
--- /dev/null |
+++ b/ios/clean/chrome/browser/model/browser_list.mm |
@@ -0,0 +1,63 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#import "ios/clean/chrome/browser/model/browser_list.h" |
+ |
+#include <stdint.h> |
+ |
+#include "base/logging.h" |
+#include "base/memory/ptr_util.h" |
+#include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
+ |
+#if !defined(__has_feature) || !__has_feature(objc_arc) |
+#error "This file requires ARC support." |
+#endif |
+ |
+namespace { |
+const char kBrowserListKey = 0; |
+} |
+ |
+BrowserList::BrowserList(ios::ChromeBrowserState* browser_state) |
+ : browser_state_(browser_state) { |
+ DCHECK(browser_state_); |
+} |
+ |
+BrowserList::~BrowserList() = default; |
+ |
+// static |
+BrowserList* BrowserList::FromBrowserState( |
+ ios::ChromeBrowserState* browser_state) { |
+ base::SupportsUserData::Data* data = |
+ browser_state->GetUserData(&kBrowserListKey); |
+ if (!data) { |
+ browser_state->SetUserData(&kBrowserListKey, |
+ base::MakeUnique<BrowserList>(browser_state)); |
+ data = browser_state->GetUserData(&kBrowserListKey); |
+ } |
+ DCHECK(data); |
+ return static_cast<BrowserList*>(data); |
+} |
+ |
+int BrowserList::GetBrowserCount() const { |
+ DCHECK_LE(browsers_.size(), static_cast<size_t>(INT_MAX)); |
+ return static_cast<int>(browsers_.size()); |
+} |
+ |
+int BrowserList::ContainsIndex(int index) const { |
+ return 0 <= index && index < GetBrowserCount(); |
+} |
rohitrao (ping after 24h)
2017/03/04 01:29:49
Blank line after.
|
+Browser* BrowserList::GetBrowserAtIndex(int index) const { |
+ DCHECK(ContainsIndex(index)); |
+ return browsers_[index].get(); |
+} |
+ |
+Browser* BrowserList::CreateNewBrowser() { |
+ browsers_.push_back(base::MakeUnique<Browser>(browser_state_)); |
+ return browsers_.back().get(); |
+} |
+ |
+void BrowserList::CloseBrowserAtIndex(int index) { |
+ DCHECK(ContainsIndex(index)); |
+ browsers_.erase(browsers_.begin() + index); |
+} |