1 // Copyright 2013 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_SITE_ISOLATION_SITE_DETAILS_H_ 6 #define CHROME_BROWSER_SITE_ISOLATION_SITE_DETAILS_H_ 7 8 #include <stdint.h> 9 10 #include <map> 11 #include <set> 12 13 #include "base/macros.h" 14 #include "content/public/browser/browser_context.h" 15 #include "content/public/browser/site_instance.h" 16 #include "content/public/browser/web_contents.h" 17 18 // Collects metrics about an actual browsing instance in the current session. 19 struct BrowsingInstanceInfo { 20 BrowsingInstanceInfo(); 21 BrowsingInstanceInfo(const BrowsingInstanceInfo& other); 22 ~BrowsingInstanceInfo(); 23 24 std::set<content::SiteInstance*> site_instances; 25 int proxy_count = 0; 26 }; 27 using BrowsingInstanceMap = 28 std::map<content::SiteInstance*, BrowsingInstanceInfo>; 29 30 // Information about the sites and SiteInstances in each BrowsingInstance, for 31 // use in estimating the number of processes needed for various process models. 32 struct SiteData { 33 SiteData(); 34 SiteData(const SiteData& other); 35 ~SiteData(); 36 37 // This map groups related SiteInstances together into BrowsingInstances. The 38 // first SiteInstance we see in a BrowsingInstance is designated as the 39 // 'primary' SiteInstance, and becomes the key of this map. 40 BrowsingInstanceMap browsing_instances; 41 42 // A count of all RenderFrameHosts, which are in a different SiteInstance from 43 // their parents. 44 int out_of_process_frames = 0; 45 }; 46 47 // Maps a BrowserContext to information about the sites it contains. 48 typedef std::map<content::BrowserContext*, SiteData> BrowserContextSiteDataMap; 49 50 class SiteDetails { 51 public: 52 // Collect information about all committed sites in the given WebContents 53 // on the UI thread. 54 static void CollectSiteInfo(content::WebContents* contents, 55 SiteData* site_data); 56 57 // Updates the global histograms for tracking memory usage. 58 static void UpdateHistograms(const BrowserContextSiteDataMap& site_data_map); 59 60 private: 61 // Only static methods - never needs to be constructed. 62 SiteDetails() = delete; 63 ~SiteDetails() = delete; 64 65 DISALLOW_COPY_AND_ASSIGN(SiteDetails); 66 }; 67 68 #endif // CHROME_BROWSER_SITE_ISOLATION_SITE_DETAILS_H_ 69