| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 #include <set> |
| 9 | 10 |
| 10 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
| 11 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
| 12 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 13 #include "base/logging.h" | 14 #include "base/logging.h" |
| 14 #include "base/macros.h" | 15 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 16 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
| 17 #include "content/public/browser/browser_context.h" | 18 #include "content/public/browser/browser_context.h" |
| 18 | 19 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 /////////////////////////////////////////////////////////////////////////////// | 58 /////////////////////////////////////////////////////////////////////////////// |
| 58 class CONTENT_EXPORT BrowsingInstance final | 59 class CONTENT_EXPORT BrowsingInstance final |
| 59 : public base::RefCounted<BrowsingInstance> { | 60 : public base::RefCounted<BrowsingInstance> { |
| 60 private: | 61 private: |
| 61 friend class base::RefCounted<BrowsingInstance>; | 62 friend class base::RefCounted<BrowsingInstance>; |
| 62 friend class SiteInstanceImpl; | 63 friend class SiteInstanceImpl; |
| 63 FRIEND_TEST_ALL_PREFIXES(SiteInstanceTest, OneSiteInstancePerSite); | 64 FRIEND_TEST_ALL_PREFIXES(SiteInstanceTest, OneSiteInstancePerSite); |
| 64 FRIEND_TEST_ALL_PREFIXES(SiteInstanceTest, | 65 FRIEND_TEST_ALL_PREFIXES(SiteInstanceTest, |
| 65 OneSiteInstancePerSiteInBrowserContext); | 66 OneSiteInstancePerSiteInBrowserContext); |
| 66 | 67 |
| 68 // Lookup for a SiteInstance associated to |url| among all the |
| 69 // BrowsingInstances that belongs to |browser_context|. |
| 70 static scoped_refptr<SiteInstanceImpl> FindSiteInstance( |
| 71 BrowserContext* browser_context, |
| 72 const GURL& url); |
| 73 |
| 67 // Create a new BrowsingInstance. | 74 // Create a new BrowsingInstance. |
| 68 explicit BrowsingInstance(BrowserContext* context); | 75 explicit BrowsingInstance(BrowserContext* context); |
| 69 | 76 |
| 70 ~BrowsingInstance(); | 77 ~BrowsingInstance(); |
| 71 | 78 |
| 72 // Get the browser context to which this BrowsingInstance belongs. | 79 // Get the browser context to which this BrowsingInstance belongs. |
| 73 BrowserContext* browser_context() const { return browser_context_; } | 80 BrowserContext* browser_context() const { return browser_context_; } |
| 74 | 81 |
| 75 // Returns whether this BrowsingInstance has registered a SiteInstance for | 82 // Returns whether this BrowsingInstance has registered a SiteInstance for |
| 76 // the site of the given URL. | 83 // the site of the given URL. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 90 // Adds the given SiteInstance to our map, to ensure that we do not create | 97 // Adds the given SiteInstance to our map, to ensure that we do not create |
| 91 // another SiteInstance for the same site. | 98 // another SiteInstance for the same site. |
| 92 void RegisterSiteInstance(SiteInstanceImpl* site_instance); | 99 void RegisterSiteInstance(SiteInstanceImpl* site_instance); |
| 93 | 100 |
| 94 // Removes the given SiteInstance from our map, after all references to it | 101 // Removes the given SiteInstance from our map, after all references to it |
| 95 // have been deleted. This means it is safe to create a new SiteInstance | 102 // have been deleted. This means it is safe to create a new SiteInstance |
| 96 // if the user later visits a page from this site, within this | 103 // if the user later visits a page from this site, within this |
| 97 // BrowsingInstance. | 104 // BrowsingInstance. |
| 98 void UnregisterSiteInstance(SiteInstanceImpl* site_instance); | 105 void UnregisterSiteInstance(SiteInstanceImpl* site_instance); |
| 99 | 106 |
| 107 void RegisterUsedFor(SiteInstanceImpl* site_instance, std::string site); |
| 108 void UnregisterUsedFor(SiteInstanceImpl* site_instance, |
| 109 const std::set<std::string>& sites); |
| 110 |
| 100 // Tracks the number of WebContents currently in this BrowsingInstance. | 111 // Tracks the number of WebContents currently in this BrowsingInstance. |
| 101 size_t active_contents_count() const { return active_contents_count_; } | 112 size_t active_contents_count() const { return active_contents_count_; } |
| 102 void increment_active_contents_count() { active_contents_count_++; } | 113 void increment_active_contents_count() { active_contents_count_++; } |
| 103 void decrement_active_contents_count() { | 114 void decrement_active_contents_count() { |
| 104 DCHECK_LT(0u, active_contents_count_); | 115 DCHECK_LT(0u, active_contents_count_); |
| 105 active_contents_count_--; | 116 active_contents_count_--; |
| 106 } | 117 } |
| 107 | 118 |
| 108 // Map of site to SiteInstance, to ensure we only have one SiteInstance per | 119 // Map of site to SiteInstance, to ensure we only have one SiteInstance per |
| 109 // site. | 120 // site. |
| 110 typedef base::hash_map<std::string, SiteInstanceImpl*> SiteInstanceMap; | 121 typedef base::hash_map<std::string, SiteInstanceImpl*> SiteInstanceMap; |
| 111 | 122 |
| 112 // Common browser context to which all SiteInstances in this BrowsingInstance | 123 // Common browser context to which all SiteInstances in this BrowsingInstance |
| 113 // must belong. | 124 // must belong. |
| 114 BrowserContext* const browser_context_; | 125 BrowserContext* const browser_context_; |
| 115 | 126 |
| 116 // Map of site to SiteInstance, to ensure we only have one SiteInstance per | 127 // Map of site to SiteInstance, to ensure we only have one SiteInstance per |
| 117 // site. The site string should be the possibly_invalid_spec() of a GURL | 128 // site. The site string should be the possibly_invalid_spec() of a GURL |
| 118 // obtained with SiteInstanceImpl::GetSiteForURL. Note that this map may not | 129 // obtained with SiteInstanceImpl::GetSiteForURL. Note that this map may not |
| 119 // contain every active SiteInstance, because a race exists where two | 130 // contain every active SiteInstance, because a race exists where two |
| 120 // SiteInstances can be assigned to the same site. This is ok in rare cases. | 131 // SiteInstances can be assigned to the same site. This is ok in rare cases. |
| 121 // It also does not contain SiteInstances which have not yet been assigned a | 132 // It also does not contain SiteInstances which have not yet been assigned a |
| 122 // site, such as about:blank. See NavigatorImpl::ShouldAssignSiteForURL. | 133 // site, such as about:blank. See NavigatorImpl::ShouldAssignSiteForURL. |
| 123 SiteInstanceMap site_instance_map_; | 134 SiteInstanceMap site_instance_map_; |
| 124 | 135 |
| 136 // Keeps track of all the SiteInstances that displayed which sites. |
| 137 using SiteToSiteInstanceMap = |
| 138 std::map<std::string, std::set<SiteInstanceImpl*>>; |
| 139 SiteToSiteInstanceMap site_to_site_instance_map_; |
| 140 |
| 125 // Number of WebContentses currently using this BrowsingInstance. | 141 // Number of WebContentses currently using this BrowsingInstance. |
| 126 size_t active_contents_count_; | 142 size_t active_contents_count_; |
| 127 | 143 |
| 128 SiteInstanceImpl* default_subframe_site_instance_ = nullptr; | 144 SiteInstanceImpl* default_subframe_site_instance_ = nullptr; |
| 129 | 145 |
| 130 DISALLOW_COPY_AND_ASSIGN(BrowsingInstance); | 146 DISALLOW_COPY_AND_ASSIGN(BrowsingInstance); |
| 131 }; | 147 }; |
| 132 | 148 |
| 133 } // namespace content | 149 } // namespace content |
| 134 | 150 |
| 135 #endif // CONTENT_BROWSER_BROWSING_INSTANCE_H_ | 151 #endif // CONTENT_BROWSER_BROWSING_INSTANCE_H_ |
| OLD | NEW |