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

Side by Side 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: Added more unit tests for PrerenderingLoader 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 unified diff | Download patch
OLDNEW
(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 "chrome/browser/prerender/prerender_manager.h"
8 #include "chrome/browser/prerender/prerender_manager_factory.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "content/public/browser/browser_context.h"
11 #include "content/public/browser/web_contents.h"
12 #include "ui/gfx/geometry/size.h"
13
14 namespace offline_pages {
15
16 PrerenderAdapter::PrerenderAdapter() {}
17
18 PrerenderAdapter::~PrerenderAdapter() {
19 if (IsActive())
20 DestroyActive();
21 }
22
23 bool PrerenderAdapter::CanPrerender() const {
24 return prerender::PrerenderManager::ActuallyPrerendering();
25 }
26
27 bool PrerenderAdapter::StartPrerender(
28 content::BrowserContext* browser_context,
29 const GURL& url,
30 content::SessionStorageNamespace* session_storage_namespace,
31 const gfx::Size& size,
32 prerender::PrerenderHandle::Observer* observer) {
33 DCHECK(!IsActive());
34 DCHECK(CanPrerender());
35
36 Profile* profile = Profile::FromBrowserContext(browser_context);
37 prerender::PrerenderManager* manager =
38 prerender::PrerenderManagerFactory::GetForProfile(profile);
39 DCHECK(manager);
40
41 // Start prerendering the url and capture the handle for the prerendering.
42 active_handle_.reset(
43 manager->AddPrerenderForOffline(url, session_storage_namespace, size));
44 if (!active_handle_)
45 return false;
46
47 active_handle_->SetObserver(observer);
48 return true;
49 }
50
51 content::WebContents* PrerenderAdapter::GetWebContents() const {
52 DCHECK(IsActive());
53 DCHECK(active_handle_->contents());
54 // Note: the prerender stack maintains ownership of these contents
55 // and PrerenderingLoader::StopLoading() must be called to report
56 // the Loader is done with the contents.
57 return active_handle_->contents()->prerender_contents();
58 }
59
60 prerender::FinalStatus PrerenderAdapter::GetFinalStatus() const {
61 DCHECK(IsActive());
62 DCHECK(active_handle_->contents());
63 return active_handle_->contents()->final_status();
64 }
65
66 bool PrerenderAdapter::IsActive() const {
67 return active_handle_.get();
68 }
69
70 bool PrerenderAdapter::HasHandle(prerender::PrerenderHandle* handle) const {
71 return active_handle_.get() == handle;
72 }
73
74 void PrerenderAdapter::DestroyActive() {
75 DCHECK(IsActive());
76 active_handle_->OnCancel();
77 active_handle_.reset(nullptr);
78 }
79
80 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698