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

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

Issue 10905284: Use the user's preferred downloads directory for creating the initial download file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Windows path check Created 8 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 | Annotate | Revision Log
« no previous file with comments | « content/browser/download/base_file.h ('k') | content/browser/download/base_file_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/base_file.h" 5 #include "content/browser/download/base_file.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 } 238 }
239 239
240 BaseFile::~BaseFile() { 240 BaseFile::~BaseFile() {
241 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 241 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
242 if (detached_) 242 if (detached_)
243 Close(); 243 Close();
244 else 244 else
245 Cancel(); // Will delete the file. 245 Cancel(); // Will delete the file.
246 } 246 }
247 247
248 net::Error BaseFile::Initialize() { 248 net::Error BaseFile::Initialize(const FilePath& default_directory) {
249 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 249 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
250 DCHECK(!detached_); 250 DCHECK(!detached_);
251 251
252 if (full_path_.empty()) { 252 if (full_path_.empty()) {
253 FilePath initial_directory(default_directory);
253 FilePath temp_file; 254 FilePath temp_file;
254 FilePath download_dir = 255 if (initial_directory.empty()) {
255 content::GetContentClient()->browser()->GetDefaultDownloadDirectory(); 256 initial_directory =
256 if (!file_util::CreateTemporaryFileInDir(download_dir, &temp_file) && 257 content::GetContentClient()->browser()->GetDefaultDownloadDirectory();
258 }
259 // |initial_directory| can still be empty if ContentBrowserClient returned
260 // an empty path for the downloads directory.
261 if ((initial_directory.empty() ||
262 !file_util::CreateTemporaryFileInDir(initial_directory, &temp_file)) &&
257 !file_util::CreateTemporaryFile(&temp_file)) { 263 !file_util::CreateTemporaryFile(&temp_file)) {
258 return LOG_ERROR("unable to create", net::ERR_FILE_NOT_FOUND); 264 return LOG_ERROR("unable to create", net::ERR_FILE_NOT_FOUND);
259 } 265 }
260 full_path_ = temp_file; 266 full_path_ = temp_file;
261 } 267 }
262 268
263 return Open(); 269 return Open();
264 } 270 }
265 271
266 net::Error BaseFile::AppendDataToFile(const char* data, size_t data_len) { 272 net::Error BaseFile::AppendDataToFile(const char* data, size_t data_len) {
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 int64 BaseFile::CurrentSpeedAtTime(base::TimeTicks current_time) const { 556 int64 BaseFile::CurrentSpeedAtTime(base::TimeTicks current_time) const {
551 base::TimeDelta diff = current_time - start_tick_; 557 base::TimeDelta diff = current_time - start_tick_;
552 int64 diff_ms = diff.InMilliseconds(); 558 int64 diff_ms = diff.InMilliseconds();
553 return diff_ms == 0 ? 0 : bytes_so_far() * 1000 / diff_ms; 559 return diff_ms == 0 ? 0 : bytes_so_far() * 1000 / diff_ms;
554 } 560 }
555 561
556 int64 BaseFile::CurrentSpeed() const { 562 int64 BaseFile::CurrentSpeed() const {
557 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 563 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
558 return CurrentSpeedAtTime(base::TimeTicks::Now()); 564 return CurrentSpeedAtTime(base::TimeTicks::Now());
559 } 565 }
560
OLDNEW
« no previous file with comments | « content/browser/download/base_file.h ('k') | content/browser/download/base_file_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698