Commit 43b65e28 authored by edchin's avatar edchin Committed by Commit Bot

[ios] Call SnapshotTabHelper instead of SnapshotBrowserAgent in TabModel

The calls to SnapshotCache methods via SnapshotBrowserAgent required
obtaining and passing in a Tab ID. It is more correct to directly
call the SnapshotTabHelper since it is tied to the WebState.

Change-Id: Ie0a7f1976544bc860e4b0cf4ba4e4e381689333e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2370015Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Commit-Queue: edchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#801385}
parent 60612d0b
...@@ -78,6 +78,7 @@ class Time; ...@@ -78,6 +78,7 @@ class Time;
// background thread. // background thread.
- (void)purgeCacheOlderThan:(const base::Time&)date - (void)purgeCacheOlderThan:(const base::Time&)date
keeping:(NSSet*)liveSnapshotIDs; keeping:(NSSet*)liveSnapshotIDs;
// Hint that the snapshot for |snapshotID| will likely be saved to disk when the // Hint that the snapshot for |snapshotID| will likely be saved to disk when the
// application is backgrounded. The snapshot is then saved in memory, so it // application is backgrounded. The snapshot is then saved in memory, so it
// does not need to be read off disk. // does not need to be read off disk.
......
...@@ -78,6 +78,15 @@ class SnapshotTabHelper : public infobars::InfoBarManager::Observer, ...@@ -78,6 +78,15 @@ class SnapshotTabHelper : public infobars::InfoBarManager::Observer,
// Instructs the helper not to snapshot content for the next page load event. // Instructs the helper not to snapshot content for the next page load event.
void IgnoreNextLoad(); void IgnoreNextLoad();
// Hint that the snapshot will likely be saved to disk when the application is
// backgrounded. The snapshot is then saved in memory, so it does not need to
// be read off disk.
void WillBeSavedGreyWhenBackgrounding();
// Write a grey copy of the snapshot to disk, but if and only if a color
// version of the snapshot already exists in memory or on disk.
void SaveGreyInBackground();
private: private:
friend class web::WebStateUserData<SnapshotTabHelper>; friend class web::WebStateUserData<SnapshotTabHelper>;
...@@ -97,6 +106,7 @@ class SnapshotTabHelper : public infobars::InfoBarManager::Observer, ...@@ -97,6 +106,7 @@ class SnapshotTabHelper : public infobars::InfoBarManager::Observer,
void OnManagerShuttingDown(infobars::InfoBarManager* manager) override; void OnManagerShuttingDown(infobars::InfoBarManager* manager) override;
web::WebState* web_state_ = nullptr; web::WebState* web_state_ = nullptr;
NSString* tab_id_ = nil;
SnapshotGenerator* snapshot_generator_ = nil; SnapshotGenerator* snapshot_generator_ = nil;
infobars::InfoBarManager* infobar_manager_ = nullptr; infobars::InfoBarManager* infobar_manager_ = nullptr;
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "components/infobars/core/infobar.h" #include "components/infobars/core/infobar.h"
#include "components/infobars/core/infobar_delegate.h" #include "components/infobars/core/infobar_delegate.h"
#include "ios/chrome/browser/infobars/infobar_manager_impl.h" #include "ios/chrome/browser/infobars/infobar_manager_impl.h"
#import "ios/chrome/browser/snapshots/snapshot_cache.h"
#import "ios/chrome/browser/snapshots/snapshot_generator.h" #import "ios/chrome/browser/snapshots/snapshot_generator.h"
#import "ios/chrome/browser/ui/infobars/infobar_feature.h" #import "ios/chrome/browser/ui/infobars/infobar_feature.h"
#include "ios/chrome/browser/ui/util/ui_util.h" #include "ios/chrome/browser/ui/util/ui_util.h"
...@@ -101,7 +102,6 @@ UIImage* SnapshotTabHelper::GenerateSnapshotWithoutOverlays() { ...@@ -101,7 +102,6 @@ UIImage* SnapshotTabHelper::GenerateSnapshotWithoutOverlays() {
} }
void SnapshotTabHelper::RemoveSnapshot() { void SnapshotTabHelper::RemoveSnapshot() {
DCHECK(web_state_);
[snapshot_generator_ removeSnapshot]; [snapshot_generator_ removeSnapshot];
} }
...@@ -109,13 +109,24 @@ void SnapshotTabHelper::IgnoreNextLoad() { ...@@ -109,13 +109,24 @@ void SnapshotTabHelper::IgnoreNextLoad() {
ignore_next_load_ = true; ignore_next_load_ = true;
} }
void SnapshotTabHelper::WillBeSavedGreyWhenBackgrounding() {
[snapshot_generator_.snapshotCache willBeSavedGreyWhenBackgrounding:tab_id_];
}
void SnapshotTabHelper::SaveGreyInBackground() {
[snapshot_generator_.snapshotCache saveGreyInBackgroundForSnapshotID:tab_id_];
}
SnapshotTabHelper::SnapshotTabHelper(web::WebState* web_state, NSString* tab_id) SnapshotTabHelper::SnapshotTabHelper(web::WebState* web_state, NSString* tab_id)
: web_state_(web_state), : web_state_(web_state),
tab_id_([tab_id copy]),
web_state_observer_(this), web_state_observer_(this),
infobar_observer_(this), infobar_observer_(this),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
DCHECK(web_state_);
DCHECK(tab_id_.length > 0);
snapshot_generator_ = [[SnapshotGenerator alloc] initWithWebState:web_state_ snapshot_generator_ = [[SnapshotGenerator alloc] initWithWebState:web_state_
tabID:tab_id]; tabID:tab_id_];
web_state_observer_.Add(web_state_); web_state_observer_.Add(web_state_);
// Supports missing InfoBarManager to make testing easier. // Supports missing InfoBarManager to make testing easier.
...@@ -180,6 +191,7 @@ void SnapshotTabHelper::WebStateDestroyed(web::WebState* web_state) { ...@@ -180,6 +191,7 @@ void SnapshotTabHelper::WebStateDestroyed(web::WebState* web_state) {
DCHECK_EQ(web_state_, web_state); DCHECK_EQ(web_state_, web_state);
web_state_observer_.Remove(web_state); web_state_observer_.Remove(web_state);
web_state_ = nullptr; web_state_ = nullptr;
tab_id_ = nil;
} }
void SnapshotTabHelper::OnInfoBarAdded(infobars::InfoBar* infobar) { void SnapshotTabHelper::OnInfoBarAdded(infobars::InfoBar* infobar) {
......
...@@ -35,10 +35,8 @@ ...@@ -35,10 +35,8 @@
#import "ios/chrome/browser/sessions/session_restoration_browser_agent.h" #import "ios/chrome/browser/sessions/session_restoration_browser_agent.h"
#import "ios/chrome/browser/sessions/session_service_ios.h" #import "ios/chrome/browser/sessions/session_service_ios.h"
#import "ios/chrome/browser/sessions/session_window_ios.h" #import "ios/chrome/browser/sessions/session_window_ios.h"
#import "ios/chrome/browser/snapshots/snapshot_browser_agent.h" #import "ios/chrome/browser/snapshots/snapshot_tab_helper.h"
#import "ios/chrome/browser/snapshots/snapshot_cache.h"
#import "ios/chrome/browser/tabs/tab_parenting_observer.h" #import "ios/chrome/browser/tabs/tab_parenting_observer.h"
#import "ios/chrome/browser/web/tab_id_tab_helper.h"
#import "ios/chrome/browser/web_state_list/web_state_list.h" #import "ios/chrome/browser/web_state_list/web_state_list.h"
#import "ios/chrome/browser/web_state_list/web_state_list_observer.h" #import "ios/chrome/browser/web_state_list/web_state_list_observer.h"
#import "ios/chrome/browser/web_state_list/web_usage_enabler/web_usage_enabler_browser_agent.h" #import "ios/chrome/browser/web_state_list/web_usage_enabler/web_usage_enabler_browser_agent.h"
...@@ -133,9 +131,6 @@ void RecordInterfaceOrientationMetric() { ...@@ -133,9 +131,6 @@ void RecordInterfaceOrientationMetric() {
// Weak reference to the session restoration agent. // Weak reference to the session restoration agent.
SessionRestorationBrowserAgent* _sessionRestorationBrowserAgent; SessionRestorationBrowserAgent* _sessionRestorationBrowserAgent;
// Used for saving gray images.
SnapshotBrowserAgent* _snapshotBrowserAgent;
// Used to ensure thread-safety of the certificate policy management code. // Used to ensure thread-safety of the certificate policy management code.
base::CancelableTaskTracker _clearPoliciesTaskTracker; base::CancelableTaskTracker _clearPoliciesTaskTracker;
...@@ -180,8 +175,6 @@ void RecordInterfaceOrientationMetric() { ...@@ -180,8 +175,6 @@ void RecordInterfaceOrientationMetric() {
SessionRestorationBrowserAgent::FromBrowser(browser); SessionRestorationBrowserAgent::FromBrowser(browser);
_webEnabler = WebUsageEnablerBrowserAgent::FromBrowser(browser); _webEnabler = WebUsageEnablerBrowserAgent::FromBrowser(browser);
_snapshotBrowserAgent = SnapshotBrowserAgent::FromBrowser(browser);
_webStateListObservers.push_back(std::make_unique<TabParentingObserver>()); _webStateListObservers.push_back(std::make_unique<TabParentingObserver>());
for (const auto& webStateListObserver : _webStateListObservers) for (const auto& webStateListObserver : _webStateListObservers)
...@@ -239,12 +232,8 @@ void RecordInterfaceOrientationMetric() { ...@@ -239,12 +232,8 @@ void RecordInterfaceOrientationMetric() {
// TODO(crbug.com/1115611): Move to SceneController. // TODO(crbug.com/1115611): Move to SceneController.
- (void)willResignActive:(NSNotification*)notify { - (void)willResignActive:(NSNotification*)notify {
if (_webEnabler->IsWebUsageEnabled() && _webStateList->GetActiveWebState()) { if (_webEnabler->IsWebUsageEnabled() && _webStateList->GetActiveWebState()) {
NSString* tabId = SnapshotTabHelper::FromWebState(_webStateList->GetActiveWebState())
TabIdTabHelper::FromWebState(_webStateList->GetActiveWebState()) ->WillBeSavedGreyWhenBackgrounding();
->tab_id();
[_snapshotBrowserAgent->snapshot_cache()
willBeSavedGreyWhenBackgrounding:tabId];
} }
} }
...@@ -268,12 +257,8 @@ void RecordInterfaceOrientationMetric() { ...@@ -268,12 +257,8 @@ void RecordInterfaceOrientationMetric() {
// Write out a grey version of the current website to disk. // Write out a grey version of the current website to disk.
if (_webEnabler->IsWebUsageEnabled() && _webStateList->GetActiveWebState()) { if (_webEnabler->IsWebUsageEnabled() && _webStateList->GetActiveWebState()) {
NSString* tabId = SnapshotTabHelper::FromWebState(_webStateList->GetActiveWebState())
TabIdTabHelper::FromWebState(_webStateList->GetActiveWebState()) ->SaveGreyInBackground();
->tab_id();
[_snapshotBrowserAgent->snapshot_cache()
saveGreyInBackgroundForSnapshotID:tabId];
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment