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

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

Issue 764643002: Remove WebViewKey in rules registry. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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 e27039b6013c936071b622a62f2f8edb9a0e304f..ed879c2c19e756c34851e85bdcb687f33c0f586c 100644
--- a/extensions/browser/guest_view/web_view/web_view_guest.cc
+++ b/extensions/browser/guest_view/web_view/web_view_guest.cc
@@ -30,6 +30,7 @@
#include "content/public/common/result_codes.h"
#include "content/public/common/stop_find_action.h"
#include "content/public/common/url_constants.h"
+#include "extensions/browser/api/declarative/rules_registry_service.h"
#include "extensions/browser/api/extensions_api_client.h"
#include "extensions/browser/api/web_request/web_request_api.h"
#include "extensions/browser/api/web_view/web_view_internal_api.h"
@@ -180,6 +181,44 @@ bool WebViewGuest::GetGuestPartitionConfigForSite(
// static
const char WebViewGuest::Type[] = "webview";
+typedef std::pair<int, int> WebViewKey;
+typedef std::map<WebViewKey, int> WebViewKeyToIDMap;
+typedef std::map<int, WebViewKey> IDToWebViewKeyMap;
+static base::LazyInstance<WebViewKeyToIDMap> web_view_key_to_id_map =
+ LAZY_INSTANCE_INITIALIZER;
+static base::LazyInstance<IDToWebViewKeyMap> id_to_web_view_key_map =
+ LAZY_INSTANCE_INITIALIZER;
+
+// static
+void WebViewGuest::GenerateRulesRegistryID(
Fady Samuel 2014/11/28 11:34:24 GetOrGenerateRulesRegistryID
Xi Han 2014/11/28 16:12:56 Done.
+ int embedder_process_id,
+ int webview_instance_id,
+ RulesRegistryService* rules_registry_service,
Fady Samuel 2014/11/26 23:39:41 Pass in a BrowserContext instead.
Xi Han 2014/11/27 23:25:26 Done.
+ int* rules_registry_id) {
Fady Samuel 2014/11/26 23:39:41 return this value instead of making it an output p
Xi Han 2014/11/27 23:25:26 Done.
+ WebViewKey key = std::make_pair(embedder_process_id, webview_instance_id);
+ WebViewKeyToIDMap::iterator it = web_view_key_to_id_map.Get().find(key);
+ if (it != web_view_key_to_id_map.Get().end()) {
+ (*rules_registry_id) = it->second;
+ return;
+ }
+ *rules_registry_id = rules_registry_service->GetNextRulesRegistryId();
+ web_view_key_to_id_map.Get()[key] = *rules_registry_id;
+ id_to_web_view_key_map.Get()[*rules_registry_id] = key;
+}
+
+// static
+int WebViewGuest::GetEmbedderProcessID(int rules_registry_id) {
+ return id_to_web_view_key_map.Get().find(rules_registry_id)->first;
+}
+
+// static
+void WebViewGuest::RemoveRulesRegistryID(int rules_registry_id) {
+ IDToWebViewKeyMap::iterator it =
+ id_to_web_view_key_map.Get().find(rules_registry_id);
+ web_view_key_to_id_map.Get().erase(it->second);
+ id_to_web_view_key_map.Get().erase(it);
+}
+
// static
int WebViewGuest::GetViewInstanceId(WebContents* contents) {
WebViewGuest* guest = FromWebContents(contents);
@@ -812,6 +851,9 @@ void WebViewGuest::PushWebViewStateToIOThread() {
web_view_info.instance_id = view_instance_id();
web_view_info.partition_id = partition_id;
web_view_info.embedder_extension_id = embedder_extension_id();
+ WebViewKey key(web_view_info.embedder_process_id, web_view_info.instance_id);
+ web_view_info.rules_registry_id =
+ web_view_key_to_id_map.Get().find(key)->second;
content::BrowserThread::PostTask(
content::BrowserThread::IO,

Powered by Google App Engine
This is Rietveld 408576698