blob: cd7f24690d9da666ad21cf9952d39a297795c3ea [file] [log] [blame]
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_TABS_TAB_MODEL_FAVICON_DRIVER_OBSERVER_H_
#define IOS_CHROME_BROWSER_TABS_TAB_MODEL_FAVICON_DRIVER_OBSERVER_H_
#include <map>
#include "base/macros.h"
#include "components/favicon/core/favicon_driver_observer.h"
#import "ios/chrome/browser/web_state_list/web_state_list_observer.h"
@class TabModel;
@class TabModelObservers;
// Listen to multiple FaviconDriver for notification that their WebState's
// favicon has changed and forward the notifications to TabModelObservers.
// The class listen to a WebStateList for the creation/replacement/removal
// of WebStates.
class TabModelFaviconDriverObserver : public favicon::FaviconDriverObserver,
public WebStateListObserver {
public:
TabModelFaviconDriverObserver(TabModel* tab_model,
TabModelObservers* observers);
~TabModelFaviconDriverObserver() override;
// WebStateListObserver implementation:
void WebStateInsertedAt(WebStateList* web_state_list,
web::WebState* web_state,
int index,
bool activating) override;
void WebStateReplacedAt(WebStateList* web_state_list,
web::WebState* old_web_state,
web::WebState* new_web_state,
int index) override;
void WebStateDetachedAt(WebStateList* web_state_list,
web::WebState* web_state,
int index) override;
// favicon::FaviconDriverObserver implementation.
void OnFaviconUpdated(favicon::FaviconDriver* driver,
NotificationIconType icon_type,
const GURL& icon_url,
bool icon_url_changed,
const gfx::Image& image) override;
private:
// The owning TabModel. This will be passed to the TabModelObservers
// when forwarding notificaton.
__weak TabModel* tab_model_;
// The TabModelObservers to which the FaviconDriver notification are
// forwarded. Should not be nil.
__weak TabModelObservers* observers_;
// Maps FaviconDriver to the WebState they are attached to. Used
// to find the WebState that should be passed when forwarding the
// notification to TabModelObservers.
std::map<favicon::FaviconDriver*, web::WebState*> driver_to_web_state_map_;
DISALLOW_COPY_AND_ASSIGN(TabModelFaviconDriverObserver);
};
#endif // IOS_CHROME_BROWSER_TABS_TAB_MODEL_FAVICON_DRIVER_OBSERVER_H_