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

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

Issue 1845233003: SiteInstance unittest improvements (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@doghouse_now
Patch Set: Created 4 years, 8 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
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 <stddef.h> 8 #include <stddef.h>
9 9
10 #include "base/containers/hash_tables.h" 10 #include "base/containers/hash_tables.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 // need to be manually deleted. 47 // need to be manually deleted.
48 // 48 //
49 // BrowsingInstance has no public members, as it is designed to be 49 // BrowsingInstance has no public members, as it is designed to be
50 // visible only from the SiteInstance class. To get a new 50 // visible only from the SiteInstance class. To get a new
51 // SiteInstance that is part of the same BrowsingInstance, use 51 // SiteInstance that is part of the same BrowsingInstance, use
52 // SiteInstance::GetRelatedSiteInstance. Because of this, 52 // SiteInstance::GetRelatedSiteInstance. Because of this,
53 // BrowsingInstances and SiteInstances are tested together in 53 // BrowsingInstances and SiteInstances are tested together in
54 // site_instance_unittest.cc. 54 // site_instance_unittest.cc.
55 // 55 //
56 /////////////////////////////////////////////////////////////////////////////// 56 ///////////////////////////////////////////////////////////////////////////////
57 class CONTENT_EXPORT BrowsingInstance 57 class CONTENT_EXPORT BrowsingInstance final
58 : public base::RefCounted<BrowsingInstance> { 58 : public base::RefCounted<BrowsingInstance> {
59 protected: 59 protected:
60 ~BrowsingInstance();
61
60 // Create a new BrowsingInstance. 62 // Create a new BrowsingInstance.
61 explicit BrowsingInstance(BrowserContext* context); 63 explicit BrowsingInstance(BrowserContext* context);
62 64
63 // Get the browser context to which this BrowsingInstance belongs. 65 // Get the browser context to which this BrowsingInstance belongs.
64 BrowserContext* browser_context() const { return browser_context_; } 66 BrowserContext* browser_context() const { return browser_context_; }
65 67
66 // Returns whether this BrowsingInstance has registered a SiteInstance for 68 // Returns whether this BrowsingInstance has registered a SiteInstance for
67 // the site of the given URL. 69 // the site of the given URL.
68 bool HasSiteInstance(const GURL& url); 70 bool HasSiteInstance(const GURL& url);
69 71
(...skipping 19 matching lines...) Expand all
89 void UnregisterSiteInstance(SiteInstanceImpl* site_instance); 91 void UnregisterSiteInstance(SiteInstanceImpl* site_instance);
90 92
91 // Tracks the number of WebContents currently in this BrowsingInstance. 93 // Tracks the number of WebContents currently in this BrowsingInstance.
92 size_t active_contents_count() const { return active_contents_count_; } 94 size_t active_contents_count() const { return active_contents_count_; }
93 void increment_active_contents_count() { active_contents_count_++; } 95 void increment_active_contents_count() { active_contents_count_++; }
94 void decrement_active_contents_count() { 96 void decrement_active_contents_count() {
95 DCHECK_LT(0u, active_contents_count_); 97 DCHECK_LT(0u, active_contents_count_);
96 active_contents_count_--; 98 active_contents_count_--;
97 } 99 }
98 100
101 private:
102 friend class base::RefCounted<BrowsingInstance>;
99 friend class SiteInstanceImpl; 103 friend class SiteInstanceImpl;
100 104 FRIEND_TEST_ALL_PREFIXES(SiteInstanceTest, OneSiteInstancePerSite);
101 friend class base::RefCounted<BrowsingInstance>; 105 FRIEND_TEST_ALL_PREFIXES(SiteInstanceTest,
102 106 OneSiteInstancePerSiteInBrowserContext);
103 // Virtual to allow tests to extend it.
104 virtual ~BrowsingInstance();
105
106 private:
107 // Map of site to SiteInstance, to ensure we only have one SiteInstance per 107 // Map of site to SiteInstance, to ensure we only have one SiteInstance per
108 // site. 108 // site.
109 typedef base::hash_map<std::string, SiteInstanceImpl*> SiteInstanceMap; 109 typedef base::hash_map<std::string, SiteInstanceImpl*> SiteInstanceMap;
110 110
111 // Common browser context to which all SiteInstances in this BrowsingInstance 111 // Common browser context to which all SiteInstances in this BrowsingInstance
112 // must belong. 112 // must belong.
113 BrowserContext* const browser_context_; 113 BrowserContext* const browser_context_;
114 114
115 // Map of site to SiteInstance, to ensure we only have one SiteInstance per 115 // Map of site to SiteInstance, to ensure we only have one SiteInstance per
116 // site. The site string should be the possibly_invalid_spec() of a GURL 116 // site. The site string should be the possibly_invalid_spec() of a GURL
117 // obtained with SiteInstanceImpl::GetSiteForURL. Note that this map may not 117 // obtained with SiteInstanceImpl::GetSiteForURL. Note that this map may not
118 // contain every active SiteInstance, because a race exists where two 118 // contain every active SiteInstance, because a race exists where two
119 // SiteInstances can be assigned to the same site. This is ok in rare cases. 119 // SiteInstances can be assigned to the same site. This is ok in rare cases.
120 // It also does not contain SiteInstances which have not yet been assigned a 120 // It also does not contain SiteInstances which have not yet been assigned a
121 // site, such as about:blank. See NavigatorImpl::ShouldAssignSiteForURL. 121 // site, such as about:blank. See NavigatorImpl::ShouldAssignSiteForURL.
122 SiteInstanceMap site_instance_map_; 122 SiteInstanceMap site_instance_map_;
123 123
124 // Number of WebContentses currently using this BrowsingInstance. 124 // Number of WebContentses currently using this BrowsingInstance.
125 size_t active_contents_count_; 125 size_t active_contents_count_;
126 126
127 SiteInstanceImpl* default_subframe_site_instance_ = nullptr; 127 SiteInstanceImpl* default_subframe_site_instance_ = nullptr;
128 128
129 DISALLOW_COPY_AND_ASSIGN(BrowsingInstance); 129 DISALLOW_COPY_AND_ASSIGN(BrowsingInstance);
130 }; 130 };
131 131
132 } // namespace content 132 } // namespace content
133 133
134 #endif // CONTENT_BROWSER_BROWSING_INSTANCE_H_ 134 #endif // CONTENT_BROWSER_BROWSING_INSTANCE_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/site_instance_impl.h » ('j') | content/browser/site_instance_impl.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698