Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_UI_SHARED_WEB_VIEW_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_UI_SHARED_WEB_VIEW_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "base/memory/memory_pressure_listener.h" | |
| 12 #include "components/keyed_service/core/keyed_service.h" | |
| 13 #include "content/public/browser/notification_observer.h" | |
| 14 #include "content/public/browser/notification_registrar.h" | |
| 15 #include "url/gurl.h" | |
| 16 | |
| 17 class Profile; | |
| 18 | |
| 19 namespace views { | |
| 20 class WebView; | |
| 21 } | |
| 22 | |
| 23 namespace chromeos { | |
| 24 | |
| 25 class SharedWebView : public KeyedService, | |
|
xiyuan
2016/12/09 22:37:30
nit: Document the class.
jdufault
2016/12/12 18:23:09
Done.
| |
| 26 public content::NotificationObserver { | |
| 27 public: | |
| 28 explicit SharedWebView(Profile* profile); | |
| 29 ~SharedWebView() override; | |
| 30 void Shutdown() override; | |
| 31 | |
| 32 // Stores a webview instance inside of |out_web_view|. |url| is the initial | |
| 33 // URL that the webview stores (note: this function does not perform the | |
| 34 // navigation). This returns true if the webview was reused, false if it | |
| 35 // was freshly created. | |
| 36 bool Get(const GURL& url, views::WebView** out_web_view); | |
| 37 | |
| 38 private: | |
| 39 friend class SharedWebViewUsageHandle; | |
| 40 | |
| 41 // Mark the webview as in-use. | |
| 42 void MarkUsed(); | |
| 43 // 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
| |
| 44 void MarkUnused(); | |
| 45 | |
| 46 // content::NotificationObserver: | |
| 47 void Observe(int type, | |
| 48 const content::NotificationSource& source, | |
| 49 const content::NotificationDetails& details) override; | |
| 50 | |
| 51 // Called when there is a memory pressure event. | |
| 52 void OnMemoryPressure( | |
| 53 base::MemoryPressureListener::MemoryPressureLevel level); | |
| 54 | |
| 55 content::NotificationRegistrar registrar_; | |
| 56 | |
| 57 // Profile used for creating the views::WebView instance. | |
| 58 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.
| |
| 59 | |
| 60 // Cached URL that the |web_view_| instance should point to used for | |
| 61 // validation. | |
| 62 GURL web_view_url_; | |
| 63 | |
| 64 // Number of SharedWebViewUsageHandle instances associated with this type. We | |
| 65 // do not destroy the WebView on low-memory if this is >= 1. | |
| 66 int handle_count_ = 0; | |
| 67 | |
| 68 // Shared web-view instance; owned by this class. | |
| 69 std::unique_ptr<views::WebView> web_view_; | |
| 70 | |
| 71 std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_; | |
| 72 | |
| 73 DISALLOW_COPY_AND_ASSIGN(SharedWebView); | |
| 74 }; | |
| 75 | |
| 76 // Ensures that the WebView instance stored inside of SharedWebView will | |
| 77 // not be destroyed during the lifetime of the SharedWebViewUsageHandle | |
| 78 // instance. | |
| 79 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.
| |
| 80 public: | |
| 81 explicit SharedWebViewUsageHandle(SharedWebView* shared_web_view); | |
| 82 ~SharedWebViewUsageHandle(); | |
| 83 | |
| 84 private: | |
| 85 SharedWebView* shared_web_view_; | |
| 86 | |
| 87 DISALLOW_COPY_AND_ASSIGN(SharedWebViewUsageHandle); | |
| 88 }; | |
| 89 | |
| 90 } // namespace chromeos | |
| 91 | |
| 92 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_UI_SHARED_WEB_VIEW_H_ | |
| OLD | NEW |