| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/hash_tables.h" | 9 #include "base/hash_tables.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
| 13 | 13 |
| 14 class GURL; | 14 class GURL; |
| 15 class SiteInstance; | 15 class SiteInstanceImpl; |
| 16 | 16 |
| 17 namespace content { | 17 namespace content { |
| 18 class BrowserContext; | 18 class BrowserContext; |
| 19 class SiteInstance; |
| 19 } | 20 } |
| 20 | 21 |
| 21 /////////////////////////////////////////////////////////////////////////////// | 22 /////////////////////////////////////////////////////////////////////////////// |
| 22 // | 23 // |
| 23 // BrowsingInstance class | 24 // BrowsingInstance class |
| 24 // | 25 // |
| 25 // A browsing instance corresponds to the notion of a "unit of related browsing | 26 // A browsing instance corresponds to the notion of a "unit of related browsing |
| 26 // contexts" in the HTML 5 spec. Intuitively, it represents a collection of | 27 // contexts" in the HTML 5 spec. Intuitively, it represents a collection of |
| 27 // tabs and frames that can have script connections to each other. In that | 28 // tabs and frames that can have script connections to each other. In that |
| 28 // sense, it reflects the user interface, and not the contents of the tabs and | 29 // sense, it reflects the user interface, and not the contents of the tabs and |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 // Get the browser context to which this BrowsingInstance belongs. | 74 // Get the browser context to which this BrowsingInstance belongs. |
| 74 content::BrowserContext* browser_context() const { return browser_context_; } | 75 content::BrowserContext* browser_context() const { return browser_context_; } |
| 75 | 76 |
| 76 // Returns whether this BrowsingInstance has registered a SiteInstance for | 77 // Returns whether this BrowsingInstance has registered a SiteInstance for |
| 77 // the site of the given URL. | 78 // the site of the given URL. |
| 78 bool HasSiteInstance(const GURL& url); | 79 bool HasSiteInstance(const GURL& url); |
| 79 | 80 |
| 80 // Get the SiteInstance responsible for rendering the given URL. Should | 81 // Get the SiteInstance responsible for rendering the given URL. Should |
| 81 // create a new one if necessary, but should not create more than one | 82 // create a new one if necessary, but should not create more than one |
| 82 // SiteInstance per site. | 83 // SiteInstance per site. |
| 83 SiteInstance* GetSiteInstanceForURL(const GURL& url); | 84 content::SiteInstance* GetSiteInstanceForURL(const GURL& url); |
| 84 | 85 |
| 85 // Adds the given SiteInstance to our map, to ensure that we do not create | 86 // Adds the given SiteInstance to our map, to ensure that we do not create |
| 86 // another SiteInstance for the same site. | 87 // another SiteInstance for the same site. |
| 87 void RegisterSiteInstance(SiteInstance* site_instance); | 88 void RegisterSiteInstance(content::SiteInstance* site_instance); |
| 88 | 89 |
| 89 // Removes the given SiteInstance from our map, after all references to it | 90 // Removes the given SiteInstance from our map, after all references to it |
| 90 // have been deleted. This means it is safe to create a new SiteInstance | 91 // have been deleted. This means it is safe to create a new SiteInstance |
| 91 // if the user later visits a page from this site, within this | 92 // if the user later visits a page from this site, within this |
| 92 // BrowsingInstance. | 93 // BrowsingInstance. |
| 93 void UnregisterSiteInstance(SiteInstance* site_instance); | 94 void UnregisterSiteInstance(content::SiteInstance* site_instance); |
| 94 | 95 |
| 95 friend class SiteInstance; | 96 friend class SiteInstanceImpl; |
| 97 friend class content::SiteInstance; |
| 96 | 98 |
| 97 friend class base::RefCounted<BrowsingInstance>; | 99 friend class base::RefCounted<BrowsingInstance>; |
| 98 | 100 |
| 99 // Virtual to allow tests to extend it. | 101 // Virtual to allow tests to extend it. |
| 100 virtual ~BrowsingInstance(); | 102 virtual ~BrowsingInstance(); |
| 101 | 103 |
| 102 private: | 104 private: |
| 103 // Map of site to SiteInstance, to ensure we only have one SiteInstance per | 105 // Map of site to SiteInstance, to ensure we only have one SiteInstance per |
| 104 typedef base::hash_map<std::string, SiteInstance*> SiteInstanceMap; | 106 typedef base::hash_map<std::string, content::SiteInstance*> SiteInstanceMap; |
| 105 | 107 |
| 106 // Map of BrowserContext to SiteInstanceMap, for use in the process-per-site | 108 // Map of BrowserContext to SiteInstanceMap, for use in the process-per-site |
| 107 // model. | 109 // model. |
| 108 typedef base::hash_map<content::BrowserContext*, SiteInstanceMap> | 110 typedef base::hash_map<content::BrowserContext*, SiteInstanceMap> |
| 109 ContextSiteInstanceMap; | 111 ContextSiteInstanceMap; |
| 110 | 112 |
| 111 // Returns a pointer to the relevant SiteInstanceMap for this object. If the | 113 // Returns a pointer to the relevant SiteInstanceMap for this object. If the |
| 112 // process-per-site model is in use, or if process-per-site-instance is in | 114 // process-per-site model is in use, or if process-per-site-instance is in |
| 113 // use and |url| matches a site for which we always use one process (e.g., | 115 // use and |url| matches a site for which we always use one process (e.g., |
| 114 // the new tab page), then this returns the SiteInstanceMap for the entire | 116 // the new tab page), then this returns the SiteInstanceMap for the entire |
| 115 // browser context. If not, this returns the BrowsingInstance's own private | 117 // browser context. If not, this returns the BrowsingInstance's own private |
| 116 // SiteInstanceMap. | 118 // SiteInstanceMap. |
| 117 SiteInstanceMap* GetSiteInstanceMap(content::BrowserContext* browser_context, | 119 SiteInstanceMap* GetSiteInstanceMap(content::BrowserContext* browser_context, |
| 118 const GURL& url); | 120 const GURL& url); |
| 119 | 121 |
| 120 // Utility routine which removes the passed SiteInstance from the passed | 122 // Utility routine which removes the passed SiteInstance from the passed |
| 121 // SiteInstanceMap. | 123 // SiteInstanceMap. |
| 122 bool RemoveSiteInstanceFromMap(SiteInstanceMap* map, const std::string& site, | 124 bool RemoveSiteInstanceFromMap(SiteInstanceMap* map, const std::string& site, |
| 123 SiteInstance* site_instance); | 125 content::SiteInstance* site_instance); |
| 124 | 126 |
| 125 // Common browser context to which all SiteInstances in this BrowsingInstance | 127 // Common browser context to which all SiteInstances in this BrowsingInstance |
| 126 // must belong. | 128 // must belong. |
| 127 content::BrowserContext* const browser_context_; | 129 content::BrowserContext* const browser_context_; |
| 128 | 130 |
| 129 // Map of site to SiteInstance, to ensure we only have one SiteInstance per | 131 // Map of site to SiteInstance, to ensure we only have one SiteInstance per |
| 130 // site. The site string should be the possibly_invalid_spec() of a GURL | 132 // site. The site string should be the possibly_invalid_spec() of a GURL |
| 131 // obtained with SiteInstance::GetSiteForURL. Note that this map may not | 133 // obtained with SiteInstanceImpl::GetSiteForURL. Note that this map may not |
| 132 // contain every active SiteInstance, because a race exists where two | 134 // contain every active SiteInstance, because a race exists where two |
| 133 // SiteInstances can be assigned to the same site. This is ok in rare cases. | 135 // SiteInstances can be assigned to the same site. This is ok in rare cases. |
| 134 // This field is only used if we are not using process-per-site. | 136 // This field is only used if we are not using process-per-site. |
| 135 SiteInstanceMap site_instance_map_; | 137 SiteInstanceMap site_instance_map_; |
| 136 | 138 |
| 137 // Global map of BrowserContext to SiteInstanceMap, for process-per-site. | 139 // Global map of BrowserContext to SiteInstanceMap, for process-per-site. |
| 138 static base::LazyInstance< | 140 static base::LazyInstance< |
| 139 ContextSiteInstanceMap, | 141 ContextSiteInstanceMap, |
| 140 base::LeakyLazyInstanceTraits<ContextSiteInstanceMap> > | 142 base::LeakyLazyInstanceTraits<ContextSiteInstanceMap> > |
| 141 context_site_instance_map_; | 143 context_site_instance_map_; |
| 142 | 144 |
| 143 DISALLOW_COPY_AND_ASSIGN(BrowsingInstance); | 145 DISALLOW_COPY_AND_ASSIGN(BrowsingInstance); |
| 144 }; | 146 }; |
| 145 | 147 |
| 146 #endif // CONTENT_BROWSER_BROWSING_INSTANCE_H_ | 148 #endif // CONTENT_BROWSER_BROWSING_INSTANCE_H_ |
| OLD | NEW |