Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(638)

Unified Diff: ios/clean/chrome/browser/model/browser_list.mm

Issue 2727353006: Introduce BrowserList and Browser classes for iOS. (Closed)
Patch Set: Add blank line. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..5a2e57066efdcaddad8cb84e8b61e727e4a0ac07
--- /dev/null
+++ b/ios/clean/chrome/browser/model/browser_list.mm
@@ -0,0 +1,64 @@
+// 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();
+}
+
+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);
+}
« no previous file with comments | « ios/clean/chrome/browser/model/browser_list.h ('k') | ios/clean/chrome/browser/model/browser_list_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698