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