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

Unified Diff: chrome/browser/android/offline_pages/prerender_adapter.cc

Issue 1968593002: PrerenderingLoader initial integration with PrerenderManager/PrerenderHandle (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: uninlined ObserverDelegate impl Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/offline_pages/prerender_adapter.cc
diff --git a/chrome/browser/android/offline_pages/prerender_adapter.cc b/chrome/browser/android/offline_pages/prerender_adapter.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c451b4ea3c81daf9ecd70c233d6c644fc1f7c48b
--- /dev/null
+++ b/chrome/browser/android/offline_pages/prerender_adapter.cc
@@ -0,0 +1,89 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/android/offline_pages/prerender_adapter.h"
+
+#include "base/location.h"
+#include "base/logging.h"
+#include "chrome/browser/android/offline_pages/prerendering_loader.h"
+#include "chrome/browser/prerender/prerender_manager_factory.h"
+#include "chrome/browser/profiles/profile.h"
+#include "content/public/browser/browser_context.h"
+#include "content/public/browser/web_contents.h"
+#include "ui/gfx/geometry/size.h"
+
+namespace offline_pages {
+
+PrerenderAdapter::PrerenderAdapter() {}
+
+PrerenderAdapter::~PrerenderAdapter() {
+ DestroyActive();
+}
+
+bool PrerenderAdapter::CanPrerender() const {
+ return prerender::PrerenderManager::ActuallyPrerendering();
+}
+
+bool PrerenderAdapter::StartPrerender(
+ content::BrowserContext* browser_context,
+ const GURL& url,
+ content::SessionStorageNamespace* session_storage_namespace,
+ const gfx::Size& size,
+ prerender::PrerenderHandle::Observer* observer) {
+ DCHECK(!IsActive());
+ DCHECK(CanPrerender());
+
+ Profile* profile = Profile::FromBrowserContext(browser_context);
+ prerender::PrerenderManager* manager =
+ prerender::PrerenderManagerFactory::GetForProfile(profile);
+ DCHECK(manager);
+
+ // Start prerendering the url and capture the handle for the prerendering.
+ active_handle_.reset(
+ manager->AddPrerenderForOffline(url, session_storage_namespace, size));
+ if (!active_handle_)
+ return false;
+
+ active_handle_->SetObserver(observer);
+ return true;
+}
+
+bool PrerenderAdapter::IsPrerendering() const {
+ 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
+ return active_handle_->IsPrerendering();
+}
+
+content::WebContents* PrerenderAdapter::GetWebContents() const {
+ DCHECK(IsActive());
+ if (active_handle_->contents()) {
+ // Note: the prerender stack maintains ownership of these contents
+ // and PrerenderingLoader::StopLoading() must be called to report
+ // the Loader is done with the contents.
+ return active_handle_->contents()->prerender_contents();
+ }
+ return nullptr;
+}
+
+prerender::FinalStatus PrerenderAdapter::GetFinalStatus() const {
+ DCHECK(IsActive());
+ 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
+ return active_handle_->contents()->final_status();
+}
+
+bool PrerenderAdapter::IsActive() const {
+ return active_handle_.get();
+}
+
+bool PrerenderAdapter::HasHandle(prerender::PrerenderHandle* handle) const {
+ return active_handle_.get() == handle;
+}
+
+void PrerenderAdapter::DestroyActive() {
+ 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
+ active_handle_->OnCancel();
+ active_handle_.reset(nullptr);
+ }
+}
+
+} // namespace offline_pages

Powered by Google App Engine
This is Rietveld 408576698