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

Side by Side Diff: content/browser/background_fetch/background_fetch_job_controller.cc

Issue 2829443002: Give Background Fetch downloads an explicit path on Android (Closed)
Patch Set: Created 3 years, 8 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "content/browser/background_fetch/background_fetch_job_controller.h" 5 #include "content/browser/background_fetch/background_fetch_job_controller.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "content/browser/background_fetch/background_fetch_constants.h" 12 #include "content/browser/background_fetch/background_fetch_constants.h"
13 #include "content/browser/background_fetch/background_fetch_data_manager.h" 13 #include "content/browser/background_fetch/background_fetch_data_manager.h"
14 #include "content/common/service_worker/service_worker_types.h" 14 #include "content/common/service_worker/service_worker_types.h"
15 #include "content/public/browser/browser_context.h" 15 #include "content/public/browser/browser_context.h"
16 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/download_interrupt_reasons.h" 17 #include "content/public/browser/download_interrupt_reasons.h"
18 #include "content/public/browser/download_manager.h" 18 #include "content/public/browser/download_manager.h"
19 #include "net/url_request/url_request_context_getter.h" 19 #include "net/url_request/url_request_context_getter.h"
20 20
21 #if defined(OS_ANDROID)
22 #include "base/android/path_utils.h"
23 #include "base/files/file_path.h"
24 #include "base/guid.h"
25 #endif
26
21 namespace content { 27 namespace content {
22 28
29 #if defined(OS_ANDROID)
30 namespace {
31
32 // Prefix for files stored in the Chromium-internal download directory to
33 // indicate files thta were fetched through Background Fetch.
shaktisahu 2017/04/18 20:16:56 nit: typo
34 const char kBackgroundFetchFilePrefix[] = "BGFetch-";
35
36 } // namespace
37 #endif // defined(OS_ANDROID)
38
23 // Internal functionality of the BackgroundFetchJobController that lives on the 39 // Internal functionality of the BackgroundFetchJobController that lives on the
24 // UI thread, where all interaction with the download manager must happen. 40 // UI thread, where all interaction with the download manager must happen.
25 class BackgroundFetchJobController::Core : public DownloadItem::Observer { 41 class BackgroundFetchJobController::Core : public DownloadItem::Observer {
26 public: 42 public:
27 Core(const base::WeakPtr<BackgroundFetchJobController>& io_parent, 43 Core(const base::WeakPtr<BackgroundFetchJobController>& io_parent,
28 BrowserContext* browser_context, 44 BrowserContext* browser_context,
29 scoped_refptr<net::URLRequestContextGetter> request_context) 45 scoped_refptr<net::URLRequestContextGetter> request_context)
30 : io_parent_(io_parent), 46 : io_parent_(io_parent),
31 browser_context_(browser_context), 47 browser_context_(browser_context),
32 request_context_(std::move(request_context)), 48 request_context_(std::move(request_context)),
(...skipping 19 matching lines...) Expand all
52 68
53 const ServiceWorkerFetchRequest& fetch_request = request->fetch_request(); 69 const ServiceWorkerFetchRequest& fetch_request = request->fetch_request();
54 70
55 std::unique_ptr<DownloadUrlParameters> download_parameters( 71 std::unique_ptr<DownloadUrlParameters> download_parameters(
56 base::MakeUnique<DownloadUrlParameters>(fetch_request.url, 72 base::MakeUnique<DownloadUrlParameters>(fetch_request.url,
57 request_context_.get())); 73 request_context_.get()));
58 74
59 // TODO(peter): The |download_parameters| should be populated with all the 75 // TODO(peter): The |download_parameters| should be populated with all the
60 // properties set in the |fetch_request| structure. 76 // properties set in the |fetch_request| structure.
61 77
78 // TODO(peter): Background Fetch responses should not end up in the user's
79 // download folder on any platform. Find an appropriate solution for desktop
80 // too. The Android internal directory is not scoped to a profile.
81
62 download_parameters->set_transient(true); 82 download_parameters->set_transient(true);
83
84 #if defined(OS_ANDROID)
85 base::FilePath download_directory;
86 if (base::android::GetDownloadInternalDirectory(&download_directory)) {
87 download_parameters->set_file_path(download_directory.Append(
88 std::string(kBackgroundFetchFilePrefix) + base::GenerateGUID()));
89 }
90 #endif // defined(OS_ANDROID)
91
63 download_parameters->set_callback(base::Bind(&Core::DidStartRequest, 92 download_parameters->set_callback(base::Bind(&Core::DidStartRequest,
64 weak_ptr_factory_.GetWeakPtr(), 93 weak_ptr_factory_.GetWeakPtr(),
65 std::move(request))); 94 std::move(request)));
66 95
67 download_manager->DownloadUrl(std::move(download_parameters)); 96 download_manager->DownloadUrl(std::move(download_parameters));
68 } 97 }
69 98
70 // DownloadItem::Observer overrides: 99 // DownloadItem::Observer overrides:
71 void OnDownloadUpdated(DownloadItem* download_item) override { 100 void OnDownloadUpdated(DownloadItem* download_item) override {
72 DCHECK_CURRENTLY_ON(BrowserThread::UI); 101 DCHECK_CURRENTLY_ON(BrowserThread::UI);
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 292
264 // TODO(harkness): Abort all in-progress downloads. 293 // TODO(harkness): Abort all in-progress downloads.
265 294
266 state_ = State::ABORTED; 295 state_ = State::ABORTED;
267 296
268 // Inform the owner of the controller about the job having completed. 297 // Inform the owner of the controller about the job having completed.
269 std::move(completed_callback_).Run(this); 298 std::move(completed_callback_).Run(this);
270 } 299 }
271 300
272 } // namespace content 301 } // namespace content
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