OLD | NEW |
(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/chrome/browser/snapshots/snapshot_cache_web_state_list_observer.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #import "ios/chrome/browser/snapshots/snapshot_cache.h" |
| 9 #import "ios/chrome/browser/tabs/legacy_tab_helper.h" |
| 10 #import "ios/chrome/browser/tabs/tab.h" |
| 11 #import "ios/shared/chrome/browser/tabs/web_state_list.h" |
| 12 |
| 13 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 14 #error "This file requires ARC support." |
| 15 #endif |
| 16 |
| 17 SnapshotCacheWebStateListObserver::SnapshotCacheWebStateListObserver( |
| 18 SnapshotCache* snapshot_cache) |
| 19 : snapshot_cache_(snapshot_cache) { |
| 20 DCHECK(snapshot_cache_); |
| 21 } |
| 22 |
| 23 SnapshotCacheWebStateListObserver::~SnapshotCacheWebStateListObserver() = |
| 24 default; |
| 25 |
| 26 void SnapshotCacheWebStateListObserver::WebStateActivatedAt( |
| 27 WebStateList* web_state_list, |
| 28 web::WebState* old_web_state, |
| 29 web::WebState* new_web_state, |
| 30 int active_index, |
| 31 bool user_action) { |
| 32 if (!user_action) |
| 33 return; |
| 34 |
| 35 NSMutableSet<NSString*>* set = [NSMutableSet set]; |
| 36 if (active_index > 0) { |
| 37 web::WebState* web_state = web_state_list->GetWebStateAt(active_index - 1); |
| 38 [set addObject:LegacyTabHelper::GetTabForWebState(web_state).tabId]; |
| 39 } |
| 40 |
| 41 if (active_index + 1 < web_state_list->count()) { |
| 42 web::WebState* web_state = web_state_list->GetWebStateAt(active_index + 1); |
| 43 [set addObject:LegacyTabHelper::GetTabForWebState(web_state).tabId]; |
| 44 } |
| 45 |
| 46 snapshot_cache_.pinnedIDs = [set copy]; |
| 47 } |
OLD | NEW |