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

Side by Side Diff: chrome/browser/net/net_error_tab_helper.cc

Issue 2698593002: (Android) Blocking multiple scheduled downloads for the same URL (Closed)
Patch Set: Patch Created 3 years, 10 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/net/net_error_tab_helper.h" 5 #include "chrome/browser/net/net_error_tab_helper.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/io_thread.h" 10 #include "chrome/browser/io_thread.h"
(...skipping 11 matching lines...) Expand all
22 #include "content/public/browser/render_frame_host.h" 22 #include "content/public/browser/render_frame_host.h"
23 #include "content/public/common/associated_interface_provider.h" 23 #include "content/public/common/associated_interface_provider.h"
24 #include "ipc/ipc_message_macros.h" 24 #include "ipc/ipc_message_macros.h"
25 #include "net/base/net_errors.h" 25 #include "net/base/net_errors.h"
26 #include "url/gurl.h" 26 #include "url/gurl.h"
27 27
28 #if defined(OS_ANDROID) 28 #if defined(OS_ANDROID)
29 #include "base/guid.h" 29 #include "base/guid.h"
30 #include "chrome/browser/android/offline_pages/request_coordinator_factory.h" 30 #include "chrome/browser/android/offline_pages/request_coordinator_factory.h"
31 #include "components/offline_pages/core/background/request_coordinator.h" 31 #include "components/offline_pages/core/background/request_coordinator.h"
32 #include "components/offline_pages/core/background/save_page_request.h"
32 #include "components/offline_pages/core/client_namespace_constants.h" 33 #include "components/offline_pages/core/client_namespace_constants.h"
33 #endif // defined(OS_ANDROID) 34 #endif // defined(OS_ANDROID)
34 35
35 using content::BrowserContext; 36 using content::BrowserContext;
36 using content::BrowserThread; 37 using content::BrowserThread;
37 using content::WebContents; 38 using content::WebContents;
38 using content::WebContentsObserver; 39 using content::WebContentsObserver;
39 using error_page::DnsProbeStatus; 40 using error_page::DnsProbeStatus;
40 using error_page::DnsProbeStatusToString; 41 using error_page::DnsProbeStatusToString;
41 using ui::PageTransition; 42 using ui::PageTransition;
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 290
290 ShowNetworkDiagnosticsDialog(web_contents(), sanitized_url); 291 ShowNetworkDiagnosticsDialog(web_contents(), sanitized_url);
291 } 292 }
292 293
293 #if defined(OS_ANDROID) 294 #if defined(OS_ANDROID)
294 void NetErrorTabHelper::DownloadPageLaterHelper(const GURL& page_url) { 295 void NetErrorTabHelper::DownloadPageLaterHelper(const GURL& page_url) {
295 offline_pages::RequestCoordinator* request_coordinator = 296 offline_pages::RequestCoordinator* request_coordinator =
296 offline_pages::RequestCoordinatorFactory::GetForBrowserContext( 297 offline_pages::RequestCoordinatorFactory::GetForBrowserContext(
297 web_contents()->GetBrowserContext()); 298 web_contents()->GetBrowserContext());
298 DCHECK(request_coordinator) << "No RequestCoordinator for SavePageLater"; 299 DCHECK(request_coordinator) << "No RequestCoordinator for SavePageLater";
299 offline_pages::ClientId client_id( 300
300 offline_pages::kAsyncNamespace, base::GenerateGUID()); 301 auto request_coordinator_continuation = [](
Dmitry Titov 2017/02/17 02:40:59 I think this will be a suboptimal UX - there will
marcin 2017/02/17 08:02:32 Button will do something -> will change to Downloa
301 request_coordinator->SavePageLater( 302 offline_pages::RequestCoordinator* req_coordinator,
302 page_url, client_id, true /*user_requested*/, 303 const GURL& download_url,
303 offline_pages::RequestCoordinator::RequestAvailability:: 304 std::vector<std::unique_ptr<offline_pages::SavePageRequest>> requests) {
304 ENABLED_FOR_OFFLINER); 305 bool found = false;
306 for (auto& request : requests) {
307 if (request->url() == download_url) {
308 found = true;
309 break;
310 }
311 }
312 if (!found) {
313 offline_pages::ClientId client_id(offline_pages::kAsyncNamespace,
314 base::GenerateGUID());
315 req_coordinator->SavePageLater(
316 download_url, client_id, true /*user_requested*/,
317 offline_pages::RequestCoordinator::RequestAvailability::
318 ENABLED_FOR_OFFLINER);
319 }
320 };
321
322 request_coordinator->GetAllRequests(base::Bind(
323 request_coordinator_continuation, request_coordinator, page_url));
305 } 324 }
306 #endif // defined(OS_ANDROID) 325 #endif // defined(OS_ANDROID)
307 326
308 } // namespace chrome_browser_net 327 } // namespace chrome_browser_net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698