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

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

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

Powered by Google App Engine
This is Rietveld 408576698