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

Side by Side Diff: chrome/browser/android/offline_pages/downloads/offline_page_download_bridge.cc

Issue 2274373002: Hook up the Background Loader to StartDownload for offline pages. (Closed)
Patch Set: nit fix Created 4 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/downloads/offline_page_download_b ridge.h" 5 #include "chrome/browser/android/offline_pages/downloads/offline_page_download_b ridge.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/android/jni_string.h" 9 #include "base/android/jni_string.h"
10 #include "base/guid.h" 10 #include "base/guid.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "chrome/browser/android/offline_pages/downloads/offline_page_notificati on_bridge.h" 12 #include "chrome/browser/android/offline_pages/downloads/offline_page_notificati on_bridge.h"
13 #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h" 13 #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h"
14 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" 14 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h"
15 #include "chrome/browser/android/offline_pages/recent_tab_helper.h"
16 #include "chrome/browser/android/offline_pages/request_coordinator_factory.h"
15 #include "chrome/browser/android/tab_android.h" 17 #include "chrome/browser/android/tab_android.h"
16 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/profiles/profile_android.h" 19 #include "chrome/browser/profiles/profile_android.h"
20 #include "components/offline_pages/background/request_coordinator.h"
18 #include "components/offline_pages/client_namespace_constants.h" 21 #include "components/offline_pages/client_namespace_constants.h"
19 #include "components/offline_pages/downloads/download_ui_item.h" 22 #include "components/offline_pages/downloads/download_ui_item.h"
23 #include "components/offline_pages/offline_page_feature.h"
20 #include "components/offline_pages/offline_page_model.h" 24 #include "components/offline_pages/offline_page_model.h"
21 #include "content/public/browser/web_contents.h" 25 #include "content/public/browser/web_contents.h"
22 #include "jni/OfflinePageDownloadBridge_jni.h" 26 #include "jni/OfflinePageDownloadBridge_jni.h"
23 #include "net/base/filename_util.h" 27 #include "net/base/filename_util.h"
24 #include "url/gurl.h" 28 #include "url/gurl.h"
25 29
26 using base::android::AttachCurrentThread; 30 using base::android::AttachCurrentThread;
27 using base::android::ConvertJavaStringToUTF8; 31 using base::android::ConvertJavaStringToUTF8;
28 using base::android::ConvertUTF8ToJavaString; 32 using base::android::ConvertUTF8ToJavaString;
29 using base::android::ConvertUTF16ToJavaString; 33 using base::android::ConvertUTF16ToJavaString;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 const JavaParamRef<jobject>& obj, 145 const JavaParamRef<jobject>& obj,
142 const JavaParamRef<jobject>& j_tab) { 146 const JavaParamRef<jobject>& j_tab) {
143 TabAndroid* tab = TabAndroid::GetNativeTab(env, j_tab); 147 TabAndroid* tab = TabAndroid::GetNativeTab(env, j_tab);
144 if (!tab) 148 if (!tab)
145 return; 149 return;
146 150
147 content::WebContents* web_contents = tab->web_contents(); 151 content::WebContents* web_contents = tab->web_contents();
148 if (!web_contents) 152 if (!web_contents)
149 return; 153 return;
150 154
155 GURL url = web_contents->GetLastCommittedURL();
156 offline_pages::ClientId client_id;
157 client_id.name_space = offline_pages::kDownloadNamespace;
158 client_id.id = base::GenerateGUID();
159
160 // If the page is not loaded enough to be captured, submit a background loader
161 // request instead.
162 offline_pages::RecentTabHelper* tab_helper =
163 RecentTabHelper::FromWebContents(web_contents);
164 if (tab_helper &&
165 !tab_helper->is_page_ready_for_snapshot() &&
166 offline_pages::IsBackgroundLoaderForDownloadsEnabled()) {
167 // TODO(dimich): Improve this to wait for the page load if it is still going
168 // on. Pre-submit the request and if the load finishes and capture happens,
169 // remove request.
170 offline_pages::RequestCoordinator* request_coordinator =
171 offline_pages::RequestCoordinatorFactory::GetForBrowserContext(
172 tab->GetProfile()->GetOriginalProfile());
173 request_coordinator->SavePageLater(url, client_id, true);
174 return;
175 }
176
177 // Page is ready, capture it right from the tab.
151 offline_pages::OfflinePageModel* offline_page_model = 178 offline_pages::OfflinePageModel* offline_page_model =
152 OfflinePageModelFactory::GetForBrowserContext( 179 OfflinePageModelFactory::GetForBrowserContext(
153 tab->GetProfile()->GetOriginalProfile()); 180 tab->GetProfile()->GetOriginalProfile());
154 if (!offline_page_model) 181 if (!offline_page_model)
155 return; 182 return;
156 183
157 GURL url = web_contents->GetLastCommittedURL();
158 auto archiver = 184 auto archiver =
159 base::MakeUnique<offline_pages::OfflinePageMHTMLArchiver>(web_contents); 185 base::MakeUnique<offline_pages::OfflinePageMHTMLArchiver>(web_contents);
160 186
161 offline_pages::ClientId client_id;
162 client_id.name_space = offline_pages::kDownloadNamespace;
163 client_id.id = base::GenerateGUID();
164
165 DownloadUIItem item; 187 DownloadUIItem item;
166 item.guid = client_id.id; 188 item.guid = client_id.id;
167 item.url = url; 189 item.url = url;
168 190
169 OfflinePageNotificationBridge bridge; 191 OfflinePageNotificationBridge bridge;
170 bridge.NotifyDownloadProgress(item); 192 bridge.NotifyDownloadProgress(item);
171 193
172 offline_page_model->SavePage( 194 offline_page_model->SavePage(
173 url, client_id, 0ul, std::move(archiver), 195 url, client_id, 0ul, std::move(archiver),
174 base::Bind(&OfflinePageDownloadBridge::SavePageCallback, item)); 196 base::Bind(&OfflinePageDownloadBridge::SavePageCallback, item));
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 240
219 DownloadUIAdapter* adapter = 241 DownloadUIAdapter* adapter =
220 DownloadUIAdapter::FromOfflinePageModel(offline_page_model); 242 DownloadUIAdapter::FromOfflinePageModel(offline_page_model);
221 243
222 return reinterpret_cast<jlong>( 244 return reinterpret_cast<jlong>(
223 new OfflinePageDownloadBridge(env, obj, adapter)); 245 new OfflinePageDownloadBridge(env, obj, adapter));
224 } 246 }
225 247
226 } // namespace android 248 } // namespace android
227 } // namespace offline_pages 249 } // namespace offline_pages
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698