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 DownloadSliceInfo; |
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 |
35 uint32_t GetNextDownloadId(); | 37 uint32_t GetNextDownloadId(); |
36 | 38 |
37 // Get all the downloads from the database. | 39 // Get all the downloads from the database. |
38 void QueryDownloads(std::vector<DownloadRow>* results); | 40 void QueryDownloads(std::vector<DownloadRow>* results); |
39 | 41 |
40 // Update the state of one download. Returns true if successful. | 42 // Update the state of one download. Returns true if successful. |
41 // Does not update |url|, |start_time|; uses |id| only | 43 // Does not update |url|, |start_time|; uses |id| only |
42 // to select the row in the database table to update. | 44 // to select the row in the database table to update. |
43 bool UpdateDownload(const DownloadRow& data); | 45 bool UpdateDownload(const DownloadRow& data); |
44 | 46 |
45 // Create a new database entry for one download and return true if the | 47 // Create a new database entry for one download and return true if the |
46 // creation succeeded, false otherwise. | 48 // creation succeeded, false otherwise. |
47 bool CreateDownload(const DownloadRow& info); | 49 bool CreateDownload(const DownloadRow& info); |
48 | 50 |
49 // Remove |id| from the database. | 51 // Remove |id| from the database. |
50 void RemoveDownload(uint32_t id); | 52 void RemoveDownload(DownloadId id); |
51 | 53 |
52 size_t CountDownloads(); | 54 size_t CountDownloads(); |
53 | 55 |
54 protected: | 56 protected: |
55 // Returns the database for the functions in this interface. | 57 // Returns the database for the functions in this interface. |
56 virtual sql::Connection& GetDB() = 0; | 58 virtual sql::Connection& GetDB() = 0; |
57 | 59 |
58 // Returns true if able to successfully add mime types to the downloads table. | 60 // Returns true if able to successfully add mime types to the downloads table. |
59 bool MigrateMimeType(); | 61 bool MigrateMimeType(); |
60 | 62 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 | 106 |
105 // Fixes state of the download entries. Sometimes entries with IN_PROGRESS | 107 // Fixes state of the download entries. Sometimes entries with IN_PROGRESS |
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(DownloadId id); |
| 117 |
| 118 // Creates a new download slice if it doesn't exist, or updates an existing |
| 119 // one. Returns true on success, or false otherwise. |
| 120 bool CreateOrUpdateDownloadSlice(const DownloadSliceInfo& info); |
| 121 |
| 122 // Delete all the download slices associated with one DownloadRow. |
| 123 void RemoveDownloadSlices(DownloadId id); |
| 124 |
| 125 // Helper method to query the download slices for all the records in |
| 126 // |download_row_map|. |
| 127 using DownloadRowMap = std::map<DownloadId, DownloadRow*>; |
| 128 void QueryDownloadSlices(DownloadRowMap* download_row_map); |
115 | 129 |
116 bool owning_thread_set_; | 130 bool owning_thread_set_; |
117 base::PlatformThreadId owning_thread_; | 131 base::PlatformThreadId owning_thread_; |
118 | 132 |
119 // Initialized to false on construction, and checked in all functional | 133 // Initialized to false on construction, and checked in all functional |
120 // routines post-migration in the database for a possible call to | 134 // routines post-migration in the database for a possible call to |
121 // CleanUpInProgressEntries(). This allows us to avoid | 135 // CleanUpInProgressEntries(). This allows us to avoid |
122 // doing the cleanup until after any DB migration and unless we are | 136 // doing the cleanup until after any DB migration and unless we are |
123 // actually use the downloads database. | 137 // actually use the downloads database. |
124 bool in_progress_entry_cleanup_completed_; | 138 bool in_progress_entry_cleanup_completed_; |
125 | 139 |
126 // Those constants are defined in the embedder and injected into the | 140 // Those constants are defined in the embedder and injected into the |
127 // database in the constructor. They represent the interrupt reason | 141 // database in the constructor. They represent the interrupt reason |
128 // to use for respectively an undefined value and in case of a crash. | 142 // to use for respectively an undefined value and in case of a crash. |
129 DownloadInterruptReason download_interrupt_reason_none_; | 143 DownloadInterruptReason download_interrupt_reason_none_; |
130 DownloadInterruptReason download_interrupt_reason_crash_; | 144 DownloadInterruptReason download_interrupt_reason_crash_; |
131 | 145 |
132 DISALLOW_COPY_AND_ASSIGN(DownloadDatabase); | 146 DISALLOW_COPY_AND_ASSIGN(DownloadDatabase); |
133 }; | 147 }; |
134 | 148 |
135 } // namespace history | 149 } // namespace history |
136 | 150 |
137 #endif // COMPONENTS_HISTORY_CORE_BROWSER_DOWNLOAD_DATABASE_H_ | 151 #endif // COMPONENTS_HISTORY_CORE_BROWSER_DOWNLOAD_DATABASE_H_ |
OLD | NEW |