Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Side by Side Diff: content/browser/browsing_instance.cc

Issue 8493016: content: Remove 16 exit time destructors and 15 static initializers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: mac compile Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/browsing_instance.h ('k') | content/browser/debugger/devtools_agent_host.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "content/browser/browser_context.h" 9 #include "content/browser/browser_context.h"
10 #include "content/browser/site_instance.h" 10 #include "content/browser/site_instance.h"
11 #include "content/browser/webui/web_ui_factory.h" 11 #include "content/browser/webui/web_ui_factory.h"
12 #include "content/public/browser/content_browser_client.h" 12 #include "content/public/browser/content_browser_client.h"
13 #include "content/public/common/content_switches.h" 13 #include "content/public/common/content_switches.h"
14 #include "content/public/common/url_constants.h" 14 #include "content/public/common/url_constants.h"
15 15
16 // static 16 // static
17 BrowsingInstance::ContextSiteInstanceMap 17 base::LazyInstance<
18 BrowsingInstance::context_site_instance_map_; 18 BrowsingInstance::ContextSiteInstanceMap,
19 base::LeakyLazyInstanceTraits<BrowsingInstance::ContextSiteInstanceMap> >
20 BrowsingInstance::context_site_instance_map_(base::LINKER_INITIALIZED);
19 21
20 BrowsingInstance::BrowsingInstance(content::BrowserContext* browser_context) 22 BrowsingInstance::BrowsingInstance(content::BrowserContext* browser_context)
21 : browser_context_(browser_context) { 23 : browser_context_(browser_context) {
22 } 24 }
23 25
24 bool BrowsingInstance::ShouldUseProcessPerSite(const GURL& url) { 26 bool BrowsingInstance::ShouldUseProcessPerSite(const GURL& url) {
25 // Returns true if we should use the process-per-site model. This will be 27 // Returns true if we should use the process-per-site model. This will be
26 // the case if the --process-per-site switch is specified, or in 28 // the case if the --process-per-site switch is specified, or in
27 // process-per-site-instance for particular sites (e.g., the new tab page). 29 // process-per-site-instance for particular sites (e.g., the new tab page).
28 30
(...skipping 24 matching lines...) Expand all
53 BrowsingInstance::SiteInstanceMap* BrowsingInstance::GetSiteInstanceMap( 55 BrowsingInstance::SiteInstanceMap* BrowsingInstance::GetSiteInstanceMap(
54 content::BrowserContext* browser_context, const GURL& url) { 56 content::BrowserContext* browser_context, const GURL& url) {
55 if (!ShouldUseProcessPerSite(SiteInstance::GetEffectiveURL(browser_context, 57 if (!ShouldUseProcessPerSite(SiteInstance::GetEffectiveURL(browser_context,
56 url))) { 58 url))) {
57 // Not using process-per-site, so use a map specific to this instance. 59 // Not using process-per-site, so use a map specific to this instance.
58 return &site_instance_map_; 60 return &site_instance_map_;
59 } 61 }
60 62
61 // Otherwise, process-per-site is in use, at least for this URL. Look up the 63 // Otherwise, process-per-site is in use, at least for this URL. Look up the
62 // global map for this context, creating an entry if necessary. 64 // global map for this context, creating an entry if necessary.
63 return &context_site_instance_map_[browser_context]; 65 return &context_site_instance_map_.Get()[browser_context];
64 } 66 }
65 67
66 bool BrowsingInstance::HasSiteInstance(const GURL& url) { 68 bool BrowsingInstance::HasSiteInstance(const GURL& url) {
67 std::string site = 69 std::string site =
68 SiteInstance::GetSiteForURL(browser_context_, url) 70 SiteInstance::GetSiteForURL(browser_context_, url)
69 .possibly_invalid_spec(); 71 .possibly_invalid_spec();
70 72
71 SiteInstanceMap* map = GetSiteInstanceMap(browser_context_, url); 73 SiteInstanceMap* map = GetSiteInstanceMap(browser_context_, url);
72 SiteInstanceMap::iterator i = map->find(site); 74 SiteInstanceMap::iterator i = map->find(site);
73 return (i != map->end()); 75 return (i != map->end());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 124
123 // We look for the site instance in both the local site_instance_map_ and also 125 // We look for the site instance in both the local site_instance_map_ and also
124 // the static context_site_instance_map_ - this is because the logic in 126 // the static context_site_instance_map_ - this is because the logic in
125 // ShouldUseProcessPerSite() can produce different results over the lifetime 127 // ShouldUseProcessPerSite() can produce different results over the lifetime
126 // of Chrome (e.g. installation of apps with web extents can change our 128 // of Chrome (e.g. installation of apps with web extents can change our
127 // process-per-site policy for a given domain), so we don't know which map 129 // process-per-site policy for a given domain), so we don't know which map
128 // the site was put into when it was originally registered. 130 // the site was put into when it was originally registered.
129 if (!RemoveSiteInstanceFromMap(&site_instance_map_, site, site_instance)) { 131 if (!RemoveSiteInstanceFromMap(&site_instance_map_, site, site_instance)) {
130 // Wasn't in our local map, so look in the static per-browser context map. 132 // Wasn't in our local map, so look in the static per-browser context map.
131 RemoveSiteInstanceFromMap( 133 RemoveSiteInstanceFromMap(
132 &context_site_instance_map_[browser_context_], site, site_instance); 134 &context_site_instance_map_.Get()[browser_context_],
135 site,
136 site_instance);
133 } 137 }
134 } 138 }
135 139
136 bool BrowsingInstance::RemoveSiteInstanceFromMap(SiteInstanceMap* map, 140 bool BrowsingInstance::RemoveSiteInstanceFromMap(SiteInstanceMap* map,
137 const std::string& site, 141 const std::string& site,
138 SiteInstance* site_instance) { 142 SiteInstance* site_instance) {
139 SiteInstanceMap::iterator i = map->find(site); 143 SiteInstanceMap::iterator i = map->find(site);
140 if (i != map->end() && i->second == site_instance) { 144 if (i != map->end() && i->second == site_instance) {
141 // Matches, so erase it. 145 // Matches, so erase it.
142 map->erase(i); 146 map->erase(i);
143 return true; 147 return true;
144 } 148 }
145 return false; 149 return false;
146 } 150 }
147 151
148 BrowsingInstance::~BrowsingInstance() { 152 BrowsingInstance::~BrowsingInstance() {
149 // We should only be deleted when all of the SiteInstances that refer to 153 // We should only be deleted when all of the SiteInstances that refer to
150 // us are gone. 154 // us are gone.
151 DCHECK(site_instance_map_.empty()); 155 DCHECK(site_instance_map_.empty());
152 } 156 }
OLDNEW
« no previous file with comments | « content/browser/browsing_instance.h ('k') | content/browser/debugger/devtools_agent_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698