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

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

Issue 8404049: Added member data to classes to support download resumption. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged with trunk. Created 9 years, 1 month 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 "content/browser/download/base_file.h" 5 #include "content/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 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 376
377 void BaseFile::Finish() { 377 void BaseFile::Finish() {
378 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 378 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
379 379
380 if (calculate_hash_) 380 if (calculate_hash_)
381 secure_hash_->Finish(sha256_hash_, kSha256HashLen); 381 secure_hash_->Finish(sha256_hash_, kSha256HashLen);
382 382
383 Close(); 383 Close();
384 } 384 }
385 385
386 bool BaseFile::SetSha256Hash(const std::string& hash) {
387 DCHECK(!detached_);
388 DCHECK(hash.size() == kSha256HashLen);
389 if (!calculate_hash_)
390 return false;
391 memset(sha256_hash_, 0, kSha256HashLen);
392 memcpy(sha256_hash_, hash.c_str(), kSha256HashLen);
393 return true;
394 }
395
386 bool BaseFile::GetSha256Hash(std::string* hash) { 396 bool BaseFile::GetSha256Hash(std::string* hash) {
387 DCHECK(!detached_); 397 DCHECK(!detached_);
388 hash->assign(reinterpret_cast<const char*>(sha256_hash_), 398 hash->assign(reinterpret_cast<const char*>(sha256_hash_),
389 sizeof(sha256_hash_)); 399 sizeof(sha256_hash_));
390 return (calculate_hash_ && !in_progress()); 400 return (calculate_hash_);
391 } 401 }
392 402
393 bool BaseFile::IsEmptySha256Hash(const std::string& hash) { 403 bool BaseFile::IsEmptySha256Hash(const std::string& hash) {
394 return (hash.size() == kSha256HashLen && 404 return (hash.size() == kSha256HashLen &&
395 0 == memcmp(hash.data(), kEmptySha256Hash, sizeof(kSha256HashLen))); 405 0 == memcmp(hash.data(), kEmptySha256Hash, sizeof(kSha256HashLen)));
396 } 406 }
397 407
398 void BaseFile::AnnotateWithSourceInformation() { 408 void BaseFile::AnnotateWithSourceInformation() {
399 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 409 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
400 DCHECK(!detached_); 410 DCHECK(!detached_);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 std::string BaseFile::DebugString() const { 474 std::string BaseFile::DebugString() const {
465 return base::StringPrintf("{ source_url_ = \"%s\"" 475 return base::StringPrintf("{ source_url_ = \"%s\""
466 " full_path_ = \"%" PRFilePath "\"" 476 " full_path_ = \"%" PRFilePath "\""
467 " bytes_so_far_ = %" PRId64 477 " bytes_so_far_ = %" PRId64
468 " detached_ = %c }", 478 " detached_ = %c }",
469 source_url_.spec().c_str(), 479 source_url_.spec().c_str(),
470 full_path_.value().c_str(), 480 full_path_.value().c_str(),
471 bytes_so_far_, 481 bytes_so_far_,
472 detached_ ? 'T' : 'F'); 482 detached_ ? 'T' : 'F');
473 } 483 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698