This source file includes following definitions.
- HasSiteInstance
- GetSiteInstanceForURL
- RegisterSiteInstance
- UnregisterSiteInstance
#include "content/browser/browsing_instance.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "content/browser/site_instance_impl.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/url_constants.h"
namespace content {
BrowsingInstance::BrowsingInstance(BrowserContext* browser_context)
: browser_context_(browser_context) {
}
bool BrowsingInstance::HasSiteInstance(const GURL& url) {
std::string site =
SiteInstanceImpl::GetSiteForURL(browser_context_, url)
.possibly_invalid_spec();
return site_instance_map_.find(site) != site_instance_map_.end();
}
SiteInstance* BrowsingInstance::GetSiteInstanceForURL(const GURL& url) {
std::string site =
SiteInstanceImpl::GetSiteForURL(browser_context_, url)
.possibly_invalid_spec();
SiteInstanceMap::iterator i = site_instance_map_.find(site);
if (i != site_instance_map_.end())
return i->second;
SiteInstanceImpl* instance = new SiteInstanceImpl(this);
instance->SetSite(url);
return instance;
}
void BrowsingInstance::RegisterSiteInstance(SiteInstance* site_instance) {
DCHECK(static_cast<SiteInstanceImpl*>(site_instance)
->browsing_instance_.get() ==
this);
DCHECK(static_cast<SiteInstanceImpl*>(site_instance)->HasSite());
std::string site = site_instance->GetSiteURL().possibly_invalid_spec();
SiteInstanceMap::iterator i = site_instance_map_.find(site);
if (i == site_instance_map_.end()) {
site_instance_map_[site] = site_instance;
}
}
void BrowsingInstance::UnregisterSiteInstance(SiteInstance* site_instance) {
DCHECK(static_cast<SiteInstanceImpl*>(site_instance)
->browsing_instance_.get() ==
this);
DCHECK(static_cast<SiteInstanceImpl*>(site_instance)->HasSite());
std::string site = site_instance->GetSiteURL().possibly_invalid_spec();
SiteInstanceMap::iterator i = site_instance_map_.find(site);
if (i != site_instance_map_.end() && i->second == site_instance) {
site_instance_map_.erase(i);
}
}
BrowsingInstance::~BrowsingInstance() {
DCHECK(site_instance_map_.empty());
}
}