| 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_frame_host.h" | 9 #include "content/public/browser/render_frame_host.h" |
| 10 #include "content/public/browser/render_process_host.h" | 10 #include "content/public/browser/render_process_host.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 | 98 |
| 99 // We model process-per-site by only inserting those sites into the first | 99 // We model process-per-site by only inserting those sites into the first |
| 100 // browsing instance in which they appear. | 100 // browsing instance in which they appear. |
| 101 if (scenario->sites.insert(site).second || !process_per_site) | 101 if (scenario->sites.insert(site).second || !process_per_site) |
| 102 scenario->browsing_instance_site_map[primary->GetId()].insert(site); | 102 scenario->browsing_instance_site_map[primary->GetId()].insert(site); |
| 103 | 103 |
| 104 // Record our result in |frame_urls| for use by children. | 104 // Record our result in |frame_urls| for use by children. |
| 105 (*frame_urls)[frame] = site; | 105 (*frame_urls)[frame] = site; |
| 106 } | 106 } |
| 107 | 107 |
| 108 content::SiteInstance* DeterminePrimarySiteInstance( |
| 109 content::SiteInstance* instance, |
| 110 SiteData* site_data) { |
| 111 // Find the BrowsingInstance this WebContents belongs to by iterating over |
| 112 // the "primary" SiteInstances of each BrowsingInstance we've seen so far. |
| 113 for (auto& existing_site_instance : site_data->instances) { |
| 114 if (instance->IsRelatedSiteInstance(existing_site_instance.first)) { |
| 115 existing_site_instance.second.insert(instance); |
| 116 return existing_site_instance.first; |
| 117 } |
| 118 } |
| 119 |
| 120 // Add |instance| as the "primary" SiteInstance of a new BrowsingInstance. |
| 121 site_data->instances[instance].clear(); |
| 122 site_data->instances[instance].insert(instance); |
| 123 |
| 124 return instance; |
| 125 } |
| 126 |
| 108 void CollectCurrentSnapshot(SiteData* site_data, RenderFrameHost* frame) { | 127 void CollectCurrentSnapshot(SiteData* site_data, RenderFrameHost* frame) { |
| 109 if (frame->GetParent()) { | 128 if (frame->GetParent()) { |
| 110 if (frame->GetSiteInstance() != frame->GetParent()->GetSiteInstance()) | 129 if (frame->GetSiteInstance() != frame->GetParent()->GetSiteInstance()) |
| 111 site_data->out_of_process_frames++; | 130 site_data->out_of_process_frames++; |
| 112 } | 131 } |
| 132 |
| 133 DeterminePrimarySiteInstance(frame->GetSiteInstance(), site_data); |
| 113 } | 134 } |
| 114 | 135 |
| 115 } // namespace | 136 } // namespace |
| 116 | 137 |
| 117 IsolationScenario::IsolationScenario() : policy(ISOLATE_ALL_SITES) {} | 138 IsolationScenario::IsolationScenario() : policy(ISOLATE_ALL_SITES) {} |
| 118 | 139 |
| 119 IsolationScenario::~IsolationScenario() {} | 140 IsolationScenario::~IsolationScenario() {} |
| 120 | 141 |
| 121 SiteData::SiteData() : out_of_process_frames(0) { | 142 SiteData::SiteData() : out_of_process_frames(0) { |
| 122 for (int i = 0; i <= ISOLATION_SCENARIO_LAST; i++) | 143 for (int i = 0; i <= ISOLATION_SCENARIO_LAST; i++) |
| 123 scenarios[i].policy = static_cast<IsolationScenarioType>(i); | 144 scenarios[i].policy = static_cast<IsolationScenarioType>(i); |
| 124 } | 145 } |
| 125 | 146 |
| 126 SiteData::~SiteData() {} | 147 SiteData::~SiteData() {} |
| 127 | 148 |
| 128 SiteDetails::SiteDetails() {} | 149 SiteDetails::SiteDetails() {} |
| 129 | 150 |
| 130 SiteDetails::~SiteDetails() {} | 151 SiteDetails::~SiteDetails() {} |
| 131 | 152 |
| 132 void SiteDetails::CollectSiteInfo(WebContents* contents, | 153 void SiteDetails::CollectSiteInfo(WebContents* contents, |
| 133 SiteData* site_data) { | 154 SiteData* site_data) { |
| 134 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 155 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 135 // Find the BrowsingInstance this WebContents belongs to by iterating over | 156 SiteInstance* primary = |
| 136 // the "primary" SiteInstances of each BrowsingInstance we've seen so far. | 157 DeterminePrimarySiteInstance(contents->GetSiteInstance(), site_data); |
| 137 SiteInstance* instance = contents->GetSiteInstance(); | |
| 138 SiteInstance* primary = NULL; | |
| 139 for (SiteInstance* already_collected_instance : site_data->instances) { | |
| 140 if (instance->IsRelatedSiteInstance(already_collected_instance)) { | |
| 141 primary = already_collected_instance; | |
| 142 break; | |
| 143 } | |
| 144 } | |
| 145 if (!primary) { | |
| 146 // Remember this as the "primary" SiteInstance of a new BrowsingInstance. | |
| 147 primary = instance; | |
| 148 site_data->instances.push_back(instance); | |
| 149 } | |
| 150 | 158 |
| 151 // Now keep track of how many sites we have in this BrowsingInstance (and | 159 // Now keep track of how many sites we have in this BrowsingInstance (and |
| 152 // overall), including sites in iframes. | 160 // overall), including sites in iframes. |
| 153 for (IsolationScenario& scenario : site_data->scenarios) { | 161 for (IsolationScenario& scenario : site_data->scenarios) { |
| 154 std::map<RenderFrameHost*, GURL> memo; | 162 std::map<RenderFrameHost*, GURL> memo; |
| 155 contents->ForEachFrame( | 163 contents->ForEachFrame( |
| 156 base::Bind(&CollectForScenario, base::Unretained(&memo), | 164 base::Bind(&CollectForScenario, base::Unretained(&memo), |
| 157 base::Unretained(primary), base::Unretained(&scenario))); | 165 base::Unretained(primary), base::Unretained(&scenario))); |
| 158 } | 166 } |
| 159 | 167 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 178 i != site_data_map.end(); ++i) { | 186 i != site_data_map.end(); ++i) { |
| 179 for (const IsolationScenario& scenario : i->second.scenarios) { | 187 for (const IsolationScenario& scenario : i->second.scenarios) { |
| 180 num_sites[scenario.policy] += scenario.sites.size(); | 188 num_sites[scenario.policy] += scenario.sites.size(); |
| 181 for (auto& browsing_instance : scenario.browsing_instance_site_map) { | 189 for (auto& browsing_instance : scenario.browsing_instance_site_map) { |
| 182 num_isolated_site_instances[scenario.policy] += | 190 num_isolated_site_instances[scenario.policy] += |
| 183 browsing_instance.second.size(); | 191 browsing_instance.second.size(); |
| 184 } | 192 } |
| 185 } | 193 } |
| 186 num_browsing_instances += i->second.scenarios[ISOLATE_ALL_SITES] | 194 num_browsing_instances += i->second.scenarios[ISOLATE_ALL_SITES] |
| 187 .browsing_instance_site_map.size(); | 195 .browsing_instance_site_map.size(); |
| 196 for (const auto& site_instance : i->second.instances) { |
| 197 UMA_HISTOGRAM_COUNTS_100("SiteIsolation.SiteInstancesPerBrowsingInstance", |
| 198 site_instance.second.size()); |
| 199 } |
| 188 num_oopifs += i->second.out_of_process_frames; | 200 num_oopifs += i->second.out_of_process_frames; |
| 189 } | 201 } |
| 190 | 202 |
| 191 // Predict the number of processes needed when isolating all sites, when | 203 // Predict the number of processes needed when isolating all sites, when |
| 192 // isolating only HTTPS sites, and when isolating extensions. | 204 // isolating only HTTPS sites, and when isolating extensions. |
| 193 int process_count_lower_bound[ISOLATION_SCENARIO_LAST + 1]; | 205 int process_count_lower_bound[ISOLATION_SCENARIO_LAST + 1]; |
| 194 int process_count_upper_bound[ISOLATION_SCENARIO_LAST + 1]; | 206 int process_count_upper_bound[ISOLATION_SCENARIO_LAST + 1]; |
| 195 int process_count_estimate[ISOLATION_SCENARIO_LAST + 1]; | 207 int process_count_estimate[ISOLATION_SCENARIO_LAST + 1]; |
| 196 for (int policy = 0; policy <= ISOLATION_SCENARIO_LAST; policy++) { | 208 for (int policy = 0; policy <= ISOLATION_SCENARIO_LAST; policy++) { |
| 197 process_count_lower_bound[policy] = num_sites[policy]; | 209 process_count_lower_bound[policy] = num_sites[policy]; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 UMA_HISTOGRAM_COUNTS_100( | 262 UMA_HISTOGRAM_COUNTS_100( |
| 251 "SiteIsolation.IsolateExtensionsProcessCountLowerBound", | 263 "SiteIsolation.IsolateExtensionsProcessCountLowerBound", |
| 252 process_count_lower_bound[ISOLATE_EXTENSIONS]); | 264 process_count_lower_bound[ISOLATE_EXTENSIONS]); |
| 253 UMA_HISTOGRAM_COUNTS_100( | 265 UMA_HISTOGRAM_COUNTS_100( |
| 254 "SiteIsolation.IsolateExtensionsProcessCountEstimate", | 266 "SiteIsolation.IsolateExtensionsProcessCountEstimate", |
| 255 process_count_estimate[ISOLATE_EXTENSIONS]); | 267 process_count_estimate[ISOLATE_EXTENSIONS]); |
| 256 UMA_HISTOGRAM_COUNTS_100( | 268 UMA_HISTOGRAM_COUNTS_100( |
| 257 "SiteIsolation.IsolateExtensionsTotalProcessCountEstimate", | 269 "SiteIsolation.IsolateExtensionsTotalProcessCountEstimate", |
| 258 process_count_estimate[ISOLATE_EXTENSIONS] + non_renderer_process_count); | 270 process_count_estimate[ISOLATE_EXTENSIONS] + non_renderer_process_count); |
| 259 } | 271 } |
| OLD | NEW |