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

Side by Side Diff: content/browser/download/download_manager_impl.cc

Issue 2948443002: [Merge to M60] Change linux default hidden file save directory to XDG_DATA_HOME (Closed)
Patch Set: Created 3 years, 6 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 | content/browser/download/download_manager_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "content/browser/download/download_manager_impl.h" 5 #include "content/browser/download/download_manager_impl.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 #include "net/base/elements_upload_data_stream.h" 48 #include "net/base/elements_upload_data_stream.h"
49 #include "net/base/load_flags.h" 49 #include "net/base/load_flags.h"
50 #include "net/base/request_priority.h" 50 #include "net/base/request_priority.h"
51 #include "net/base/upload_bytes_element_reader.h" 51 #include "net/base/upload_bytes_element_reader.h"
52 #include "net/log/net_log_source_type.h" 52 #include "net/log/net_log_source_type.h"
53 #include "net/log/net_log_with_source.h" 53 #include "net/log/net_log_with_source.h"
54 #include "net/url_request/url_request_context.h" 54 #include "net/url_request/url_request_context.h"
55 #include "storage/browser/blob/blob_url_request_job_factory.h" 55 #include "storage/browser/blob/blob_url_request_job_factory.h"
56 #include "url/origin.h" 56 #include "url/origin.h"
57 57
58 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
59 #include "base/nix/xdg_util.h"
60 #endif
61
58 namespace content { 62 namespace content {
59 namespace { 63 namespace {
60 64
61 std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread> BeginDownload( 65 std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread> BeginDownload(
62 std::unique_ptr<DownloadUrlParameters> params, 66 std::unique_ptr<DownloadUrlParameters> params,
63 content::ResourceContext* resource_context, 67 content::ResourceContext* resource_context,
64 uint32_t download_id, 68 uint32_t download_id,
65 base::WeakPtr<DownloadManagerImpl> download_manager) { 69 base::WeakPtr<DownloadManagerImpl> download_manager) {
66 DCHECK_CURRENTLY_ON(BrowserThread::IO); 70 DCHECK_CURRENTLY_ON(BrowserThread::IO);
67 71
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 const base::FilePath& path, 171 const base::FilePath& path,
168 const GURL& url, 172 const GURL& url,
169 const std::string& mime_type, 173 const std::string& mime_type,
170 std::unique_ptr<DownloadRequestHandleInterface> request_handle, 174 std::unique_ptr<DownloadRequestHandleInterface> request_handle,
171 const net::NetLogWithSource& net_log) override { 175 const net::NetLogWithSource& net_log) override {
172 return new DownloadItemImpl(delegate, download_id, path, url, mime_type, 176 return new DownloadItemImpl(delegate, download_id, path, url, mime_type,
173 std::move(request_handle), net_log); 177 std::move(request_handle), net_log);
174 } 178 }
175 }; 179 };
176 180
181 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
182 base::FilePath GetTemporaryDownloadDirectory() {
183 std::unique_ptr<base::Environment> env(base::Environment::Create());
184 return base::nix::GetXDGDirectory(env.get(), "XDG_DATA_HOME", ".local/share");
185 }
186 #endif
187
177 } // namespace 188 } // namespace
178 189
179 DownloadManagerImpl::DownloadManagerImpl(net::NetLog* net_log, 190 DownloadManagerImpl::DownloadManagerImpl(net::NetLog* net_log,
180 BrowserContext* browser_context) 191 BrowserContext* browser_context)
181 : item_factory_(new DownloadItemFactoryImpl()), 192 : item_factory_(new DownloadItemFactoryImpl()),
182 file_factory_(new DownloadFileFactory()), 193 file_factory_(new DownloadFileFactory()),
183 shutdown_needed_(true), 194 shutdown_needed_(true),
184 initialized_(false), 195 initialized_(false),
185 browser_context_(browser_context), 196 browser_context_(browser_context),
186 delegate_(nullptr), 197 delegate_(nullptr),
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 // The ByteStreamReader lives and dies on the FILE thread. 363 // The ByteStreamReader lives and dies on the FILE thread.
353 if (info->result == DOWNLOAD_INTERRUPT_REASON_NONE) 364 if (info->result == DOWNLOAD_INTERRUPT_REASON_NONE)
354 BrowserThread::DeleteSoon(BrowserThread::FILE, FROM_HERE, 365 BrowserThread::DeleteSoon(BrowserThread::FILE, FROM_HERE,
355 stream.release()); 366 stream.release());
356 return; 367 return;
357 } 368 }
358 download = item_iterator->second.get(); 369 download = item_iterator->second.get();
359 } 370 }
360 371
361 base::FilePath default_download_directory; 372 base::FilePath default_download_directory;
373 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
374 // TODO(thomasanderson): Remove this when all Linux distros with
375 // versions of GTK lower than 3.14.7 are no longer supported. This
376 // should happen when support for Ubuntu Trusty and Debian Jessie
377 // are removed.
378 default_download_directory = GetTemporaryDownloadDirectory();
379 #else
362 if (delegate_) { 380 if (delegate_) {
363 base::FilePath website_save_directory; // Unused 381 base::FilePath website_save_directory; // Unused
364 bool skip_dir_check = false; // Unused 382 bool skip_dir_check = false; // Unused
365 delegate_->GetSaveDir(GetBrowserContext(), &website_save_directory, 383 delegate_->GetSaveDir(GetBrowserContext(), &website_save_directory,
366 &default_download_directory, &skip_dir_check); 384 &default_download_directory, &skip_dir_check);
367 } 385 }
386 #endif
368 387
369 std::unique_ptr<DownloadFile> download_file; 388 std::unique_ptr<DownloadFile> download_file;
370 389
371 if (info->result == DOWNLOAD_INTERRUPT_REASON_NONE) { 390 if (info->result == DOWNLOAD_INTERRUPT_REASON_NONE) {
372 DCHECK(stream.get()); 391 DCHECK(stream.get());
373 download_file.reset(file_factory_->CreateFile( 392 download_file.reset(file_factory_->CreateFile(
374 std::move(info->save_info), default_download_directory, 393 std::move(info->save_info), default_download_directory,
375 std::move(stream), download->GetNetLogWithSource(), 394 std::move(stream), download->GetNetLogWithSource(),
376 download->DestinationObserverAsWeakPtr())); 395 download->DestinationObserverAsWeakPtr()));
377 } 396 }
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 if (delegate_) 778 if (delegate_)
760 delegate_->OpenDownload(download); 779 delegate_->OpenDownload(download);
761 } 780 }
762 781
763 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { 782 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) {
764 if (delegate_) 783 if (delegate_)
765 delegate_->ShowDownloadInShell(download); 784 delegate_->ShowDownloadInShell(download);
766 } 785 }
767 786
768 } // namespace content 787 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/download/download_manager_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698