Chromium Code Reviews| Index: chrome/browser/chromeos/login/ui/shared_web_view.h |
| diff --git a/chrome/browser/chromeos/login/ui/shared_web_view.h b/chrome/browser/chromeos/login/ui/shared_web_view.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..06be2f99a037a88b1be4c1e9e393faf33f7b19f5 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/login/ui/shared_web_view.h |
| @@ -0,0 +1,92 @@ |
| +// 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 CHROME_BROWSER_CHROMEOS_LOGIN_UI_SHARED_WEB_VIEW_H_ |
| +#define CHROME_BROWSER_CHROMEOS_LOGIN_UI_SHARED_WEB_VIEW_H_ |
| + |
| +#include <memory> |
| + |
| +#include "base/macros.h" |
| +#include "base/memory/memory_pressure_listener.h" |
| +#include "components/keyed_service/core/keyed_service.h" |
| +#include "content/public/browser/notification_observer.h" |
| +#include "content/public/browser/notification_registrar.h" |
| +#include "url/gurl.h" |
| + |
| +class Profile; |
| + |
| +namespace views { |
| +class WebView; |
| +} |
| + |
| +namespace chromeos { |
| + |
| +class SharedWebView : public KeyedService, |
|
xiyuan
2016/12/09 22:37:30
nit: Document the class.
jdufault
2016/12/12 18:23:09
Done.
|
| + public content::NotificationObserver { |
| + public: |
| + explicit SharedWebView(Profile* profile); |
| + ~SharedWebView() override; |
| + void Shutdown() override; |
| + |
| + // Stores a webview instance inside of |out_web_view|. |url| is the initial |
| + // URL that the webview stores (note: this function does not perform the |
| + // navigation). This returns true if the webview was reused, false if it |
| + // was freshly created. |
| + bool Get(const GURL& url, views::WebView** out_web_view); |
| + |
| + private: |
| + friend class SharedWebViewUsageHandle; |
| + |
| + // Mark the webview as in-use. |
| + void MarkUsed(); |
| + // Mark the webview as no-longer in use. |
|
xiyuan
2016/12/09 22:37:30
nit: insert an empty line before
jdufault
2016/12/12 18:23:09
Removed
|
| + void MarkUnused(); |
| + |
| + // content::NotificationObserver: |
| + void Observe(int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) override; |
| + |
| + // Called when there is a memory pressure event. |
| + void OnMemoryPressure( |
| + base::MemoryPressureListener::MemoryPressureLevel level); |
| + |
| + content::NotificationRegistrar registrar_; |
| + |
| + // Profile used for creating the views::WebView instance. |
| + Profile* profile_; |
|
xiyuan
2016/12/09 22:37:30
nit: Profile* const since |profile_| is not going
jdufault
2016/12/12 18:23:09
Done.
|
| + |
| + // Cached URL that the |web_view_| instance should point to used for |
| + // validation. |
| + GURL web_view_url_; |
| + |
| + // Number of SharedWebViewUsageHandle instances associated with this type. We |
| + // do not destroy the WebView on low-memory if this is >= 1. |
| + int handle_count_ = 0; |
| + |
| + // Shared web-view instance; owned by this class. |
| + std::unique_ptr<views::WebView> web_view_; |
| + |
| + std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SharedWebView); |
| +}; |
| + |
| +// Ensures that the WebView instance stored inside of SharedWebView will |
| +// not be destroyed during the lifetime of the SharedWebViewUsageHandle |
| +// instance. |
| +class SharedWebViewUsageHandle { |
|
xiyuan
2016/12/09 22:37:30
This looks like to be used as a ref count for |web
jdufault
2016/12/12 18:23:09
Done.
|
| + public: |
| + explicit SharedWebViewUsageHandle(SharedWebView* shared_web_view); |
| + ~SharedWebViewUsageHandle(); |
| + |
| + private: |
| + SharedWebView* shared_web_view_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SharedWebViewUsageHandle); |
| +}; |
| + |
| +} // namespace chromeos |
| + |
| +#endif // CHROME_BROWSER_CHROMEOS_LOGIN_UI_SHARED_WEB_VIEW_H_ |