Commit a7c39cdc authored by Sylvain Defresne's avatar Sylvain Defresne Committed by Commit Bot

Allow WebStateObserver to observe N WebStates [9/N].

Convert WebFaviconDriver to directly track registration with
the observed WebState instead of relying on the deprecated
code in WebStateObserver.

Bug: 775684
Change-Id: I7f7fcec4a57c1da79012069d971123c9e4144799
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-eg
Reviewed-on: https://chromium-review.googlesource.com/758863
Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#515951}
parent f75e20be
......@@ -67,6 +67,7 @@ class WebFaviconDriver : public web::WebStateObserver,
void FaviconUrlUpdated(
web::WebState* web_state,
const std::vector<web::FaviconURL>& candidates) override;
void WebStateDestroyed(web::WebState* web_state) override;
// Invoked when new favicon URL candidates are received.
void FaviconUrlUpdatedInternal(
......@@ -78,6 +79,10 @@ class WebFaviconDriver : public web::WebStateObserver,
// Caches the favicon URLs candidates for same-document navigations.
std::vector<favicon::FaviconURL> candidates_;
// The WebState this instance is observing. Will be null after
// WebStateDestroyed has been called.
web::WebState* web_state_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(WebFaviconDriver);
};
......
......@@ -51,19 +51,19 @@ void WebFaviconDriver::CreateForWebState(
gfx::Image WebFaviconDriver::GetFavicon() const {
web::NavigationItem* item =
web_state()->GetNavigationManager()->GetLastCommittedItem();
web_state_->GetNavigationManager()->GetLastCommittedItem();
return item ? item->GetFavicon().image : gfx::Image();
}
bool WebFaviconDriver::FaviconIsValid() const {
web::NavigationItem* item =
web_state()->GetNavigationManager()->GetLastCommittedItem();
web_state_->GetNavigationManager()->GetLastCommittedItem();
return item ? item->GetFavicon().valid : false;
}
GURL WebFaviconDriver::GetActiveURL() {
web::NavigationItem* item =
web_state()->GetNavigationManager()->GetVisibleItem();
web_state_->GetNavigationManager()->GetVisibleItem();
return item ? item->GetURL() : GURL();
}
......@@ -103,8 +103,8 @@ void WebFaviconDriver::DownloadManifest(const GURL& url,
}
bool WebFaviconDriver::IsOffTheRecord() {
DCHECK(web_state());
return web_state()->GetBrowserState()->IsOffTheRecord();
DCHECK(web_state_);
return web_state_->GetBrowserState()->IsOffTheRecord();
}
void WebFaviconDriver::OnFaviconUpdated(
......@@ -122,7 +122,7 @@ void WebFaviconDriver::OnFaviconUpdated(
}
web::NavigationItem* item =
web_state()->GetNavigationManager()->GetVisibleItem();
web_state_->GetNavigationManager()->GetVisibleItem();
DCHECK(item);
web::FaviconStatus& favicon_status = item->GetFavicon();
......@@ -155,16 +155,23 @@ void WebFaviconDriver::OnFaviconDeleted(
WebFaviconDriver::WebFaviconDriver(web::WebState* web_state,
FaviconService* favicon_service,
history::HistoryService* history_service)
: web::WebStateObserver(web_state),
FaviconDriverImpl(favicon_service, history_service),
image_fetcher_(web_state->GetBrowserState()->GetRequestContext()) {}
: FaviconDriverImpl(favicon_service, history_service),
image_fetcher_(web_state->GetBrowserState()->GetRequestContext()),
web_state_(web_state) {
web_state_->AddObserver(this);
}
WebFaviconDriver::~WebFaviconDriver() {
// WebFaviconDriver is owned by WebState (as it is a WebStateUserData), so
// the WebStateDestroyed will be called before the destructor and the member
// field reset to null.
DCHECK(!web_state_);
}
void WebFaviconDriver::DidStartNavigation(
web::WebState* web_state,
web::NavigationContext* navigation_context) {
DCHECK_EQ(web_state_, web_state);
SetFaviconOutOfDateForPage(navigation_context->GetUrl(),
/*force_reload=*/false);
}
......@@ -172,6 +179,7 @@ void WebFaviconDriver::DidStartNavigation(
void WebFaviconDriver::DidFinishNavigation(
web::WebState* web_state,
web::NavigationContext* navigation_context) {
DCHECK_EQ(web_state_, web_state);
if (navigation_context->GetError())
return;
......@@ -191,11 +199,18 @@ void WebFaviconDriver::DidFinishNavigation(
void WebFaviconDriver::FaviconUrlUpdated(
web::WebState* web_state,
const std::vector<web::FaviconURL>& candidates) {
DCHECK_EQ(web_state_, web_state);
DCHECK(!candidates.empty());
candidates_ = FaviconURLsFromWebFaviconURLs(candidates);
FaviconUrlUpdatedInternal(candidates_);
}
void WebFaviconDriver::WebStateDestroyed(web::WebState* web_state) {
DCHECK_EQ(web_state_, web_state);
web_state_->RemoveObserver(this);
web_state_ = nullptr;
}
void WebFaviconDriver::FaviconUrlUpdatedInternal(
const std::vector<favicon::FaviconURL>& candidates) {
OnUpdateCandidates(GetActiveURL(), candidates, GURL());
......
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