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

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

Issue 9221017: Hide BrowsingInstance from all but SiteInstance, as intended by design. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 8 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 // one SiteInstance per site for the entire browser context, not just for each 43 // one SiteInstance per site for the entire browser context, not just for each
44 // BrowsingInstance. This reduces the number of renderer processes we create. 44 // BrowsingInstance. This reduces the number of renderer processes we create.
45 // (This is currently only true if --process-per-site is specified at the 45 // (This is currently only true if --process-per-site is specified at the
46 // command line.) 46 // command line.)
47 // 47 //
48 // A BrowsingInstance is live as long as any SiteInstance has a reference to 48 // A BrowsingInstance is live as long as any SiteInstance has a reference to
49 // it. A SiteInstance is live as long as any NavigationEntry or RenderViewHost 49 // it. A SiteInstance is live as long as any NavigationEntry or RenderViewHost
50 // have references to it. Because both classes are RefCounted, they do not 50 // have references to it. Because both classes are RefCounted, they do not
51 // need to be manually deleted. 51 // need to be manually deleted.
52 // 52 //
53 // Currently, the BrowsingInstance class is not visible outside of the 53 // BrowsingInstance has no public members, as it is designed to be
54 // SiteInstance class. To get a new SiteInstance that is part of the same 54 // visible only from the SiteInstance class. To get a new
55 // BrowsingInstance, use SiteInstance::GetRelatedSiteInstance. Because of 55 // SiteInstance that is part of the same BrowsingInstance, use
56 // this, BrowsingInstances and SiteInstances are tested together in 56 // SiteInstance::GetRelatedSiteInstance. Because of this,
57 // BrowsingInstances and SiteInstances are tested together in
57 // site_instance_unittest.cc. 58 // site_instance_unittest.cc.
58 // 59 //
59 /////////////////////////////////////////////////////////////////////////////// 60 ///////////////////////////////////////////////////////////////////////////////
60 class CONTENT_EXPORT BrowsingInstance 61 class CONTENT_EXPORT BrowsingInstance
61 : public base::RefCounted<BrowsingInstance> { 62 : public base::RefCounted<BrowsingInstance> {
62 public: 63 protected:
63 // Create a new BrowsingInstance. 64 // Create a new BrowsingInstance.
64 explicit BrowsingInstance(content::BrowserContext* context); 65 explicit BrowsingInstance(content::BrowserContext* context);
65 66
66 // Returns whether the process-per-site model is in use (globally or just for 67 // Returns whether the process-per-site model is in use (globally or just for
67 // the given url), in which case we should ensure there is only one 68 // the given url), in which case we should ensure there is only one
68 // SiteInstance per site for the entire browser context, not just for this 69 // SiteInstance per site for the entire browser context, not just for this
69 // BrowsingInstance. 70 // BrowsingInstance.
70 virtual bool ShouldUseProcessPerSite(const GURL& url); 71 virtual bool ShouldUseProcessPerSite(const GURL& url);
71 72
72 // Get the browser context to which this BrowsingInstance belongs. 73 // Get the browser context to which this BrowsingInstance belongs.
73 content::BrowserContext* browser_context() { return browser_context_; } 74 content::BrowserContext* browser_context() const { return browser_context_; }
74 75
75 // Returns whether this BrowsingInstance has registered a SiteInstance for 76 // Returns whether this BrowsingInstance has registered a SiteInstance for
76 // the site of the given URL. 77 // the site of the given URL.
77 bool HasSiteInstance(const GURL& url); 78 bool HasSiteInstance(const GURL& url);
78 79
79 // Get the SiteInstance responsible for rendering the given URL. Should 80 // Get the SiteInstance responsible for rendering the given URL. Should
80 // create a new one if necessary, but should not create more than one 81 // create a new one if necessary, but should not create more than one
81 // SiteInstance per site. 82 // SiteInstance per site.
82 SiteInstance* GetSiteInstanceForURL(const GURL& url); 83 SiteInstance* GetSiteInstanceForURL(const GURL& url);
83 84
84 // Adds the given SiteInstance to our map, to ensure that we do not create 85 // Adds the given SiteInstance to our map, to ensure that we do not create
85 // another SiteInstance for the same site. 86 // another SiteInstance for the same site.
86 void RegisterSiteInstance(SiteInstance* site_instance); 87 void RegisterSiteInstance(SiteInstance* site_instance);
87 88
88 // Removes the given SiteInstance from our map, after all references to it 89 // Removes the given SiteInstance from our map, after all references to it
89 // have been deleted. This means it is safe to create a new SiteInstance 90 // have been deleted. This means it is safe to create a new SiteInstance
90 // if the user later visits a page from this site, within this 91 // if the user later visits a page from this site, within this
91 // BrowsingInstance. 92 // BrowsingInstance.
92 void UnregisterSiteInstance(SiteInstance* site_instance); 93 void UnregisterSiteInstance(SiteInstance* site_instance);
93 94
94 protected: 95 friend class SiteInstance;
96
95 friend class base::RefCounted<BrowsingInstance>; 97 friend class base::RefCounted<BrowsingInstance>;
96 98
97 // Virtual to allow tests to extend it. 99 // Virtual to allow tests to extend it.
98 virtual ~BrowsingInstance(); 100 virtual ~BrowsingInstance();
99 101
100 private: 102 private:
101 // Map of site to SiteInstance, to ensure we only have one SiteInstance per 103 // Map of site to SiteInstance, to ensure we only have one SiteInstance per
102 typedef base::hash_map<std::string, SiteInstance*> SiteInstanceMap; 104 typedef base::hash_map<std::string, SiteInstance*> SiteInstanceMap;
103 105
104 // Map of BrowserContext to SiteInstanceMap, for use in the process-per-site 106 // Map of BrowserContext to SiteInstanceMap, for use in the process-per-site
(...skipping 30 matching lines...) Expand all
135 // Global map of BrowserContext to SiteInstanceMap, for process-per-site. 137 // Global map of BrowserContext to SiteInstanceMap, for process-per-site.
136 static base::LazyInstance< 138 static base::LazyInstance<
137 ContextSiteInstanceMap, 139 ContextSiteInstanceMap,
138 base::LeakyLazyInstanceTraits<ContextSiteInstanceMap> > 140 base::LeakyLazyInstanceTraits<ContextSiteInstanceMap> >
139 context_site_instance_map_; 141 context_site_instance_map_;
140 142
141 DISALLOW_COPY_AND_ASSIGN(BrowsingInstance); 143 DISALLOW_COPY_AND_ASSIGN(BrowsingInstance);
142 }; 144 };
143 145
144 #endif // CONTENT_BROWSER_BROWSING_INSTANCE_H_ 146 #endif // CONTENT_BROWSER_BROWSING_INSTANCE_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/extension_settings_handler.cc ('k') | content/browser/browsing_instance.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698