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

Side by Side Diff: ios/clean/chrome/browser/model/browser_list.mm

Issue 2727353006: Introduce BrowserList and Browser classes for iOS. (Closed)
Patch Set: Created 3 years, 9 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "ios/clean/chrome/browser/model/browser_list.h"
6
7 #include <stdint.h>
8
9 #include "base/logging.h"
10 #include "base/memory/ptr_util.h"
11 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
12
13 #if !defined(__has_feature) || !__has_feature(objc_arc)
14 #error "This file requires ARC support."
15 #endif
16
17 namespace {
18 const char kBrowserListKey = 0;
19 }
20
21 BrowserList::BrowserList(ios::ChromeBrowserState* browser_state)
22 : browser_state_(browser_state) {
23 DCHECK(browser_state_);
24 }
25
26 BrowserList::~BrowserList() = default;
27
28 // static
29 BrowserList* BrowserList::FromBrowserState(
30 ios::ChromeBrowserState* browser_state) {
31 base::SupportsUserData::Data* data =
32 browser_state->GetUserData(&kBrowserListKey);
33 if (!data) {
34 browser_state->SetUserData(&kBrowserListKey,
35 base::MakeUnique<BrowserList>(browser_state));
36 data = browser_state->GetUserData(&kBrowserListKey);
37 }
38 DCHECK(data);
39 return static_cast<BrowserList*>(data);
40 }
41
42 int BrowserList::GetBrowserCount() const {
43 DCHECK_LE(browsers_.size(), static_cast<size_t>(INT_MAX));
44 return static_cast<int>(browsers_.size());
45 }
46
47 int BrowserList::ContainsIndex(int index) const {
48 return 0 <= index && index < GetBrowserCount();
49 }
rohitrao (ping after 24h) 2017/03/04 01:29:49 Blank line after.
50 Browser* BrowserList::GetBrowserAtIndex(int index) const {
51 DCHECK(ContainsIndex(index));
52 return browsers_[index].get();
53 }
54
55 Browser* BrowserList::CreateNewBrowser() {
56 browsers_.push_back(base::MakeUnique<Browser>(browser_state_));
57 return browsers_.back().get();
58 }
59
60 void BrowserList::CloseBrowserAtIndex(int index) {
61 DCHECK(ContainsIndex(index));
62 browsers_.erase(browsers_.begin() + index);
63 }
OLDNEW
« 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