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

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

Issue 6973052: When the download folder does not exist, change the download folder to a user's "Downloads" (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Overrides the user's "Downloads" folder in DownloadPrefs Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/download/base_file.h" 5 #include "chrome/browser/download/base_file.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/format_macros.h" 8 #include "base/format_macros.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
(...skipping 28 matching lines...) Expand all
39 } 39 }
40 40
41 BaseFile::~BaseFile() { 41 BaseFile::~BaseFile() {
42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
43 if (detached_) 43 if (detached_)
44 Close(); 44 Close();
45 else 45 else
46 Cancel(); // Will delete the file. 46 Cancel(); // Will delete the file.
47 } 47 }
48 48
49 bool BaseFile::Initialize(bool calculate_hash) { 49 bool BaseFile::Initialize(bool calculate_hash, const FilePath& save_path) {
50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
51 DCHECK(!detached_); 51 DCHECK(!detached_);
52 52
53 calculate_hash_ = calculate_hash; 53 calculate_hash_ = calculate_hash;
54 54
55 if (calculate_hash_) 55 if (calculate_hash_)
56 secure_hash_.reset(crypto::SecureHash::Create(crypto::SecureHash::SHA256)); 56 secure_hash_.reset(crypto::SecureHash::Create(crypto::SecureHash::SHA256));
57 57
58 if (!full_path_.empty() || 58 if (full_path_.empty()) {
59 download_util::CreateTemporaryFileForDownload(&full_path_)) 59 if (!file_util::CreateTemporaryFileInDir(save_path, &full_path_))
Paweł Hajdan Jr. 2011/06/15 09:31:33 nit: Instead of having a nested "if", how about ad
haraken1 2011/06/15 10:39:45 Done.
60 return Open(); 60 return false;
61 return false; 61 }
62 return Open();
62 } 63 }
63 64
64 bool BaseFile::AppendDataToFile(const char* data, size_t data_len) { 65 bool BaseFile::AppendDataToFile(const char* data, size_t data_len) {
65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
66 DCHECK(!detached_); 67 DCHECK(!detached_);
67 68
68 if (!file_stream_.get()) 69 if (!file_stream_.get())
69 return false; 70 return false;
70 71
71 // TODO(phajdan.jr): get rid of this check. 72 // TODO(phajdan.jr): get rid of this check.
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 240
240 std::string BaseFile::DebugString() const { 241 std::string BaseFile::DebugString() const {
241 return base::StringPrintf("{ source_url_ = \"%s\"" 242 return base::StringPrintf("{ source_url_ = \"%s\""
242 " full_path_ = \"%" PRFilePath "\"" 243 " full_path_ = \"%" PRFilePath "\""
243 " bytes_so_far_ = %" PRId64 " detached_ = %c }", 244 " bytes_so_far_ = %" PRId64 " detached_ = %c }",
244 source_url_.spec().c_str(), 245 source_url_.spec().c_str(),
245 full_path_.value().c_str(), 246 full_path_.value().c_str(),
246 bytes_so_far_, 247 bytes_so_far_,
247 detached_ ? 'T' : 'F'); 248 detached_ ? 'T' : 'F');
248 } 249 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698