OLD | NEW |
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/logging.h" |
10 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
11 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
12 #include "content/public/browser/browser_context.h" | 13 #include "content/public/browser/browser_context.h" |
13 | 14 |
14 class GURL; | 15 class GURL; |
15 | 16 |
16 namespace content { | 17 namespace content { |
17 class SiteInstance; | 18 class SiteInstance; |
18 class SiteInstanceImpl; | 19 class SiteInstanceImpl; |
19 | 20 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 // Adds the given SiteInstance to our map, to ensure that we do not create | 73 // Adds the given SiteInstance to our map, to ensure that we do not create |
73 // another SiteInstance for the same site. | 74 // another SiteInstance for the same site. |
74 void RegisterSiteInstance(SiteInstance* site_instance); | 75 void RegisterSiteInstance(SiteInstance* site_instance); |
75 | 76 |
76 // Removes the given SiteInstance from our map, after all references to it | 77 // 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 | 78 // 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 | 79 // if the user later visits a page from this site, within this |
79 // BrowsingInstance. | 80 // BrowsingInstance. |
80 void UnregisterSiteInstance(SiteInstance* site_instance); | 81 void UnregisterSiteInstance(SiteInstance* site_instance); |
81 | 82 |
| 83 // Tracks the number of WebContents currently in this BrowsingInstance. |
| 84 size_t active_contents_count() const { return active_contents_count_; } |
| 85 void increment_active_contents_count() { active_contents_count_++; } |
| 86 void decrement_active_contents_count() { |
| 87 DCHECK_LT(0u, active_contents_count_); |
| 88 active_contents_count_--; |
| 89 } |
| 90 |
82 friend class SiteInstanceImpl; | 91 friend class SiteInstanceImpl; |
83 friend class SiteInstance; | 92 friend class SiteInstance; |
84 | 93 |
85 friend class base::RefCounted<BrowsingInstance>; | 94 friend class base::RefCounted<BrowsingInstance>; |
86 | 95 |
87 // Virtual to allow tests to extend it. | 96 // Virtual to allow tests to extend it. |
88 virtual ~BrowsingInstance(); | 97 virtual ~BrowsingInstance(); |
89 | 98 |
90 private: | 99 private: |
91 // Map of site to SiteInstance, to ensure we only have one SiteInstance per | 100 // Map of site to SiteInstance, to ensure we only have one SiteInstance per |
| 101 // site. |
92 typedef base::hash_map<std::string, SiteInstance*> SiteInstanceMap; | 102 typedef base::hash_map<std::string, SiteInstance*> SiteInstanceMap; |
93 | 103 |
94 // Common browser context to which all SiteInstances in this BrowsingInstance | 104 // Common browser context to which all SiteInstances in this BrowsingInstance |
95 // must belong. | 105 // must belong. |
96 BrowserContext* const browser_context_; | 106 BrowserContext* const browser_context_; |
97 | 107 |
98 // Map of site to SiteInstance, to ensure we only have one SiteInstance per | 108 // 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 | 109 // site. The site string should be the possibly_invalid_spec() of a GURL |
100 // obtained with SiteInstanceImpl::GetSiteForURL. Note that this map may not | 110 // obtained with SiteInstanceImpl::GetSiteForURL. Note that this map may not |
101 // contain every active SiteInstance, because a race exists where two | 111 // 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. | 112 // SiteInstances can be assigned to the same site. This is ok in rare cases. |
| 113 // It also does not contain SiteInstances which have not yet been assigned a |
| 114 // site, such as about:blank. See NavigatorImpl::ShouldAssignSiteForURL. |
103 SiteInstanceMap site_instance_map_; | 115 SiteInstanceMap site_instance_map_; |
104 | 116 |
| 117 // Number of WebContentses currently using this BrowsingInstance. |
| 118 size_t active_contents_count_; |
| 119 |
105 DISALLOW_COPY_AND_ASSIGN(BrowsingInstance); | 120 DISALLOW_COPY_AND_ASSIGN(BrowsingInstance); |
106 }; | 121 }; |
107 | 122 |
108 } // namespace content | 123 } // namespace content |
109 | 124 |
110 #endif // CONTENT_BROWSER_BROWSING_INSTANCE_H_ | 125 #endif // CONTENT_BROWSER_BROWSING_INSTANCE_H_ |
OLD | NEW |