| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/site_details.h" | 5 #include "chrome/browser/site_details.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
| 8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
| 9 #include "content/public/browser/render_process_host.h" | 9 #include "content/public/browser/render_process_host.h" |
| 10 #include "extensions/common/constants.h" |
| 10 | 11 |
| 11 using content::BrowserThread; | 12 using content::BrowserThread; |
| 12 using content::RenderProcessHost; | 13 using content::RenderProcessHost; |
| 13 using content::SiteInstance; | 14 using content::SiteInstance; |
| 14 using content::WebContents; | 15 using content::WebContents; |
| 15 | 16 |
| 16 SiteData::SiteData() {} | 17 namespace { |
| 18 |
| 19 bool ShouldIsolate(IsolationScenarioType policy, const GURL& site) { |
| 20 switch (policy) { |
| 21 case ISOLATE_ALL_SITES: |
| 22 return true; |
| 23 case ISOLATE_HTTPS_SITES: |
| 24 // Note: For estimation purposes "isolate https sites" is really |
| 25 // implemented as "isolate non-http sites". This means that, for example, |
| 26 // the New Tab Page gets counted as two processes under this policy, and |
| 27 // extensions are isolated as well. |
| 28 return !site.SchemeIs(url::kHttpScheme); |
| 29 case ISOLATE_EXTENSIONS: |
| 30 return site.SchemeIs(extensions::kExtensionScheme); |
| 31 } |
| 32 NOTREACHED(); |
| 33 return true; |
| 34 } |
| 35 |
| 36 } // namespace |
| 37 |
| 38 IsolationScenario::IsolationScenario() : policy(ISOLATE_ALL_SITES) {} |
| 39 |
| 40 IsolationScenario::~IsolationScenario() {} |
| 41 |
| 42 void IsolationScenario::CollectSiteInfoForScenario(SiteInstance* primary, |
| 43 const GURL& site) { |
| 44 const GURL& isolated = ShouldIsolate(policy, site) ? site : GURL("http://"); |
| 45 sites.insert(isolated); |
| 46 browsing_instance_site_map[primary->GetId()].insert(isolated); |
| 47 } |
| 48 |
| 49 SiteData::SiteData() { |
| 50 scenarios[ISOLATE_ALL_SITES].policy = ISOLATE_ALL_SITES; |
| 51 scenarios[ISOLATE_HTTPS_SITES].policy = ISOLATE_HTTPS_SITES; |
| 52 scenarios[ISOLATE_EXTENSIONS].policy = ISOLATE_EXTENSIONS; |
| 53 } |
| 17 | 54 |
| 18 SiteData::~SiteData() {} | 55 SiteData::~SiteData() {} |
| 19 | 56 |
| 20 SiteDetails::SiteDetails() {} | 57 SiteDetails::SiteDetails() {} |
| 21 | 58 |
| 22 SiteDetails::~SiteDetails() {} | 59 SiteDetails::~SiteDetails() {} |
| 23 | 60 |
| 24 void SiteDetails::CollectSiteInfo(WebContents* contents, | 61 void SiteDetails::CollectSiteInfo(WebContents* contents, |
| 25 SiteData* site_data) { | 62 SiteData* site_data) { |
| 26 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 27 content::BrowserContext* browser_context = contents->GetBrowserContext(); | 64 content::BrowserContext* browser_context = contents->GetBrowserContext(); |
| 28 | 65 |
| 29 // Find the BrowsingInstance this WebContents belongs to by iterating over | 66 // Find the BrowsingInstance this WebContents belongs to by iterating over |
| 30 // the "primary" SiteInstances of each BrowsingInstance we've seen so far. | 67 // the "primary" SiteInstances of each BrowsingInstance we've seen so far. |
| 31 SiteInstance* instance = contents->GetSiteInstance(); | 68 SiteInstance* instance = contents->GetSiteInstance(); |
| 32 SiteInstance* primary = NULL; | 69 SiteInstance* primary = NULL; |
| 33 for (size_t i = 0; i < site_data->instances.size(); ++i) { | 70 for (SiteInstance* already_collected_instance : site_data->instances) { |
| 34 if (instance->IsRelatedSiteInstance(site_data->instances[i])) { | 71 if (instance->IsRelatedSiteInstance(already_collected_instance)) { |
| 35 primary = site_data->instances[i]; | 72 primary = already_collected_instance; |
| 36 break; | 73 break; |
| 37 } | 74 } |
| 38 } | 75 } |
| 39 if (!primary) { | 76 if (!primary) { |
| 40 // Remember this as the "primary" SiteInstance of a new BrowsingInstance. | 77 // Remember this as the "primary" SiteInstance of a new BrowsingInstance. |
| 41 primary = instance; | 78 primary = instance; |
| 42 site_data->instances.push_back(instance); | 79 site_data->instances.push_back(instance); |
| 43 } | 80 } |
| 44 | 81 |
| 45 // Now keep track of how many sites we have in this BrowsingInstance (and | 82 // Now keep track of how many sites we have in this BrowsingInstance (and |
| 46 // overall), including sites in iframes. | 83 // overall), including sites in iframes. |
| 47 std::set<GURL> sites_in_tab = contents->GetSitesInTab(); | 84 for (const GURL& site : contents->GetSitesInTab()) { |
| 48 for (std::set<GURL>::iterator iter = sites_in_tab.begin(); | 85 // Make sure we don't overcount process-per-site sites, like the NTP or |
| 49 iter != sites_in_tab.end(); ++iter) { | 86 // extensions, by skipping over them if they're already logged for |
| 50 // Skip about:blank, since we won't usually give it its own process. | 87 // ISOLATE_ALL_SITES. |
| 51 // Because about:blank has no host, its site URL will be blank. | 88 if (RenderProcessHost::ShouldUseProcessPerSite(browser_context, site) && |
| 52 if (iter->is_empty()) | 89 site_data->scenarios[ISOLATE_ALL_SITES].sites.find(site) != |
| 53 continue; | 90 site_data->scenarios[ISOLATE_ALL_SITES].sites.end()) { |
| 54 | |
| 55 // Make sure we don't overcount process-per-site sites, like the NTP. | |
| 56 if (RenderProcessHost::ShouldUseProcessPerSite(browser_context, *iter) && | |
| 57 site_data->sites.find(*iter) != site_data->sites.end()) { | |
| 58 continue; | 91 continue; |
| 59 } | 92 } |
| 60 | 93 |
| 61 site_data->sites.insert(*iter); | 94 for (IsolationScenario& scenario : site_data->scenarios) { |
| 62 site_data->instance_site_map[primary->GetId()].insert(*iter); | 95 scenario.CollectSiteInfoForScenario(primary, site); |
| 63 | 96 } |
| 64 // Also keep track of how things would look if we only isolated HTTPS sites. | |
| 65 // In this model, all HTTP sites are grouped into one "http://" site. HTTPS | |
| 66 // and other schemes (e.g., chrome:) are still isolated. | |
| 67 GURL https_site = iter->SchemeIs("http") ? GURL("http://") : *iter; | |
| 68 site_data->https_sites.insert(https_site); | |
| 69 site_data->instance_https_site_map[primary->GetId()].insert(https_site); | |
| 70 } | 97 } |
| 71 } | 98 } |
| 72 | 99 |
| 73 void SiteDetails::UpdateHistograms( | 100 void SiteDetails::UpdateHistograms( |
| 74 const BrowserContextSiteDataMap& site_data_map, | 101 const BrowserContextSiteDataMap& site_data_map, |
| 75 int all_renderer_process_count, | 102 int all_renderer_process_count, |
| 76 int non_renderer_process_count) { | 103 int non_renderer_process_count) { |
| 77 // Reports a set of site-based process metrics to UMA. | 104 // Reports a set of site-based process metrics to UMA. |
| 78 int process_limit = RenderProcessHost::GetMaxRendererProcessCount(); | 105 int process_limit = RenderProcessHost::GetMaxRendererProcessCount(); |
| 79 | 106 |
| 80 // Sum the number of sites and SiteInstances in each BrowserContext. | 107 // Sum the number of sites and SiteInstances in each BrowserContext. |
| 81 int num_sites = 0; | 108 int num_sites[ISOLATION_SCENARIO_LAST + 1] = {}; |
| 82 int num_https_sites = 0; | 109 int num_isolated_site_instances[ISOLATION_SCENARIO_LAST + 1] = {}; |
| 83 int num_browsing_instances = 0; | 110 int num_browsing_instances = 0; |
| 84 int num_isolated_site_instances = 0; | |
| 85 int num_isolated_https_site_instances = 0; | |
| 86 for (BrowserContextSiteDataMap::const_iterator i = site_data_map.begin(); | 111 for (BrowserContextSiteDataMap::const_iterator i = site_data_map.begin(); |
| 87 i != site_data_map.end(); ++i) { | 112 i != site_data_map.end(); ++i) { |
| 88 num_sites += i->second.sites.size(); | 113 for (const IsolationScenario& scenario : i->second.scenarios) { |
| 89 num_https_sites += i->second.https_sites.size(); | 114 num_sites[scenario.policy] += scenario.sites.size(); |
| 90 num_browsing_instances += i->second.instance_site_map.size(); | 115 for (auto& browsing_instance : scenario.browsing_instance_site_map) { |
| 91 for (BrowsingInstanceSiteMap::const_iterator iter = | 116 num_isolated_site_instances[scenario.policy] += |
| 92 i->second.instance_site_map.begin(); | 117 browsing_instance.second.size(); |
| 93 iter != i->second.instance_site_map.end(); ++iter) { | 118 } |
| 94 num_isolated_site_instances += iter->second.size(); | |
| 95 } | 119 } |
| 96 for (BrowsingInstanceSiteMap::const_iterator iter = | 120 num_browsing_instances += i->second.scenarios[ISOLATE_ALL_SITES] |
| 97 i->second.instance_https_site_map.begin(); | 121 .browsing_instance_site_map.size(); |
| 98 iter != i->second.instance_https_site_map.end(); ++iter) { | |
| 99 num_isolated_https_site_instances += iter->second.size(); | |
| 100 } | |
| 101 } | 122 } |
| 102 | 123 |
| 103 // Predict the number of processes needed when isolating all sites and when | 124 // Predict the number of processes needed when isolating all sites, when |
| 104 // isolating only HTTPS sites. | 125 // isolating only HTTPS sites, and when isolating extensions. |
| 105 int process_count_lower_bound = num_sites; | 126 int process_count_lower_bound[ISOLATION_SCENARIO_LAST + 1]; |
| 106 int process_count_upper_bound = num_sites + process_limit - 1; | 127 int process_count_upper_bound[ISOLATION_SCENARIO_LAST + 1]; |
| 107 int process_count_estimate = std::min( | 128 int process_count_estimate[ISOLATION_SCENARIO_LAST + 1]; |
| 108 num_isolated_site_instances, process_count_upper_bound); | 129 for (int policy = 0; policy <= ISOLATION_SCENARIO_LAST; policy++) { |
| 109 | 130 process_count_lower_bound[policy] = num_sites[policy]; |
| 110 int process_count_https_lower_bound = num_https_sites; | 131 process_count_upper_bound[policy] = num_sites[policy] + process_limit - 1; |
| 111 int process_count_https_upper_bound = num_https_sites + process_limit - 1; | 132 process_count_estimate[policy] = std::min( |
| 112 int process_count_https_estimate = std::min( | 133 num_isolated_site_instances[policy], process_count_upper_bound[policy]); |
| 113 num_isolated_https_site_instances, process_count_https_upper_bound); | 134 } |
| 114 | 135 |
| 115 // Just renderer process count: | 136 // Just renderer process count: |
| 116 UMA_HISTOGRAM_COUNTS_100("SiteIsolation.CurrentRendererProcessCount", | 137 UMA_HISTOGRAM_COUNTS_100("SiteIsolation.CurrentRendererProcessCount", |
| 117 all_renderer_process_count); | 138 all_renderer_process_count); |
| 118 UMA_HISTOGRAM_COUNTS_100( | 139 UMA_HISTOGRAM_COUNTS_100( |
| 119 "SiteIsolation.BrowsingInstanceCount", | 140 "SiteIsolation.BrowsingInstanceCount", |
| 120 num_browsing_instances); | 141 num_browsing_instances); |
| 121 UMA_HISTOGRAM_COUNTS_100( | 142 UMA_HISTOGRAM_COUNTS_100("SiteIsolation.IsolateAllSitesProcessCountNoLimit", |
| 122 "SiteIsolation.IsolateAllSitesProcessCountNoLimit", | 143 num_isolated_site_instances[ISOLATE_ALL_SITES]); |
| 123 num_isolated_site_instances); | |
| 124 UMA_HISTOGRAM_COUNTS_100( | 144 UMA_HISTOGRAM_COUNTS_100( |
| 125 "SiteIsolation.IsolateAllSitesProcessCountLowerBound", | 145 "SiteIsolation.IsolateAllSitesProcessCountLowerBound", |
| 126 process_count_lower_bound); | 146 process_count_lower_bound[ISOLATE_ALL_SITES]); |
| 127 UMA_HISTOGRAM_COUNTS_100( | 147 UMA_HISTOGRAM_COUNTS_100("SiteIsolation.IsolateAllSitesProcessCountEstimate", |
| 128 "SiteIsolation.IsolateAllSitesProcessCountEstimate", | 148 process_count_estimate[ISOLATE_ALL_SITES]); |
| 129 process_count_estimate); | 149 |
| 130 UMA_HISTOGRAM_COUNTS_100( | 150 UMA_HISTOGRAM_COUNTS_100("SiteIsolation.IsolateHttpsSitesProcessCountNoLimit", |
| 131 "SiteIsolation.IsolateHttpsSitesProcessCountNoLimit", | 151 num_isolated_site_instances[ISOLATE_HTTPS_SITES]); |
| 132 num_isolated_https_site_instances); | |
| 133 UMA_HISTOGRAM_COUNTS_100( | 152 UMA_HISTOGRAM_COUNTS_100( |
| 134 "SiteIsolation.IsolateHttpsSitesProcessCountLowerBound", | 153 "SiteIsolation.IsolateHttpsSitesProcessCountLowerBound", |
| 135 process_count_https_lower_bound); | 154 process_count_lower_bound[ISOLATE_HTTPS_SITES]); |
| 136 UMA_HISTOGRAM_COUNTS_100( | 155 UMA_HISTOGRAM_COUNTS_100( |
| 137 "SiteIsolation.IsolateHttpsSitesProcessCountEstimate", | 156 "SiteIsolation.IsolateHttpsSitesProcessCountEstimate", |
| 138 process_count_https_estimate); | 157 process_count_estimate[ISOLATE_HTTPS_SITES]); |
| 158 |
| 159 UMA_HISTOGRAM_COUNTS_100("SiteIsolation.IsolateExtensionsProcessCountNoLimit", |
| 160 num_isolated_site_instances[ISOLATE_EXTENSIONS]); |
| 161 UMA_HISTOGRAM_COUNTS_100( |
| 162 "SiteIsolation.IsolateExtensionsProcessCountLowerBound", |
| 163 process_count_lower_bound[ISOLATE_EXTENSIONS]); |
| 164 UMA_HISTOGRAM_COUNTS_100( |
| 165 "SiteIsolation.IsolateExtensionsProcessCountEstimate", |
| 166 process_count_estimate[ISOLATE_EXTENSIONS]); |
| 139 | 167 |
| 140 // Total process count: | 168 // Total process count: |
| 141 UMA_HISTOGRAM_COUNTS_100( | 169 UMA_HISTOGRAM_COUNTS_100( |
| 142 "SiteIsolation.IsolateAllSitesTotalProcessCountEstimate", | 170 "SiteIsolation.IsolateAllSitesTotalProcessCountEstimate", |
| 143 process_count_estimate + non_renderer_process_count); | 171 process_count_estimate[ISOLATE_ALL_SITES] + non_renderer_process_count); |
| 144 UMA_HISTOGRAM_COUNTS_100( | 172 UMA_HISTOGRAM_COUNTS_100( |
| 145 "SiteIsolation.IsolateHttpsSitesTotalProcessCountEstimate", | 173 "SiteIsolation.IsolateHttpsSitesTotalProcessCountEstimate", |
| 146 process_count_https_estimate + non_renderer_process_count); | 174 process_count_estimate[ISOLATE_HTTPS_SITES] + non_renderer_process_count); |
| 175 UMA_HISTOGRAM_COUNTS_100( |
| 176 "SiteIsolation.IsolateExtensionsTotalProcessCountEstimate", |
| 177 process_count_estimate[ISOLATE_EXTENSIONS] + non_renderer_process_count); |
| 147 } | 178 } |
| OLD | NEW |