Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/android/offline_pages/prerender_adapter.h" | |
| 6 | |
| 7 #include "base/location.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "chrome/browser/android/offline_pages/prerendering_loader.h" | |
| 10 #include "chrome/browser/prerender/prerender_manager_factory.h" | |
| 11 #include "chrome/browser/profiles/profile.h" | |
| 12 #include "content/public/browser/browser_context.h" | |
| 13 #include "content/public/browser/web_contents.h" | |
| 14 #include "ui/gfx/geometry/size.h" | |
| 15 | |
| 16 namespace offline_pages { | |
| 17 | |
| 18 PrerenderAdapter::PrerenderAdapter() {} | |
| 19 | |
| 20 PrerenderAdapter::~PrerenderAdapter() { | |
| 21 DestroyActive(); | |
| 22 } | |
| 23 | |
| 24 bool PrerenderAdapter::CanPrerender() const { | |
| 25 return prerender::PrerenderManager::ActuallyPrerendering(); | |
| 26 } | |
| 27 | |
| 28 bool PrerenderAdapter::StartPrerender( | |
| 29 content::BrowserContext* browser_context, | |
| 30 const GURL& url, | |
| 31 content::SessionStorageNamespace* session_storage_namespace, | |
| 32 const gfx::Size& size, | |
| 33 prerender::PrerenderHandle::Observer* observer) { | |
| 34 DCHECK(!IsActive()); | |
| 35 DCHECK(CanPrerender()); | |
| 36 | |
| 37 Profile* profile = Profile::FromBrowserContext(browser_context); | |
| 38 prerender::PrerenderManager* manager = | |
| 39 prerender::PrerenderManagerFactory::GetForProfile(profile); | |
| 40 DCHECK(manager); | |
| 41 | |
| 42 // Start prerendering the url and capture the handle for the prerendering. | |
| 43 active_handle_.reset( | |
| 44 manager->AddPrerenderForOffline(url, session_storage_namespace, size)); | |
| 45 if (!active_handle_) | |
| 46 return false; | |
| 47 | |
| 48 active_handle_->SetObserver(observer); | |
| 49 return true; | |
| 50 } | |
| 51 | |
| 52 bool PrerenderAdapter::IsPrerendering() const { | |
| 53 DCHECK(IsActive()); | |
|
fgorski
2016/05/17 05:09:51
I am wondering why you decided on a DCHECK here.
w
pasko
2016/05/17 15:34:20
I would support the DCHECK because the adapter is
fgorski
2016/05/17 15:54:54
IsActive() is not a fall through but statement of
pasko
2016/05/17 16:26:31
There are only two methods that can affect this bi
fgorski
2016/05/17 17:06:19
Let's have Doug digest it and try to come up with
dougarnett
2016/05/18 00:37:46
Simplifying by dropping IsPrerendering() altogethe
| |
| 54 return active_handle_->IsPrerendering(); | |
| 55 } | |
| 56 | |
| 57 content::WebContents* PrerenderAdapter::GetWebContents() const { | |
| 58 DCHECK(IsActive()); | |
| 59 if (active_handle_->contents()) { | |
| 60 // Note: the prerender stack maintains ownership of these contents | |
| 61 // and PrerenderingLoader::StopLoading() must be called to report | |
| 62 // the Loader is done with the contents. | |
| 63 return active_handle_->contents()->prerender_contents(); | |
| 64 } | |
| 65 return nullptr; | |
| 66 } | |
| 67 | |
| 68 prerender::FinalStatus PrerenderAdapter::GetFinalStatus() const { | |
| 69 DCHECK(IsActive()); | |
| 70 DCHECK(active_handle_->contents()); | |
|
fgorski
2016/05/17 05:09:51
why is there a difference between GetWebContents a
dougarnett
2016/05/18 00:37:46
Put DCHECK in other one
| |
| 71 return active_handle_->contents()->final_status(); | |
| 72 } | |
| 73 | |
| 74 bool PrerenderAdapter::IsActive() const { | |
| 75 return active_handle_.get(); | |
| 76 } | |
| 77 | |
| 78 bool PrerenderAdapter::HasHandle(prerender::PrerenderHandle* handle) const { | |
| 79 return active_handle_.get() == handle; | |
| 80 } | |
| 81 | |
| 82 void PrerenderAdapter::DestroyActive() { | |
| 83 if (IsActive()) { | |
|
pasko
2016/05/17 15:34:20
We are checking for the same condition in prerende
dougarnett
2016/05/18 00:37:46
Ok, I will move this IsActive() condition into the
| |
| 84 active_handle_->OnCancel(); | |
| 85 active_handle_.reset(nullptr); | |
| 86 } | |
| 87 } | |
| 88 | |
| 89 } // namespace offline_pages | |
| OLD | NEW |