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

Side by Side Diff: chrome/browser/android/offline_pages/prerendering_offliner.cc

Issue 2234873004: Have the RequestCoordinator generate the offline_id (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge, and CR fixes per Dimich Created 4 years, 4 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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 "chrome/browser/android/offline_pages/prerendering_offliner.h" 5 #include "chrome/browser/android/offline_pages/prerendering_offliner.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/sys_info.h" 8 #include "base/sys_info.h"
9 #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h" 9 #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h"
10 #include "components/offline_pages/background/save_page_request.h" 10 #include "components/offline_pages/background/save_page_request.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 // WebContents are being destroyed) - whichever callback occurs first. 54 // WebContents are being destroyed) - whichever callback occurs first.
55 DCHECK(web_contents); 55 DCHECK(web_contents);
56 std::unique_ptr<OfflinePageArchiver> archiver( 56 std::unique_ptr<OfflinePageArchiver> archiver(
57 new OfflinePageMHTMLArchiver(web_contents)); 57 new OfflinePageMHTMLArchiver(web_contents));
58 // Pass in the URL from the WebContents in case it is redirected from 58 // Pass in the URL from the WebContents in case it is redirected from
59 // the requested URL. This is to work around a check in the 59 // the requested URL. This is to work around a check in the
60 // OfflinePageModel implementation that ensures URL passed in here is 60 // OfflinePageModel implementation that ensures URL passed in here is
61 // same as LastCommittedURL from the snapshot. 61 // same as LastCommittedURL from the snapshot.
62 // TODO(dougarnett): Raise issue of how to better deal with redirects. 62 // TODO(dougarnett): Raise issue of how to better deal with redirects.
63 SavePage(web_contents->GetLastCommittedURL(), request.client_id(), 63 SavePage(web_contents->GetLastCommittedURL(), request.client_id(),
64 std::move(archiver), 64 request.request_id(), std::move(archiver),
65 base::Bind(&PrerenderingOffliner::OnSavePageDone, 65 base::Bind(&PrerenderingOffliner::OnSavePageDone,
66 weak_ptr_factory_.GetWeakPtr(), request)); 66 weak_ptr_factory_.GetWeakPtr(), request));
67 } else { 67 } else {
68 // Clear pending request and app listener then run completion callback. 68 // Clear pending request and app listener then run completion callback.
69 pending_request_.reset(nullptr); 69 pending_request_.reset(nullptr);
70 app_listener_.reset(nullptr); 70 app_listener_.reset(nullptr);
71 completion_callback_.Run(request, load_status); 71 completion_callback_.Run(request, load_status);
72 } 72 }
73 } 73 }
74 74
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 } 164 }
165 165
166 void PrerenderingOffliner::SetApplicationStateForTesting( 166 void PrerenderingOffliner::SetApplicationStateForTesting(
167 base::android::ApplicationState application_state) { 167 base::android::ApplicationState application_state) {
168 OnApplicationStateChange(application_state); 168 OnApplicationStateChange(application_state);
169 } 169 }
170 170
171 void PrerenderingOffliner::SavePage( 171 void PrerenderingOffliner::SavePage(
172 const GURL& url, 172 const GURL& url,
173 const ClientId& client_id, 173 const ClientId& client_id,
174 int64_t proposed_offline_id,
174 std::unique_ptr<OfflinePageArchiver> archiver, 175 std::unique_ptr<OfflinePageArchiver> archiver,
175 const SavePageCallback& save_callback) { 176 const SavePageCallback& save_callback) {
176 DCHECK(offline_page_model_); 177 DCHECK(offline_page_model_);
177 offline_page_model_->SavePage(url, client_id, std::move(archiver), 178 offline_page_model_->SavePage(url, client_id, proposed_offline_id,
178 save_callback); 179 std::move(archiver), save_callback);
179 } 180 }
180 181
181 PrerenderingLoader* PrerenderingOffliner::GetOrCreateLoader() { 182 PrerenderingLoader* PrerenderingOffliner::GetOrCreateLoader() {
182 if (!loader_) { 183 if (!loader_) {
183 loader_.reset(new PrerenderingLoader(browser_context_)); 184 loader_.reset(new PrerenderingLoader(browser_context_));
184 } 185 }
185 return loader_.get(); 186 return loader_.get();
186 } 187 }
187 188
188 void PrerenderingOffliner::OnApplicationStateChange( 189 void PrerenderingOffliner::OnApplicationStateChange(
189 base::android::ApplicationState application_state) { 190 base::android::ApplicationState application_state) {
190 if (pending_request_ && is_low_end_device_ && 191 if (pending_request_ && is_low_end_device_ &&
191 application_state == 192 application_state ==
192 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES) { 193 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES) {
193 DVLOG(1) << "App became active, canceling current offlining request"; 194 DVLOG(1) << "App became active, canceling current offlining request";
194 SavePageRequest* request = pending_request_.get(); 195 SavePageRequest* request = pending_request_.get();
195 Cancel(); 196 Cancel();
196 completion_callback_.Run(*request, 197 completion_callback_.Run(*request,
197 Offliner::RequestStatus::FOREGROUND_CANCELED); 198 Offliner::RequestStatus::FOREGROUND_CANCELED);
198 } 199 }
199 } 200 }
200 201
201 } // namespace offline_pages 202 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698