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