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

Unified Diff: extensions/browser/guest_view/web_view/web_view_guest.cc

Issue 1143333008: Getting rid of more webview memory leaks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months 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 side-by-side diff with in-line comments
Download patch
Index: extensions/browser/guest_view/web_view/web_view_guest.cc
diff --git a/extensions/browser/guest_view/web_view/web_view_guest.cc b/extensions/browser/guest_view/web_view/web_view_guest.cc
index 7a5f4f2dada3c527fbafb8038960f730d785daed..8712fa43593a37f59273d1408a2a5dfd646ecb37 100644
--- a/extensions/browser/guest_view/web_view/web_view_guest.cc
+++ b/extensions/browser/guest_view/web_view/web_view_guest.cc
@@ -166,13 +166,11 @@ void ParsePartitionParam(const base::DictionaryValue& create_params,
void RemoveWebViewEventListenersOnIOThread(
void* profile,
- const std::string& extension_id,
int embedder_process_id,
int view_instance_id) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
ExtensionWebRequestEventRouter::GetInstance()->RemoveWebViewEventListeners(
profile,
- extension_id,
embedder_process_id,
view_instance_id);
}
@@ -187,6 +185,39 @@ double ConvertZoomLevelToZoomFactor(double zoom_level) {
} // namespace
+using WebViewKey = std::pair<int, int>;
+using WebViewKeyToIDMap = std::map<WebViewKey, int>;
+static base::LazyInstance<WebViewKeyToIDMap> web_view_key_to_id_map =
lazyboy 2015/06/05 23:09:55 should we put these inside anonymous namespace?
paulmeyer 2015/06/08 17:53:59 Not sure. I didn't actually write this one, I just
+ LAZY_INSTANCE_INITIALIZER;
+
+// static
+void WebViewGuest::CleanUp(int embedder_process_id, int view_instance_id) {
+ GuestViewBase::CleanUp(embedder_process_id, view_instance_id);
+
+ auto rph = content::RenderProcessHost::FromID(embedder_process_id);
+ auto browser_context = rph->GetBrowserContext();
lazyboy 2015/06/05 23:09:55 If I remember correctly, we were using auto only f
paulmeyer 2015/06/08 17:53:59 I was under the impression that auto should/can be
+
+ // Clean up rules registries for the WebView.
+ WebViewKey key(embedder_process_id, view_instance_id);
+ auto it = web_view_key_to_id_map.Get().find(key);
+ if (it != web_view_key_to_id_map.Get().end()) {
+ auto rules_registry_id = it->second;
+ web_view_key_to_id_map.Get().erase(it);
+ RulesRegistryService::Get(browser_context)->
+ RemoveRulesRegistriesByID(rules_registry_id);
+ }
+
+ // Clean up web request event listeners for the WebView.
+ content::BrowserThread::PostTask(
+ content::BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(
+ &RemoveWebViewEventListenersOnIOThread,
+ browser_context,
+ embedder_process_id,
+ view_instance_id));
+}
+
// static
GuestViewBase* WebViewGuest::Create(content::WebContents* owner_web_contents) {
return new WebViewGuest(owner_web_contents);
@@ -218,11 +249,6 @@ bool WebViewGuest::GetGuestPartitionConfigForSite(
// static
const char WebViewGuest::Type[] = "webview";
-using WebViewKey = std::pair<int, int>;
-using WebViewKeyToIDMap = std::map<WebViewKey, int>;
-static base::LazyInstance<WebViewKeyToIDMap> web_view_key_to_id_map =
- LAZY_INSTANCE_INITIALIZER;
-
// static
int WebViewGuest::GetOrGenerateRulesRegistryID(
int embedder_process_id,
@@ -384,25 +410,6 @@ void WebViewGuest::EmbedderFullscreenToggled(bool entered_fullscreen) {
SetFullscreenState(false);
}
-void WebViewGuest::EmbedderWillBeDestroyed() {
- // Clean up rules registries for the webview.
- RulesRegistryService::Get(browser_context())
- ->RemoveRulesRegistriesByID(rules_registry_id_);
- WebViewKey key(owner_web_contents()->GetRenderProcessHost()->GetID(),
- view_instance_id());
- web_view_key_to_id_map.Get().erase(key);
-
- content::BrowserThread::PostTask(
- content::BrowserThread::IO,
- FROM_HERE,
- base::Bind(
- &RemoveWebViewEventListenersOnIOThread,
- browser_context(),
- owner_host(),
- owner_web_contents()->GetRenderProcessHost()->GetID(),
- view_instance_id()));
-}
-
const char* WebViewGuest::GetAPINamespace() const {
return webview::kAPINamespace;
}

Powered by Google App Engine
This is Rietveld 408576698