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

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

Issue 257083002: Check BrowsingInstance before swapping prerenders. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 7 months 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 | « chrome/browser/prerender/prerender_manager.cc ('k') | content/browser/browsing_instance.cc » ('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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef CONTENT_BROWSER_BROWSING_INSTANCE_H_ 5 #ifndef CONTENT_BROWSER_BROWSING_INSTANCE_H_
6 #define CONTENT_BROWSER_BROWSING_INSTANCE_H_ 6 #define CONTENT_BROWSER_BROWSING_INSTANCE_H_
7 7
8 #include "base/containers/hash_tables.h" 8 #include "base/containers/hash_tables.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 // Adds the given SiteInstance to our map, to ensure that we do not create 72 // Adds the given SiteInstance to our map, to ensure that we do not create
73 // another SiteInstance for the same site. 73 // another SiteInstance for the same site.
74 void RegisterSiteInstance(SiteInstance* site_instance); 74 void RegisterSiteInstance(SiteInstance* site_instance);
75 75
76 // Removes the given SiteInstance from our map, after all references to it 76 // Removes the given SiteInstance from our map, after all references to it
77 // have been deleted. This means it is safe to create a new SiteInstance 77 // have been deleted. This means it is safe to create a new SiteInstance
78 // if the user later visits a page from this site, within this 78 // if the user later visits a page from this site, within this
79 // BrowsingInstance. 79 // BrowsingInstance.
80 void UnregisterSiteInstance(SiteInstance* site_instance); 80 void UnregisterSiteInstance(SiteInstance* site_instance);
81 81
82 // Tracks the number of WebContents currently in this BrowsingInstance.
83 size_t active_contents_count() const { return active_contents_count_; }
84 void increment_active_contents_count() { active_contents_count_++; }
85 void decrement_active_contents_count() { active_contents_count_--; }
tburkard 2014/05/07 08:52:23 How about adding a DCHECK that active_contents_cou
davidben 2014/05/07 18:51:43 There's actually one in the destructor already, bu
86
82 friend class SiteInstanceImpl; 87 friend class SiteInstanceImpl;
83 friend class SiteInstance; 88 friend class SiteInstance;
84 89
85 friend class base::RefCounted<BrowsingInstance>; 90 friend class base::RefCounted<BrowsingInstance>;
86 91
87 // Virtual to allow tests to extend it. 92 // Virtual to allow tests to extend it.
88 virtual ~BrowsingInstance(); 93 virtual ~BrowsingInstance();
89 94
90 private: 95 private:
91 // Map of site to SiteInstance, to ensure we only have one SiteInstance per 96 // Map of site to SiteInstance, to ensure we only have one SiteInstance per
97 // site.
92 typedef base::hash_map<std::string, SiteInstance*> SiteInstanceMap; 98 typedef base::hash_map<std::string, SiteInstance*> SiteInstanceMap;
93 99
94 // Common browser context to which all SiteInstances in this BrowsingInstance 100 // Common browser context to which all SiteInstances in this BrowsingInstance
95 // must belong. 101 // must belong.
96 BrowserContext* const browser_context_; 102 BrowserContext* const browser_context_;
97 103
98 // Map of site to SiteInstance, to ensure we only have one SiteInstance per 104 // Map of site to SiteInstance, to ensure we only have one SiteInstance per
99 // site. The site string should be the possibly_invalid_spec() of a GURL 105 // site. The site string should be the possibly_invalid_spec() of a GURL
100 // obtained with SiteInstanceImpl::GetSiteForURL. Note that this map may not 106 // obtained with SiteInstanceImpl::GetSiteForURL. Note that this map may not
101 // contain every active SiteInstance, because a race exists where two 107 // contain every active SiteInstance, because a race exists where two
102 // SiteInstances can be assigned to the same site. This is ok in rare cases. 108 // SiteInstances can be assigned to the same site. This is ok in rare cases.
109 // It also does not contain SiteInstances which have not yet been assigned a
110 // site, such as about:blank. See NavigatorImpl::ShouldAssignSiteForURL.
103 SiteInstanceMap site_instance_map_; 111 SiteInstanceMap site_instance_map_;
104 112
113 // Number of WebContentses currently using this BrowsingInstance.
114 size_t active_contents_count_;
115
105 DISALLOW_COPY_AND_ASSIGN(BrowsingInstance); 116 DISALLOW_COPY_AND_ASSIGN(BrowsingInstance);
106 }; 117 };
107 118
108 } // namespace content 119 } // namespace content
109 120
110 #endif // CONTENT_BROWSER_BROWSING_INSTANCE_H_ 121 #endif // CONTENT_BROWSER_BROWSING_INSTANCE_H_
OLDNEW
« no previous file with comments | « chrome/browser/prerender/prerender_manager.cc ('k') | content/browser/browsing_instance.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698