OLD | NEW |
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" |
11 #include "base/pickle.h" | 11 #include "base/pickle.h" |
12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
13 #include "base/threading/thread_restrictions.h" | 13 #include "base/threading/thread_restrictions.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
15 #include "content/browser/download/download_net_log_parameters.h" | 15 #include "content/browser/download/download_net_log_parameters.h" |
16 #include "content/browser/download/download_stats.h" | 16 #include "content/browser/download/download_stats.h" |
17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
18 #include "content/public/browser/content_browser_client.h" | 18 #include "content/public/browser/content_browser_client.h" |
19 #include "crypto/secure_hash.h" | 19 #include "crypto/secure_hash.h" |
20 #include "net/base/file_stream.h" | 20 #include "net/base/file_stream.h" |
21 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
22 | 22 |
23 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
24 #include <windows.h> | 24 #include <windows.h> |
25 #include <shellapi.h> | 25 #include <shellapi.h> |
26 | 26 |
27 #include "content/browser/safe_util_win.h" | 27 #include "content/browser/safe_util_win.h" |
28 #elif defined(OS_MACOSX) | 28 #elif defined(OS_MACOSX) |
29 #include "content/browser/file_metadata_mac.h" | 29 #include "content/browser/file_metadata_mac.h" |
| 30 #elif defined(OS_LINUX) |
| 31 #include "content/browser/file_metadata_linux.h" |
30 #endif | 32 #endif |
31 | 33 |
32 using content::BrowserThread; | 34 using content::BrowserThread; |
33 | 35 |
34 namespace { | 36 namespace { |
35 | 37 |
36 #define LOG_ERROR(o, e) \ | 38 #define LOG_ERROR(o, e) \ |
37 LogError(__FILE__, __LINE__, __FUNCTION__, bound_net_log_, o, e) | 39 LogError(__FILE__, __LINE__, __FUNCTION__, bound_net_log_, o, e) |
38 | 40 |
39 // Logs the value and passes error on through, converting to a |net::Error|. | 41 // Logs the value and passes error on through, converting to a |net::Error|. |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 #if defined(OS_WIN) | 465 #if defined(OS_WIN) |
464 // Sets the Zone to tell Windows that this file comes from the internet. | 466 // Sets the Zone to tell Windows that this file comes from the internet. |
465 // We ignore the return value because a failure is not fatal. | 467 // We ignore the return value because a failure is not fatal. |
466 win_util::SetInternetZoneIdentifier(full_path_, | 468 win_util::SetInternetZoneIdentifier(full_path_, |
467 UTF8ToWide(source_url_.spec())); | 469 UTF8ToWide(source_url_.spec())); |
468 #elif defined(OS_MACOSX) | 470 #elif defined(OS_MACOSX) |
469 file_metadata::AddQuarantineMetadataToFile(full_path_, source_url_, | 471 file_metadata::AddQuarantineMetadataToFile(full_path_, source_url_, |
470 referrer_url_); | 472 referrer_url_); |
471 file_metadata::AddOriginMetadataToFile(full_path_, source_url_, | 473 file_metadata::AddOriginMetadataToFile(full_path_, source_url_, |
472 referrer_url_); | 474 referrer_url_); |
| 475 #elif defined(OS_LINUX) |
| 476 file_metadata::AddOriginMetadataToFile(full_path_, source_url_, |
| 477 referrer_url_); |
473 #endif | 478 #endif |
474 } | 479 } |
475 | 480 |
476 void BaseFile::CreateFileStream() { | 481 void BaseFile::CreateFileStream() { |
477 file_stream_.reset(new net::FileStream(bound_net_log_.net_log())); | 482 file_stream_.reset(new net::FileStream(bound_net_log_.net_log())); |
478 file_stream_->SetBoundNetLogSource(bound_net_log_); | 483 file_stream_->SetBoundNetLogSource(bound_net_log_); |
479 } | 484 } |
480 | 485 |
481 net::Error BaseFile::Open() { | 486 net::Error BaseFile::Open() { |
482 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 487 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 int64 BaseFile::CurrentSpeedAtTime(base::TimeTicks current_time) const { | 553 int64 BaseFile::CurrentSpeedAtTime(base::TimeTicks current_time) const { |
549 base::TimeDelta diff = current_time - start_tick_; | 554 base::TimeDelta diff = current_time - start_tick_; |
550 int64 diff_ms = diff.InMilliseconds(); | 555 int64 diff_ms = diff.InMilliseconds(); |
551 return diff_ms == 0 ? 0 : bytes_so_far() * 1000 / diff_ms; | 556 return diff_ms == 0 ? 0 : bytes_so_far() * 1000 / diff_ms; |
552 } | 557 } |
553 | 558 |
554 int64 BaseFile::CurrentSpeed() const { | 559 int64 BaseFile::CurrentSpeed() const { |
555 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 560 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
556 return CurrentSpeedAtTime(base::TimeTicks::Now()); | 561 return CurrentSpeedAtTime(base::TimeTicks::Now()); |
557 } | 562 } |
| 563 |
OLD | NEW |