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

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: Add missing #include for FRIEND_TEST 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
« no previous file with comments | « no previous file | content/browser/site_instance_impl.h » ('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 <stddef.h> 8 #include <stddef.h>
9 9
10 #include "base/containers/hash_tables.h" 10 #include "base/containers/hash_tables.h"
11 #include "base/gtest_prod_util.h"
11 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
12 #include "base/logging.h" 13 #include "base/logging.h"
13 #include "base/macros.h" 14 #include "base/macros.h"
14 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
15 #include "content/common/content_export.h" 16 #include "content/common/content_export.h"
16 #include "content/public/browser/browser_context.h" 17 #include "content/public/browser/browser_context.h"
17 18
18 class GURL; 19 class GURL;
19 20
20 namespace content { 21 namespace content {
(...skipping 26 matching lines...) Expand all
47 // need to be manually deleted. 48 // need to be manually deleted.
48 // 49 //
49 // BrowsingInstance has no public members, as it is designed to be 50 // BrowsingInstance has no public members, as it is designed to be
50 // visible only from the SiteInstance class. To get a new 51 // visible only from the SiteInstance class. To get a new
51 // SiteInstance that is part of the same BrowsingInstance, use 52 // SiteInstance that is part of the same BrowsingInstance, use
52 // SiteInstance::GetRelatedSiteInstance. Because of this, 53 // SiteInstance::GetRelatedSiteInstance. Because of this,
53 // BrowsingInstances and SiteInstances are tested together in 54 // BrowsingInstances and SiteInstances are tested together in
54 // site_instance_unittest.cc. 55 // site_instance_unittest.cc.
55 // 56 //
56 /////////////////////////////////////////////////////////////////////////////// 57 ///////////////////////////////////////////////////////////////////////////////
57 class CONTENT_EXPORT BrowsingInstance 58 class CONTENT_EXPORT BrowsingInstance final
58 : public base::RefCounted<BrowsingInstance> { 59 : public base::RefCounted<BrowsingInstance> {
59 protected: 60 private:
61 friend class base::RefCounted<BrowsingInstance>;
62 friend class SiteInstanceImpl;
63 FRIEND_TEST_ALL_PREFIXES(SiteInstanceTest, OneSiteInstancePerSite);
64 FRIEND_TEST_ALL_PREFIXES(SiteInstanceTest,
65 OneSiteInstancePerSiteInBrowserContext);
66
60 // Create a new BrowsingInstance. 67 // Create a new BrowsingInstance.
61 explicit BrowsingInstance(BrowserContext* context); 68 explicit BrowsingInstance(BrowserContext* context);
62 69
70 ~BrowsingInstance();
71
63 // Get the browser context to which this BrowsingInstance belongs. 72 // Get the browser context to which this BrowsingInstance belongs.
64 BrowserContext* browser_context() const { return browser_context_; } 73 BrowserContext* browser_context() const { return browser_context_; }
65 74
66 // Returns whether this BrowsingInstance has registered a SiteInstance for 75 // Returns whether this BrowsingInstance has registered a SiteInstance for
67 // the site of the given URL. 76 // the site of the given URL.
68 bool HasSiteInstance(const GURL& url); 77 bool HasSiteInstance(const GURL& url);
69 78
70 // Get the SiteInstance responsible for rendering the given URL. Should 79 // Get the SiteInstance responsible for rendering the given URL. Should
71 // create a new one if necessary, but should not create more than one 80 // create a new one if necessary, but should not create more than one
72 // SiteInstance per site. 81 // SiteInstance per site.
(...skipping 16 matching lines...) Expand all
89 void UnregisterSiteInstance(SiteInstanceImpl* site_instance); 98 void UnregisterSiteInstance(SiteInstanceImpl* site_instance);
90 99
91 // Tracks the number of WebContents currently in this BrowsingInstance. 100 // Tracks the number of WebContents currently in this BrowsingInstance.
92 size_t active_contents_count() const { return active_contents_count_; } 101 size_t active_contents_count() const { return active_contents_count_; }
93 void increment_active_contents_count() { active_contents_count_++; } 102 void increment_active_contents_count() { active_contents_count_++; }
94 void decrement_active_contents_count() { 103 void decrement_active_contents_count() {
95 DCHECK_LT(0u, active_contents_count_); 104 DCHECK_LT(0u, active_contents_count_);
96 active_contents_count_--; 105 active_contents_count_--;
97 } 106 }
98 107
99 friend class SiteInstanceImpl;
100
101 friend class base::RefCounted<BrowsingInstance>;
102
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 108 // Map of site to SiteInstance, to ensure we only have one SiteInstance per
108 // site. 109 // site.
109 typedef base::hash_map<std::string, SiteInstanceImpl*> SiteInstanceMap; 110 typedef base::hash_map<std::string, SiteInstanceImpl*> SiteInstanceMap;
110 111
111 // Common browser context to which all SiteInstances in this BrowsingInstance 112 // Common browser context to which all SiteInstances in this BrowsingInstance
112 // must belong. 113 // must belong.
113 BrowserContext* const browser_context_; 114 BrowserContext* const browser_context_;
114 115
115 // Map of site to SiteInstance, to ensure we only have one SiteInstance per 116 // 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 117 // site. The site string should be the possibly_invalid_spec() of a GURL
117 // obtained with SiteInstanceImpl::GetSiteForURL. Note that this map may not 118 // obtained with SiteInstanceImpl::GetSiteForURL. Note that this map may not
118 // contain every active SiteInstance, because a race exists where two 119 // 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. 120 // 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 121 // It also does not contain SiteInstances which have not yet been assigned a
121 // site, such as about:blank. See NavigatorImpl::ShouldAssignSiteForURL. 122 // site, such as about:blank. See NavigatorImpl::ShouldAssignSiteForURL.
122 SiteInstanceMap site_instance_map_; 123 SiteInstanceMap site_instance_map_;
123 124
124 // Number of WebContentses currently using this BrowsingInstance. 125 // Number of WebContentses currently using this BrowsingInstance.
125 size_t active_contents_count_; 126 size_t active_contents_count_;
126 127
127 SiteInstanceImpl* default_subframe_site_instance_ = nullptr; 128 SiteInstanceImpl* default_subframe_site_instance_ = nullptr;
128 129
129 DISALLOW_COPY_AND_ASSIGN(BrowsingInstance); 130 DISALLOW_COPY_AND_ASSIGN(BrowsingInstance);
130 }; 131 };
131 132
132 } // namespace content 133 } // namespace content
133 134
134 #endif // CONTENT_BROWSER_BROWSING_INSTANCE_H_ 135 #endif // CONTENT_BROWSER_BROWSING_INSTANCE_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/site_instance_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698