Chromium Code Reviews| 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 #include "content/browser/browsing_instance.h" | 5 #include "content/browser/browsing_instance.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "content/browser/site_instance_impl.h" | 9 #include "content/browser/site_instance_impl.h" |
| 10 #include "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 | 29 |
| 30 SiteInstance* BrowsingInstance::GetSiteInstanceForURL(const GURL& url) { | 30 SiteInstance* BrowsingInstance::GetSiteInstanceForURL(const GURL& url) { |
| 31 std::string site = | 31 std::string site = |
| 32 SiteInstanceImpl::GetSiteForURL(browser_context_, url) | 32 SiteInstanceImpl::GetSiteForURL(browser_context_, url) |
| 33 .possibly_invalid_spec(); | 33 .possibly_invalid_spec(); |
| 34 | 34 |
| 35 SiteInstanceMap::iterator i = site_instance_map_.find(site); | 35 SiteInstanceMap::iterator i = site_instance_map_.find(site); |
| 36 if (i != site_instance_map_.end()) | 36 if (i != site_instance_map_.end()) |
| 37 return i->second; | 37 return i->second; |
| 38 | 38 |
| 39 bool use_doghouse = !site_instance_map_.empty() && | |
| 40 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 41 switches::kDogHouseProcess); | |
| 42 | |
| 43 if (use_doghouse) { | |
| 44 if (SiteInstance* doghouse = GetDoghouseSiteInstance()) { | |
| 45 return doghouse; | |
| 46 } | |
| 47 } | |
| 48 | |
| 39 | 49 |
| 40 // No current SiteInstance for this site, so let's create one. | 50 // No current SiteInstance for this site, so let's create one. |
| 41 SiteInstanceImpl* instance = new SiteInstanceImpl(this); | 51 SiteInstanceImpl* instance = new SiteInstanceImpl(this); |
| 42 | 52 |
| 43 // Set the site of this new SiteInstance, which will register it with us. | 53 // Set the site of this new SiteInstance, which will register it with us. |
| 44 instance->SetSite(url); | 54 instance->SetSite(url); |
| 55 | |
| 56 // TODO(xiaochengh): Say something here... | |
| 57 instance->SetForDoghouse(use_doghouse); | |
|
ncarter (slow)
2016/03/14 17:42:24
I think this choice (of which SiteInstance becomes
| |
| 45 return instance; | 58 return instance; |
| 46 } | 59 } |
| 47 | 60 |
| 61 SiteInstance* BrowsingInstance::GetDoghouseSiteInstance() const { | |
| 62 for (SiteInstanceMap::const_iterator i = site_instance_map_.begin(); | |
| 63 i != site_instance_map_.end(); ++i) { | |
| 64 if (i->second->IsForDoghouse()) | |
| 65 return i->second; | |
| 66 } | |
| 67 return nullptr; | |
| 68 } | |
| 69 | |
| 48 void BrowsingInstance::RegisterSiteInstance(SiteInstance* site_instance) { | 70 void BrowsingInstance::RegisterSiteInstance(SiteInstance* site_instance) { |
| 49 DCHECK(static_cast<SiteInstanceImpl*>(site_instance) | 71 DCHECK(static_cast<SiteInstanceImpl*>(site_instance) |
| 50 ->browsing_instance_.get() == | 72 ->browsing_instance_.get() == |
| 51 this); | 73 this); |
| 52 DCHECK(static_cast<SiteInstanceImpl*>(site_instance)->HasSite()); | 74 DCHECK(static_cast<SiteInstanceImpl*>(site_instance)->HasSite()); |
| 53 std::string site = site_instance->GetSiteURL().possibly_invalid_spec(); | 75 std::string site = site_instance->GetSiteURL().possibly_invalid_spec(); |
| 54 | 76 |
| 55 // Only register if we don't have a SiteInstance for this site already. | 77 // Only register if we don't have a SiteInstance for this site already. |
| 56 // It's possible to have two SiteInstances point to the same site if two | 78 // It's possible to have two SiteInstances point to the same site if two |
| 57 // tabs are navigated there at the same time. (We don't call SetSite or | 79 // tabs are navigated there at the same time. (We don't call SetSite or |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 82 } | 104 } |
| 83 | 105 |
| 84 BrowsingInstance::~BrowsingInstance() { | 106 BrowsingInstance::~BrowsingInstance() { |
| 85 // We should only be deleted when all of the SiteInstances that refer to | 107 // We should only be deleted when all of the SiteInstances that refer to |
| 86 // us are gone. | 108 // us are gone. |
| 87 DCHECK(site_instance_map_.empty()); | 109 DCHECK(site_instance_map_.empty()); |
| 88 DCHECK_EQ(0u, active_contents_count_); | 110 DCHECK_EQ(0u, active_contents_count_); |
| 89 } | 111 } |
| 90 | 112 |
| 91 } // namespace content | 113 } // namespace content |
| OLD | NEW |