Chromium Code Reviews| 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 #ifndef COMPONENTS_HISTORY_CORE_BROWSER_DOWNLOAD_DATABASE_H_ | 5 #ifndef COMPONENTS_HISTORY_CORE_BROWSER_DOWNLOAD_DATABASE_H_ |
| 6 #define COMPONENTS_HISTORY_CORE_BROWSER_DOWNLOAD_DATABASE_H_ | 6 #define COMPONENTS_HISTORY_CORE_BROWSER_DOWNLOAD_DATABASE_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <map> | |
| 11 #include <string> | 12 #include <string> |
| 12 #include <vector> | 13 #include <vector> |
| 13 | 14 |
| 14 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
| 15 #include "base/macros.h" | 16 #include "base/macros.h" |
| 16 #include "base/threading/platform_thread.h" | 17 #include "base/threading/platform_thread.h" |
| 17 #include "components/history/core/browser/download_types.h" | 18 #include "components/history/core/browser/download_types.h" |
| 18 | 19 |
| 19 namespace sql { | 20 namespace sql { |
| 20 class Connection; | 21 class Connection; |
| 21 } | 22 } |
| 22 | 23 |
| 23 namespace history { | 24 namespace history { |
| 24 | 25 |
| 26 struct DownloadJobInfo; | |
| 25 struct DownloadRow; | 27 struct DownloadRow; |
| 26 | 28 |
| 27 // Maintains a table of downloads. | 29 // Maintains a table of downloads. |
| 28 class DownloadDatabase { | 30 class DownloadDatabase { |
| 29 public: | 31 public: |
| 30 // Must call InitDownloadTable before using any other functions. | 32 // Must call InitDownloadTable before using any other functions. |
| 31 DownloadDatabase(DownloadInterruptReason download_interrupt_reason_none, | 33 DownloadDatabase(DownloadInterruptReason download_interrupt_reason_none, |
| 32 DownloadInterruptReason download_interrupt_reason_crash); | 34 DownloadInterruptReason download_interrupt_reason_crash); |
| 33 virtual ~DownloadDatabase(); | 35 virtual ~DownloadDatabase(); |
| 34 | 36 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 // state are not updated during browser shutdown (particularly when crashing). | 108 // state are not updated during browser shutdown (particularly when crashing). |
| 107 // On the next start such entries are considered interrupted with | 109 // On the next start such entries are considered interrupted with |
| 108 // interrupt reason |DOWNLOAD_INTERRUPT_REASON_CRASH|. This function | 110 // interrupt reason |DOWNLOAD_INTERRUPT_REASON_CRASH|. This function |
| 109 // fixes such entries. | 111 // fixes such entries. |
| 110 void EnsureInProgressEntriesCleanedUp(); | 112 void EnsureInProgressEntriesCleanedUp(); |
| 111 | 113 |
| 112 bool EnsureColumnExists(const std::string& name, const std::string& type); | 114 bool EnsureColumnExists(const std::string& name, const std::string& type); |
| 113 | 115 |
| 114 void RemoveDownloadURLs(uint32_t id); | 116 void RemoveDownloadURLs(uint32_t id); |
| 115 | 117 |
| 118 // Creates a new download job. Returns true on success, or false otherwise. | |
| 119 bool CreateDownloadJob(const DownloadJobInfo& info); | |
| 120 | |
| 121 // Updates the state of a download job. Returns true on success, or false | |
| 122 // if the job doesn't exists.. | |
| 123 bool UpdateDownloadJob(const DownloadJobInfo& info); | |
| 124 | |
| 125 // Delete all the download jobs associated with one DownloadRow. | |
| 126 void RemoveDownloadJobs(uint32_t id); | |
|
Scott Hess - ex-Googler
2017/02/06 21:22:16
Seems like this should be DownloadId.
qinmin
2017/02/06 23:39:22
Done.
| |
| 127 | |
| 128 // Helper method to query the download jobs for all the records in | |
| 129 // |download_row_map|. | |
| 130 void QueryDownloadJobs(std::map<uint32_t, DownloadRow*>* download_row_map); | |
|
Scott Hess - ex-Googler
2017/02/06 21:22:16
This too.
Also, you should be able to return a ma
qinmin
2017/02/06 23:39:22
Done changing it to DownloadId. For the return val
| |
| 131 | |
| 116 bool owning_thread_set_; | 132 bool owning_thread_set_; |
| 117 base::PlatformThreadId owning_thread_; | 133 base::PlatformThreadId owning_thread_; |
| 118 | 134 |
| 119 // Initialized to false on construction, and checked in all functional | 135 // Initialized to false on construction, and checked in all functional |
| 120 // routines post-migration in the database for a possible call to | 136 // routines post-migration in the database for a possible call to |
| 121 // CleanUpInProgressEntries(). This allows us to avoid | 137 // CleanUpInProgressEntries(). This allows us to avoid |
| 122 // doing the cleanup until after any DB migration and unless we are | 138 // doing the cleanup until after any DB migration and unless we are |
| 123 // actually use the downloads database. | 139 // actually use the downloads database. |
| 124 bool in_progress_entry_cleanup_completed_; | 140 bool in_progress_entry_cleanup_completed_; |
| 125 | 141 |
| 126 // Those constants are defined in the embedder and injected into the | 142 // Those constants are defined in the embedder and injected into the |
| 127 // database in the constructor. They represent the interrupt reason | 143 // database in the constructor. They represent the interrupt reason |
| 128 // to use for respectively an undefined value and in case of a crash. | 144 // to use for respectively an undefined value and in case of a crash. |
| 129 DownloadInterruptReason download_interrupt_reason_none_; | 145 DownloadInterruptReason download_interrupt_reason_none_; |
| 130 DownloadInterruptReason download_interrupt_reason_crash_; | 146 DownloadInterruptReason download_interrupt_reason_crash_; |
| 131 | 147 |
| 132 DISALLOW_COPY_AND_ASSIGN(DownloadDatabase); | 148 DISALLOW_COPY_AND_ASSIGN(DownloadDatabase); |
| 133 }; | 149 }; |
| 134 | 150 |
| 135 } // namespace history | 151 } // namespace history |
| 136 | 152 |
| 137 #endif // COMPONENTS_HISTORY_CORE_BROWSER_DOWNLOAD_DATABASE_H_ | 153 #endif // COMPONENTS_HISTORY_CORE_BROWSER_DOWNLOAD_DATABASE_H_ |
| OLD | NEW |