OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/browser/browsing_instance.h" | 5 #include "content/browser/browsing_instance.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "content/browser/content_browser_client.h" | 10 #include "content/browser/content_browser_client.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 | 52 |
53 BrowsingInstance::SiteInstanceMap* BrowsingInstance::GetSiteInstanceMap( | 53 BrowsingInstance::SiteInstanceMap* BrowsingInstance::GetSiteInstanceMap( |
54 Profile* profile, const GURL& url) { | 54 Profile* profile, const GURL& url) { |
55 if (!ShouldUseProcessPerSite(SiteInstance::GetEffectiveURL(profile, url))) { | 55 if (!ShouldUseProcessPerSite(SiteInstance::GetEffectiveURL(profile, url))) { |
56 // Not using process-per-site, so use a map specific to this instance. | 56 // Not using process-per-site, so use a map specific to this instance. |
57 return &site_instance_map_; | 57 return &site_instance_map_; |
58 } | 58 } |
59 | 59 |
60 // Otherwise, process-per-site is in use, at least for this URL. Look up the | 60 // Otherwise, process-per-site is in use, at least for this URL. Look up the |
61 // global map for this profile, creating an entry if necessary. | 61 // global map for this profile, creating an entry if necessary. |
62 ProfileId runtime_id = profile ? profile->GetRuntimeId() | 62 return &profile_site_instance_map_[profile]; |
63 : Profile::kInvalidProfileId; | |
64 return &profile_site_instance_map_[runtime_id]; | |
65 } | 63 } |
66 | 64 |
67 bool BrowsingInstance::HasSiteInstance(const GURL& url) { | 65 bool BrowsingInstance::HasSiteInstance(const GURL& url) { |
68 std::string site = | 66 std::string site = |
69 SiteInstance::GetSiteForURL(profile_, url).possibly_invalid_spec(); | 67 SiteInstance::GetSiteForURL(profile_, url).possibly_invalid_spec(); |
70 | 68 |
71 SiteInstanceMap* map = GetSiteInstanceMap(profile_, url); | 69 SiteInstanceMap* map = GetSiteInstanceMap(profile_, url); |
72 SiteInstanceMap::iterator i = map->find(site); | 70 SiteInstanceMap::iterator i = map->find(site); |
73 return (i != map->end()); | 71 return (i != map->end()); |
74 } | 72 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 // comments in RegisterSiteInstance.) | 117 // comments in RegisterSiteInstance.) |
120 | 118 |
121 // We look for the site instance in both the local site_instance_map_ and also | 119 // We look for the site instance in both the local site_instance_map_ and also |
122 // the static profile_site_instance_map_ - this is because the logic in | 120 // the static profile_site_instance_map_ - this is because the logic in |
123 // ShouldUseProcessPerSite() can produce different results over the lifetime | 121 // ShouldUseProcessPerSite() can produce different results over the lifetime |
124 // of Chrome (e.g. installation of apps with web extents can change our | 122 // of Chrome (e.g. installation of apps with web extents can change our |
125 // process-per-site policy for a given domain), so we don't know which map | 123 // process-per-site policy for a given domain), so we don't know which map |
126 // the site was put into when it was originally registered. | 124 // the site was put into when it was originally registered. |
127 if (!RemoveSiteInstanceFromMap(&site_instance_map_, site, site_instance)) { | 125 if (!RemoveSiteInstanceFromMap(&site_instance_map_, site, site_instance)) { |
128 // Wasn't in our local map, so look in the static per-profile map. | 126 // Wasn't in our local map, so look in the static per-profile map. |
129 ProfileId runtime_id = profile_ ? profile_->GetRuntimeId() | |
130 : Profile::kInvalidProfileId; | |
131 RemoveSiteInstanceFromMap( | 127 RemoveSiteInstanceFromMap( |
132 &profile_site_instance_map_[runtime_id], site, site_instance); | 128 &profile_site_instance_map_[profile_], site, site_instance); |
133 } | 129 } |
134 } | 130 } |
135 | 131 |
136 bool BrowsingInstance::RemoveSiteInstanceFromMap(SiteInstanceMap* map, | 132 bool BrowsingInstance::RemoveSiteInstanceFromMap(SiteInstanceMap* map, |
137 const std::string& site, | 133 const std::string& site, |
138 SiteInstance* site_instance) { | 134 SiteInstance* site_instance) { |
139 SiteInstanceMap::iterator i = map->find(site); | 135 SiteInstanceMap::iterator i = map->find(site); |
140 if (i != map->end() && i->second == site_instance) { | 136 if (i != map->end() && i->second == site_instance) { |
141 // Matches, so erase it. | 137 // Matches, so erase it. |
142 map->erase(i); | 138 map->erase(i); |
143 return true; | 139 return true; |
144 } | 140 } |
145 return false; | 141 return false; |
146 } | 142 } |
147 | 143 |
148 BrowsingInstance::~BrowsingInstance() { | 144 BrowsingInstance::~BrowsingInstance() { |
149 // We should only be deleted when all of the SiteInstances that refer to | 145 // We should only be deleted when all of the SiteInstances that refer to |
150 // us are gone. | 146 // us are gone. |
151 DCHECK(site_instance_map_.empty()); | 147 DCHECK(site_instance_map_.empty()); |
152 } | 148 } |
OLD | NEW |