| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/chrome/browser/tabs/tab_model.h" | 5 #import "ios/chrome/browser/tabs/tab_model.h" |
| 6 | 6 |
| 7 #include <cstdint> | 7 #include <cstdint> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 for (Tab* tab in self) { | 679 for (Tab* tab in self) { |
| 680 if ([tab.webController isViewAlive]) | 680 if ([tab.webController isViewAlive]) |
| 681 count++; | 681 count++; |
| 682 } | 682 } |
| 683 return count; | 683 return count; |
| 684 } | 684 } |
| 685 | 685 |
| 686 #pragma mark - Private methods | 686 #pragma mark - Private methods |
| 687 | 687 |
| 688 - (SessionWindowIOS*)windowForSavingSession { | 688 - (SessionWindowIOS*)windowForSavingSession { |
| 689 // Background tabs will already have their state preserved, but not the | |
| 690 // fg tab. Do it now. | |
| 691 [self.currentTab recordStateInHistory]; | |
| 692 | |
| 693 // Build the array of sessions. Copy the session objects as the saving will | 689 // Build the array of sessions. Copy the session objects as the saving will |
| 694 // be done on a separate thread. | 690 // be done on a separate thread. |
| 695 // TODO(crbug.com/661986): This could get expensive especially since this | 691 // TODO(crbug.com/661986): This could get expensive especially since this |
| 696 // window may never be saved (if another call comes in before the delay). | 692 // window may never be saved (if another call comes in before the delay). |
| 697 return SerializeWebStateList(_webStateList.get()); | 693 return SerializeWebStateList(_webStateList.get()); |
| 698 } | 694 } |
| 699 | 695 |
| 700 - (void)postNotificationName:(NSString*)notificationName withTab:(Tab*)tab { | 696 - (void)postNotificationName:(NSString*)notificationName withTab:(Tab*)tab { |
| 701 // A scoped_nsobject is used rather than an NSDictionary with static | 697 // A scoped_nsobject is used rather than an NSDictionary with static |
| 702 // initializer dictionaryWithObject, because that approach adds the dictionary | 698 // initializer dictionaryWithObject, because that approach adds the dictionary |
| (...skipping 10 matching lines...) Expand all Loading... |
| 713 persistState:(BOOL)persistState { | 709 persistState:(BOOL)persistState { |
| 714 DCHECK(_browserState); | 710 DCHECK(_browserState); |
| 715 DCHECK(window); | 711 DCHECK(window); |
| 716 | 712 |
| 717 if (!window.sessions.count) | 713 if (!window.sessions.count) |
| 718 return NO; | 714 return NO; |
| 719 | 715 |
| 720 int oldCount = _webStateList->count(); | 716 int oldCount = _webStateList->count(); |
| 721 DCHECK_GE(oldCount, 0); | 717 DCHECK_GE(oldCount, 0); |
| 722 | 718 |
| 723 if (persistState && self.currentTab) | |
| 724 [self.currentTab recordStateInHistory]; | |
| 725 | |
| 726 web::WebState::CreateParams createParams(_browserState); | 719 web::WebState::CreateParams createParams(_browserState); |
| 727 DeserializeWebStateList( | 720 DeserializeWebStateList( |
| 728 _webStateList.get(), window, | 721 _webStateList.get(), window, |
| 729 base::BindRepeating(&web::WebState::CreateWithStorageSession, | 722 base::BindRepeating(&web::WebState::CreateWithStorageSession, |
| 730 createParams)); | 723 createParams)); |
| 731 | 724 |
| 732 DCHECK_GT(_webStateList->count(), oldCount); | 725 DCHECK_GT(_webStateList->count(), oldCount); |
| 733 int restoredCount = _webStateList->count() - oldCount; | 726 int restoredCount = _webStateList->count() - oldCount; |
| 734 DCHECK_EQ(window.sessions.count, static_cast<NSUInteger>(restoredCount)); | 727 DCHECK_EQ(window.sessions.count, static_cast<NSUInteger>(restoredCount)); |
| 735 | 728 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 805 } | 798 } |
| 806 | 799 |
| 807 // Called when UIApplicationWillEnterForegroundNotification is received. | 800 // Called when UIApplicationWillEnterForegroundNotification is received. |
| 808 - (void)applicationWillEnterForeground:(NSNotification*)notify { | 801 - (void)applicationWillEnterForeground:(NSNotification*)notify { |
| 809 if (_tabUsageRecorder) { | 802 if (_tabUsageRecorder) { |
| 810 _tabUsageRecorder->AppWillEnterForeground(); | 803 _tabUsageRecorder->AppWillEnterForeground(); |
| 811 } | 804 } |
| 812 } | 805 } |
| 813 | 806 |
| 814 @end | 807 @end |
| OLD | NEW |