Chromium Code Reviews| 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/containers/hash_tables.h" | |
|
ncarter (slow)
2015/12/02 18:16:49
This #include belongs in the .h file.
nasko
2015/12/02 19:06:56
Done.
| |
| 7 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 8 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
| 9 #include "content/public/browser/render_frame_host.h" | 10 #include "content/public/browser/render_frame_host.h" |
| 10 #include "content/public/browser/render_process_host.h" | 11 #include "content/public/browser/render_process_host.h" |
| 11 | 12 |
| 12 #if defined(ENABLE_EXTENSIONS) | 13 #if defined(ENABLE_EXTENSIONS) |
| 13 #include "extensions/browser/extension_registry.h" | 14 #include "extensions/browser/extension_registry.h" |
| 14 #include "extensions/common/constants.h" | 15 #include "extensions/common/constants.h" |
| 15 #include "extensions/common/extension.h" | 16 #include "extensions/common/extension.h" |
| 16 #endif | 17 #endif |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 | 99 |
| 99 // We model process-per-site by only inserting those sites into the first | 100 // We model process-per-site by only inserting those sites into the first |
| 100 // browsing instance in which they appear. | 101 // browsing instance in which they appear. |
| 101 if (scenario->sites.insert(site).second || !process_per_site) | 102 if (scenario->sites.insert(site).second || !process_per_site) |
| 102 scenario->browsing_instance_site_map[primary->GetId()].insert(site); | 103 scenario->browsing_instance_site_map[primary->GetId()].insert(site); |
| 103 | 104 |
| 104 // Record our result in |frame_urls| for use by children. | 105 // Record our result in |frame_urls| for use by children. |
| 105 (*frame_urls)[frame] = site; | 106 (*frame_urls)[frame] = site; |
| 106 } | 107 } |
| 107 | 108 |
| 109 content::SiteInstance* DeterminePrimarySiteInstance( | |
| 110 content::SiteInstance* instance, | |
| 111 SiteData* site_data) { | |
| 112 // Find the BrowsingInstance this WebContents belongs to by iterating over | |
| 113 // the "primary" SiteInstances of each BrowsingInstance we've seen so far. | |
| 114 SiteInstance* primary = nullptr; | |
| 115 for (auto& already_collected_instance : site_data->instances) { | |
| 116 if (instance->IsRelatedSiteInstance(already_collected_instance.first)) { | |
| 117 primary = already_collected_instance.first; | |
| 118 already_collected_instance.second.insert(instance); | |
| 119 break; | |
|
ncarter (slow)
2015/12/02 18:16:49
Just return here. That'll let you get rid of the |
nasko
2015/12/02 19:06:56
Done.
| |
| 120 } | |
| 121 } | |
| 122 if (!primary) { | |
| 123 // Remember this as the "primary" SiteInstance of a new BrowsingInstance. | |
| 124 primary = instance; | |
| 125 site_data->instances.insert( | |
| 126 std::make_pair(instance, std::set<SiteInstance*>())); | |
|
ncarter (slow)
2015/12/02 18:16:49
Shouldn't the new std::set contain |instance| init
nasko
2015/12/02 19:06:56
Acknowledged.
| |
| 127 } | |
| 128 | |
| 129 return primary; | |
| 130 } | |
| 131 | |
| 108 void CollectCurrentSnapshot(SiteData* site_data, RenderFrameHost* frame) { | 132 void CollectCurrentSnapshot(SiteData* site_data, RenderFrameHost* frame) { |
| 109 if (frame->GetParent()) { | 133 if (frame->GetParent()) { |
| 110 if (frame->GetSiteInstance() != frame->GetParent()->GetSiteInstance()) | 134 if (frame->GetSiteInstance() != frame->GetParent()->GetSiteInstance()) |
| 111 site_data->out_of_process_frames++; | 135 site_data->out_of_process_frames++; |
| 112 } | 136 } |
| 137 | |
| 138 DeterminePrimarySiteInstance(frame->GetSiteInstance(), site_data); | |
|
ncarter (slow)
2015/12/02 18:16:49
We've already determined the primary site instance
nasko
2015/12/02 19:06:56
Unfortunately not. Due to crbug.com/522302 not all
| |
| 113 } | 139 } |
| 114 | 140 |
| 115 } // namespace | 141 } // namespace |
| 116 | 142 |
| 117 IsolationScenario::IsolationScenario() : policy(ISOLATE_ALL_SITES) {} | 143 IsolationScenario::IsolationScenario() : policy(ISOLATE_ALL_SITES) {} |
| 118 | 144 |
| 119 IsolationScenario::~IsolationScenario() {} | 145 IsolationScenario::~IsolationScenario() {} |
| 120 | 146 |
| 121 SiteData::SiteData() : out_of_process_frames(0) { | 147 SiteData::SiteData() : out_of_process_frames(0) { |
| 122 for (int i = 0; i <= ISOLATION_SCENARIO_LAST; i++) | 148 for (int i = 0; i <= ISOLATION_SCENARIO_LAST; i++) |
| 123 scenarios[i].policy = static_cast<IsolationScenarioType>(i); | 149 scenarios[i].policy = static_cast<IsolationScenarioType>(i); |
| 124 } | 150 } |
| 125 | 151 |
| 126 SiteData::~SiteData() {} | 152 SiteData::~SiteData() {} |
| 127 | 153 |
| 128 SiteDetails::SiteDetails() {} | 154 SiteDetails::SiteDetails() {} |
| 129 | 155 |
| 130 SiteDetails::~SiteDetails() {} | 156 SiteDetails::~SiteDetails() {} |
| 131 | 157 |
| 132 void SiteDetails::CollectSiteInfo(WebContents* contents, | 158 void SiteDetails::CollectSiteInfo(WebContents* contents, |
| 133 SiteData* site_data) { | 159 SiteData* site_data) { |
| 134 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 160 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 135 // Find the BrowsingInstance this WebContents belongs to by iterating over | 161 SiteInstance* primary = |
| 136 // the "primary" SiteInstances of each BrowsingInstance we've seen so far. | 162 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 | 163 |
| 151 // Now keep track of how many sites we have in this BrowsingInstance (and | 164 // Now keep track of how many sites we have in this BrowsingInstance (and |
| 152 // overall), including sites in iframes. | 165 // overall), including sites in iframes. |
| 153 for (IsolationScenario& scenario : site_data->scenarios) { | 166 for (IsolationScenario& scenario : site_data->scenarios) { |
| 154 std::map<RenderFrameHost*, GURL> memo; | 167 std::map<RenderFrameHost*, GURL> memo; |
| 155 contents->ForEachFrame( | 168 contents->ForEachFrame( |
| 156 base::Bind(&CollectForScenario, base::Unretained(&memo), | 169 base::Bind(&CollectForScenario, base::Unretained(&memo), |
| 157 base::Unretained(primary), base::Unretained(&scenario))); | 170 base::Unretained(primary), base::Unretained(&scenario))); |
| 158 } | 171 } |
| 159 | 172 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 178 i != site_data_map.end(); ++i) { | 191 i != site_data_map.end(); ++i) { |
| 179 for (const IsolationScenario& scenario : i->second.scenarios) { | 192 for (const IsolationScenario& scenario : i->second.scenarios) { |
| 180 num_sites[scenario.policy] += scenario.sites.size(); | 193 num_sites[scenario.policy] += scenario.sites.size(); |
| 181 for (auto& browsing_instance : scenario.browsing_instance_site_map) { | 194 for (auto& browsing_instance : scenario.browsing_instance_site_map) { |
| 182 num_isolated_site_instances[scenario.policy] += | 195 num_isolated_site_instances[scenario.policy] += |
| 183 browsing_instance.second.size(); | 196 browsing_instance.second.size(); |
| 184 } | 197 } |
| 185 } | 198 } |
| 186 num_browsing_instances += i->second.scenarios[ISOLATE_ALL_SITES] | 199 num_browsing_instances += i->second.scenarios[ISOLATE_ALL_SITES] |
| 187 .browsing_instance_site_map.size(); | 200 .browsing_instance_site_map.size(); |
| 201 for (const auto& site : i->second.instances) { | |
| 202 UMA_HISTOGRAM_COUNTS_100("SiteIsolation.SiteInstancesPerBrowsingInstance", | |
| 203 site.second.size()); | |
| 204 } | |
| 188 num_oopifs += i->second.out_of_process_frames; | 205 num_oopifs += i->second.out_of_process_frames; |
| 189 } | 206 } |
| 190 | 207 |
| 191 // Predict the number of processes needed when isolating all sites, when | 208 // Predict the number of processes needed when isolating all sites, when |
| 192 // isolating only HTTPS sites, and when isolating extensions. | 209 // isolating only HTTPS sites, and when isolating extensions. |
| 193 int process_count_lower_bound[ISOLATION_SCENARIO_LAST + 1]; | 210 int process_count_lower_bound[ISOLATION_SCENARIO_LAST + 1]; |
| 194 int process_count_upper_bound[ISOLATION_SCENARIO_LAST + 1]; | 211 int process_count_upper_bound[ISOLATION_SCENARIO_LAST + 1]; |
| 195 int process_count_estimate[ISOLATION_SCENARIO_LAST + 1]; | 212 int process_count_estimate[ISOLATION_SCENARIO_LAST + 1]; |
| 196 for (int policy = 0; policy <= ISOLATION_SCENARIO_LAST; policy++) { | 213 for (int policy = 0; policy <= ISOLATION_SCENARIO_LAST; policy++) { |
| 197 process_count_lower_bound[policy] = num_sites[policy]; | 214 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( | 267 UMA_HISTOGRAM_COUNTS_100( |
| 251 "SiteIsolation.IsolateExtensionsProcessCountLowerBound", | 268 "SiteIsolation.IsolateExtensionsProcessCountLowerBound", |
| 252 process_count_lower_bound[ISOLATE_EXTENSIONS]); | 269 process_count_lower_bound[ISOLATE_EXTENSIONS]); |
| 253 UMA_HISTOGRAM_COUNTS_100( | 270 UMA_HISTOGRAM_COUNTS_100( |
| 254 "SiteIsolation.IsolateExtensionsProcessCountEstimate", | 271 "SiteIsolation.IsolateExtensionsProcessCountEstimate", |
| 255 process_count_estimate[ISOLATE_EXTENSIONS]); | 272 process_count_estimate[ISOLATE_EXTENSIONS]); |
| 256 UMA_HISTOGRAM_COUNTS_100( | 273 UMA_HISTOGRAM_COUNTS_100( |
| 257 "SiteIsolation.IsolateExtensionsTotalProcessCountEstimate", | 274 "SiteIsolation.IsolateExtensionsTotalProcessCountEstimate", |
| 258 process_count_estimate[ISOLATE_EXTENSIONS] + non_renderer_process_count); | 275 process_count_estimate[ISOLATE_EXTENSIONS] + non_renderer_process_count); |
| 259 } | 276 } |
| OLD | NEW |