Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: chrome/browser/chromeos/login/ui/shared_web_view.cc

Issue 2512473004: cros: Enable WebUILoginView reuse. (Closed)
Patch Set: Address comments Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 #include "chrome/browser/chromeos/login/ui/shared_web_view.h"
6
7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/chromeos/login/ui/web_view_handle.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "content/public/browser/notification_service.h"
11 #include "content/public/browser/render_view_host.h"
12 #include "content/public/browser/render_widget_host.h"
13 #include "content/public/browser/web_contents.h"
14 #include "ui/views/controls/webview/webview.h"
15
16 namespace chromeos {
17
18 SharedWebView::SharedWebView(Profile* profile) : profile_(profile) {
19 registrar_.Add(this, chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST,
20 content::NotificationService::AllSources());
21 memory_pressure_listener_ = base::MakeUnique<base::MemoryPressureListener>(
22 base::Bind(&SharedWebView::OnMemoryPressure, base::Unretained(this)));
23 }
24
25 SharedWebView::~SharedWebView() {}
26
27 void SharedWebView::Shutdown() {
28 web_view_handle_ = nullptr;
29 }
30
31 bool SharedWebView::Get(const GURL& url,
32 scoped_refptr<WebViewHandle>* out_handle) {
33 // At the moment only one shared WebView instance is supported per profile.
34 DCHECK(web_view_url_.is_empty() || web_view_url_ == url);
35 web_view_url_ = url;
36
37 // Ensure the WebView is not being reused simultaneously.
38 DCHECK(!web_view_handle_ || web_view_handle_->HasOneRef());
39
40 // Clear cached reference if it is no longer valid (ie, destroyed in task
41 // manager).
42 if (web_view_handle_ &&
43 !web_view_handle_->web_view()
44 ->GetWebContents()
45 ->GetRenderViewHost()
46 ->GetWidget()
47 ->GetView()) {
48 web_view_handle_ = nullptr;
49 }
50
51 // Create WebView if needed.
52 bool reused = true;
53 if (!web_view_handle_) {
54 web_view_handle_ = new WebViewHandle(profile_);
55 reused = false;
56 }
57
58 *out_handle = web_view_handle_;
59 return reused;
60 }
61
62 void SharedWebView::Observe(int type,
63 const content::NotificationSource& source,
64 const content::NotificationDetails& details) {
65 DCHECK_EQ(chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST, type);
66 web_view_handle_ = nullptr;
67 }
68
69 void SharedWebView::OnMemoryPressure(
70 base::MemoryPressureListener::MemoryPressureLevel level) {
71 switch (level) {
72 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE:
73 break;
74 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE:
75 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL:
76 web_view_handle_ = nullptr;
77 break;
78 }
79 }
80
81 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/ui/shared_web_view.h ('k') | chrome/browser/chromeos/login/ui/shared_web_view_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698