Index: ios/chrome/browser/dom_distiller/web_state_pool_impl.h |
diff --git a/ios/chrome/browser/dom_distiller/web_state_pool_impl.h b/ios/chrome/browser/dom_distiller/web_state_pool_impl.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..075e326c3258aeecb2113cd5eaf8ac89de2fe029 |
--- /dev/null |
+++ b/ios/chrome/browser/dom_distiller/web_state_pool_impl.h |
@@ -0,0 +1,74 @@ |
+// Copyright 2016 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_DOM_DISTILLER_WEB_STATE_POOL_IMPL_H_ |
+#define IOS_CHROME_BROWSER_DOM_DISTILLER_WEB_STATE_POOL_IMPL_H_ |
+ |
+#include <list> |
+#include <map> |
+#include <memory> |
+ |
+#include "base/memory/weak_ptr.h" |
+#include "components/dom_distiller/ios/web_state_pool.h" |
+#include "components/favicon/core/favicon_driver_observer.h" |
+#import "ios/web/public/web_state/web_state.h" |
+ |
+namespace favicon { |
+class FaviconDriver; |
+} |
+ |
+class GURL; |
+ |
+namespace gfx { |
+class Image; |
+} |
+ |
+namespace dom_distiller { |
+ |
+// Implementation of the WebStatePool. |
+class WebStatePoolImpl : public WebStatePool, favicon::FaviconDriverObserver { |
+ public: |
+ WebStatePoolImpl(web::BrowserState* browser_state); |
+ ~WebStatePoolImpl() override; |
+ |
+ // WebStatePool implementation. |
+ void RequestWebState(WebStatePoolDelegate* delegate) override; |
+ void ReturnWebState(web::WebState* web_state) override; |
+ |
+ // FaviconDriverObserver implementation. |
+ void OnFaviconUpdated(favicon::FaviconDriver* favicon_driver, |
+ NotificationIconType notification_icon_type, |
+ const GURL& icon_url, |
+ bool icon_url_changed, |
+ const gfx::Image& image) override; |
+ |
+ private: |
+ // Creates a WebState at the index position with a favicon driver. This object |
+ // is an observer for the favicon driver. |
+ void CreateWebState(int web_state_index); |
+ // Removes the corresponding WebState from the list of WebStates used by |
+ // favicon drivers. |
+ void OnFaviconDownloaded(favicon::FaviconDriver*); |
+ // Returns the index of the first WebState available, -1 if no WebState is |
+ // available. |
+ int GetFirstWebStateAvailable(); |
+ |
+ web::BrowserState* browser_state_; |
+ // List of delegates waiting for a WebState. |
+ std::list<WebStatePoolDelegate*> pending_delegates_; |
+ // List of unique pointers to the WebStates. Used only to ensure the lifespan |
+ // of the WebStates. |
+ std::vector<std::unique_ptr<web::WebState>> unique_web_states_; |
+ // Corresponding list of raw pointers to the WebStates. |
+ std::vector<web::WebState*> web_states_; |
+ // Map of the WebStates used by Favicon Drivers. |
+ std::map<favicon::FaviconDriver*, int> favicon_web_state_; |
+ // Map of the WebStates used by the delegates. |
+ std::map<web::WebState*, int> registered_web_state_; |
+ base::WeakPtrFactory<WebStatePoolImpl> weak_ptr_factory_; |
+}; |
+ |
+} // namespace dom_distiller |
+ |
+#endif // IOS_CHROME_BROWSER_DOM_DISTILLER_WEB_STATE_POOL_IMPL_H_ |