OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/safe_browsing/incident_reporting/download_metadata_mana
ger.h" | 5 #include "chrome/browser/safe_browsing/incident_reporting/download_metadata_mana
ger.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <list> | 10 #include <list> |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 const base::FilePath::CharType kDownloadMetadataBasename[] = | 54 const base::FilePath::CharType kDownloadMetadataBasename[] = |
55 FILE_PATH_LITERAL("DownloadMetadata"); | 55 FILE_PATH_LITERAL("DownloadMetadata"); |
56 | 56 |
57 | 57 |
58 // DownloadItemData ------------------------------------------------------------ | 58 // DownloadItemData ------------------------------------------------------------ |
59 | 59 |
60 // A UserData object that holds the ClientDownloadRequest for a download while | 60 // A UserData object that holds the ClientDownloadRequest for a download while |
61 // it is in progress. | 61 // it is in progress. |
62 class DownloadItemData : public base::SupportsUserData::Data { | 62 class DownloadItemData : public base::SupportsUserData::Data { |
63 public: | 63 public: |
| 64 ~DownloadItemData() override {} |
| 65 |
64 // Sets the ClientDownloadRequest for a given DownloadItem. | 66 // Sets the ClientDownloadRequest for a given DownloadItem. |
65 static void SetRequestForDownload( | 67 static void SetRequestForDownload( |
66 content::DownloadItem* item, | 68 content::DownloadItem* item, |
67 std::unique_ptr<ClientDownloadRequest> request); | 69 std::unique_ptr<ClientDownloadRequest> request); |
68 | 70 |
69 // Returns the ClientDownloadRequest for a download or null if there is none. | 71 // Returns the ClientDownloadRequest for a download or null if there is none. |
70 static std::unique_ptr<ClientDownloadRequest> TakeRequestForDownload( | 72 static std::unique_ptr<ClientDownloadRequest> TakeRequestForDownload( |
71 content::DownloadItem* item); | 73 content::DownloadItem* item); |
72 | 74 |
73 private: | 75 private: |
74 // A unique id for associating metadata with a content::DownloadItem. | 76 // A unique id for associating metadata with a content::DownloadItem. |
75 static const void* const kKey_; | 77 static const void* const kKey_; |
76 | 78 |
77 explicit DownloadItemData(std::unique_ptr<ClientDownloadRequest> request) | 79 explicit DownloadItemData(std::unique_ptr<ClientDownloadRequest> request) |
78 : request_(std::move(request)) {} | 80 : request_(std::move(request)) {} |
79 ~DownloadItemData() override {} | |
80 | 81 |
81 std::unique_ptr<ClientDownloadRequest> request_; | 82 std::unique_ptr<ClientDownloadRequest> request_; |
82 | 83 |
83 DISALLOW_COPY_AND_ASSIGN(DownloadItemData); | 84 DISALLOW_COPY_AND_ASSIGN(DownloadItemData); |
84 }; | 85 }; |
85 | 86 |
86 // Make the key's value unique by setting it to its own location. | 87 // Make the key's value unique by setting it to its own location. |
87 // static | 88 // static |
88 const void* const DownloadItemData::kKey_ = &DownloadItemData::kKey_; | 89 const void* const DownloadItemData::kKey_ = &DownloadItemData::kKey_; |
89 | 90 |
90 // static | 91 // static |
91 void DownloadItemData::SetRequestForDownload( | 92 void DownloadItemData::SetRequestForDownload( |
92 content::DownloadItem* item, | 93 content::DownloadItem* item, |
93 std::unique_ptr<ClientDownloadRequest> request) { | 94 std::unique_ptr<ClientDownloadRequest> request) { |
94 item->SetUserData(&kKey_, new DownloadItemData(std::move(request))); | 95 item->SetUserData(&kKey_, |
| 96 base::WrapUnique(new DownloadItemData(std::move(request)))); |
95 } | 97 } |
96 | 98 |
97 // static | 99 // static |
98 std::unique_ptr<ClientDownloadRequest> DownloadItemData::TakeRequestForDownload( | 100 std::unique_ptr<ClientDownloadRequest> DownloadItemData::TakeRequestForDownload( |
99 content::DownloadItem* item) { | 101 content::DownloadItem* item) { |
100 DownloadItemData* data = | 102 DownloadItemData* data = |
101 static_cast<DownloadItemData*>(item->GetUserData(&kKey_)); | 103 static_cast<DownloadItemData*>(item->GetUserData(&kKey_)); |
102 if (!data) | 104 if (!data) |
103 return nullptr; | 105 return nullptr; |
104 std::unique_ptr<ClientDownloadRequest> request = std::move(data->request_); | 106 std::unique_ptr<ClientDownloadRequest> request = std::move(data->request_); |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 } | 658 } |
657 | 659 |
658 void DownloadMetadataManager::ManagerContext::UpdateLastOpenedTime( | 660 void DownloadMetadataManager::ManagerContext::UpdateLastOpenedTime( |
659 const base::Time& last_opened_time) { | 661 const base::Time& last_opened_time) { |
660 download_metadata_->mutable_download()->set_open_time_msec( | 662 download_metadata_->mutable_download()->set_open_time_msec( |
661 last_opened_time.ToJavaTime()); | 663 last_opened_time.ToJavaTime()); |
662 WriteMetadata(); | 664 WriteMetadata(); |
663 } | 665 } |
664 | 666 |
665 } // namespace safe_browsing | 667 } // namespace safe_browsing |
OLD | NEW |