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& already_collected_instance : site_data->instances) { | |
sky
2015/12/03 00:04:05
nit: already_collected_instance is a bit confusing
nasko
2015/12/03 01:36:57
Yes, it is a pair, but it is the SiteInstance and
| |
114 if (instance->IsRelatedSiteInstance(already_collected_instance.first)) { | |
115 already_collected_instance.second.insert(instance); | |
116 return already_collected_instance.first; | |
117 } | |
118 } | |
119 | |
120 // Add this as the "primary" SiteInstance of a new BrowsingInstance. | |
121 std::pair<SiteInstanceMap::iterator, bool> result = | |
122 site_data->instances.insert( | |
123 std::make_pair(instance, std::set<SiteInstance*>())); | |
124 | |
125 // Also include it in the set of all SiteInstances for the BrowsingInstance. | |
126 result.first->second.insert(instance); | |
sky
2015/12/03 00:04:05
Unless I'm missing something, isn't what you have
nasko
2015/12/03 01:36:57
Done.
| |
127 | |
128 return instance; | |
129 } | |
130 | |
108 void CollectCurrentSnapshot(SiteData* site_data, RenderFrameHost* frame) { | 131 void CollectCurrentSnapshot(SiteData* site_data, RenderFrameHost* frame) { |
109 if (frame->GetParent()) { | 132 if (frame->GetParent()) { |
110 if (frame->GetSiteInstance() != frame->GetParent()->GetSiteInstance()) | 133 if (frame->GetSiteInstance() != frame->GetParent()->GetSiteInstance()) |
111 site_data->out_of_process_frames++; | 134 site_data->out_of_process_frames++; |
112 } | 135 } |
136 | |
137 DeterminePrimarySiteInstance(frame->GetSiteInstance(), site_data); | |
113 } | 138 } |
114 | 139 |
115 } // namespace | 140 } // namespace |
116 | 141 |
117 IsolationScenario::IsolationScenario() : policy(ISOLATE_ALL_SITES) {} | 142 IsolationScenario::IsolationScenario() : policy(ISOLATE_ALL_SITES) {} |
118 | 143 |
119 IsolationScenario::~IsolationScenario() {} | 144 IsolationScenario::~IsolationScenario() {} |
120 | 145 |
121 SiteData::SiteData() : out_of_process_frames(0) { | 146 SiteData::SiteData() : out_of_process_frames(0) { |
122 for (int i = 0; i <= ISOLATION_SCENARIO_LAST; i++) | 147 for (int i = 0; i <= ISOLATION_SCENARIO_LAST; i++) |
123 scenarios[i].policy = static_cast<IsolationScenarioType>(i); | 148 scenarios[i].policy = static_cast<IsolationScenarioType>(i); |
124 } | 149 } |
125 | 150 |
126 SiteData::~SiteData() {} | 151 SiteData::~SiteData() {} |
127 | 152 |
128 SiteDetails::SiteDetails() {} | 153 SiteDetails::SiteDetails() {} |
129 | 154 |
130 SiteDetails::~SiteDetails() {} | 155 SiteDetails::~SiteDetails() {} |
131 | 156 |
132 void SiteDetails::CollectSiteInfo(WebContents* contents, | 157 void SiteDetails::CollectSiteInfo(WebContents* contents, |
133 SiteData* site_data) { | 158 SiteData* site_data) { |
134 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 159 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
135 // Find the BrowsingInstance this WebContents belongs to by iterating over | 160 SiteInstance* primary = |
136 // the "primary" SiteInstances of each BrowsingInstance we've seen so far. | 161 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 | 162 |
151 // Now keep track of how many sites we have in this BrowsingInstance (and | 163 // Now keep track of how many sites we have in this BrowsingInstance (and |
152 // overall), including sites in iframes. | 164 // overall), including sites in iframes. |
153 for (IsolationScenario& scenario : site_data->scenarios) { | 165 for (IsolationScenario& scenario : site_data->scenarios) { |
154 std::map<RenderFrameHost*, GURL> memo; | 166 std::map<RenderFrameHost*, GURL> memo; |
155 contents->ForEachFrame( | 167 contents->ForEachFrame( |
156 base::Bind(&CollectForScenario, base::Unretained(&memo), | 168 base::Bind(&CollectForScenario, base::Unretained(&memo), |
157 base::Unretained(primary), base::Unretained(&scenario))); | 169 base::Unretained(primary), base::Unretained(&scenario))); |
158 } | 170 } |
159 | 171 |
(...skipping 18 matching lines...) Expand all Loading... | |
178 i != site_data_map.end(); ++i) { | 190 i != site_data_map.end(); ++i) { |
179 for (const IsolationScenario& scenario : i->second.scenarios) { | 191 for (const IsolationScenario& scenario : i->second.scenarios) { |
180 num_sites[scenario.policy] += scenario.sites.size(); | 192 num_sites[scenario.policy] += scenario.sites.size(); |
181 for (auto& browsing_instance : scenario.browsing_instance_site_map) { | 193 for (auto& browsing_instance : scenario.browsing_instance_site_map) { |
182 num_isolated_site_instances[scenario.policy] += | 194 num_isolated_site_instances[scenario.policy] += |
183 browsing_instance.second.size(); | 195 browsing_instance.second.size(); |
184 } | 196 } |
185 } | 197 } |
186 num_browsing_instances += i->second.scenarios[ISOLATE_ALL_SITES] | 198 num_browsing_instances += i->second.scenarios[ISOLATE_ALL_SITES] |
187 .browsing_instance_site_map.size(); | 199 .browsing_instance_site_map.size(); |
200 for (const auto& site : i->second.instances) { | |
sky
2015/12/03 00:04:05
Above you call 'site' 'already_collected_instance'
nasko
2015/12/03 01:36:57
Changed to be more consistent.
| |
201 UMA_HISTOGRAM_COUNTS_100("SiteIsolation.SiteInstancesPerBrowsingInstance", | |
202 site.second.size()); | |
203 } | |
188 num_oopifs += i->second.out_of_process_frames; | 204 num_oopifs += i->second.out_of_process_frames; |
189 } | 205 } |
190 | 206 |
191 // Predict the number of processes needed when isolating all sites, when | 207 // Predict the number of processes needed when isolating all sites, when |
192 // isolating only HTTPS sites, and when isolating extensions. | 208 // isolating only HTTPS sites, and when isolating extensions. |
193 int process_count_lower_bound[ISOLATION_SCENARIO_LAST + 1]; | 209 int process_count_lower_bound[ISOLATION_SCENARIO_LAST + 1]; |
194 int process_count_upper_bound[ISOLATION_SCENARIO_LAST + 1]; | 210 int process_count_upper_bound[ISOLATION_SCENARIO_LAST + 1]; |
195 int process_count_estimate[ISOLATION_SCENARIO_LAST + 1]; | 211 int process_count_estimate[ISOLATION_SCENARIO_LAST + 1]; |
196 for (int policy = 0; policy <= ISOLATION_SCENARIO_LAST; policy++) { | 212 for (int policy = 0; policy <= ISOLATION_SCENARIO_LAST; policy++) { |
197 process_count_lower_bound[policy] = num_sites[policy]; | 213 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( | 266 UMA_HISTOGRAM_COUNTS_100( |
251 "SiteIsolation.IsolateExtensionsProcessCountLowerBound", | 267 "SiteIsolation.IsolateExtensionsProcessCountLowerBound", |
252 process_count_lower_bound[ISOLATE_EXTENSIONS]); | 268 process_count_lower_bound[ISOLATE_EXTENSIONS]); |
253 UMA_HISTOGRAM_COUNTS_100( | 269 UMA_HISTOGRAM_COUNTS_100( |
254 "SiteIsolation.IsolateExtensionsProcessCountEstimate", | 270 "SiteIsolation.IsolateExtensionsProcessCountEstimate", |
255 process_count_estimate[ISOLATE_EXTENSIONS]); | 271 process_count_estimate[ISOLATE_EXTENSIONS]); |
256 UMA_HISTOGRAM_COUNTS_100( | 272 UMA_HISTOGRAM_COUNTS_100( |
257 "SiteIsolation.IsolateExtensionsTotalProcessCountEstimate", | 273 "SiteIsolation.IsolateExtensionsTotalProcessCountEstimate", |
258 process_count_estimate[ISOLATE_EXTENSIONS] + non_renderer_process_count); | 274 process_count_estimate[ISOLATE_EXTENSIONS] + non_renderer_process_count); |
259 } | 275 } |
OLD | NEW |