| 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> |
| 9 #include <stdint.h> |
| 10 |
| 8 #include <string> | 11 #include <string> |
| 9 #include <vector> | 12 #include <vector> |
| 10 | 13 |
| 11 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
| 15 #include "base/macros.h" |
| 12 #include "base/threading/platform_thread.h" | 16 #include "base/threading/platform_thread.h" |
| 13 #include "components/history/core/browser/download_types.h" | 17 #include "components/history/core/browser/download_types.h" |
| 14 | 18 |
| 15 namespace sql { | 19 namespace sql { |
| 16 class Connection; | 20 class Connection; |
| 17 } | 21 } |
| 18 | 22 |
| 19 namespace history { | 23 namespace history { |
| 20 | 24 |
| 21 struct DownloadRow; | 25 struct DownloadRow; |
| 22 | 26 |
| 23 // Maintains a table of downloads. | 27 // Maintains a table of downloads. |
| 24 class DownloadDatabase { | 28 class DownloadDatabase { |
| 25 public: | 29 public: |
| 26 // Must call InitDownloadTable before using any other functions. | 30 // Must call InitDownloadTable before using any other functions. |
| 27 DownloadDatabase(DownloadInterruptReason download_interrupt_reason_none, | 31 DownloadDatabase(DownloadInterruptReason download_interrupt_reason_none, |
| 28 DownloadInterruptReason download_interrupt_reason_crash); | 32 DownloadInterruptReason download_interrupt_reason_crash); |
| 29 virtual ~DownloadDatabase(); | 33 virtual ~DownloadDatabase(); |
| 30 | 34 |
| 31 uint32 GetNextDownloadId(); | 35 uint32_t GetNextDownloadId(); |
| 32 | 36 |
| 33 // Get all the downloads from the database. | 37 // Get all the downloads from the database. |
| 34 void QueryDownloads(std::vector<DownloadRow>* results); | 38 void QueryDownloads(std::vector<DownloadRow>* results); |
| 35 | 39 |
| 36 // Update the state of one download. Returns true if successful. | 40 // Update the state of one download. Returns true if successful. |
| 37 // Does not update |url|, |start_time|; uses |id| only | 41 // Does not update |url|, |start_time|; uses |id| only |
| 38 // to select the row in the database table to update. | 42 // to select the row in the database table to update. |
| 39 bool UpdateDownload(const DownloadRow& data); | 43 bool UpdateDownload(const DownloadRow& data); |
| 40 | 44 |
| 41 // Create a new database entry for one download and return true if the | 45 // Create a new database entry for one download and return true if the |
| 42 // creation succeeded, false otherwise. | 46 // creation succeeded, false otherwise. |
| 43 bool CreateDownload(const DownloadRow& info); | 47 bool CreateDownload(const DownloadRow& info); |
| 44 | 48 |
| 45 // Remove |id| from the database. | 49 // Remove |id| from the database. |
| 46 void RemoveDownload(uint32 id); | 50 void RemoveDownload(uint32_t id); |
| 47 | 51 |
| 48 size_t CountDownloads(); | 52 size_t CountDownloads(); |
| 49 | 53 |
| 50 protected: | 54 protected: |
| 51 // Returns the database for the functions in this interface. | 55 // Returns the database for the functions in this interface. |
| 52 virtual sql::Connection& GetDB() = 0; | 56 virtual sql::Connection& GetDB() = 0; |
| 53 | 57 |
| 54 // Returns true if able to successfully add mime types to the downloads table. | 58 // Returns true if able to successfully add mime types to the downloads table. |
| 55 bool MigrateMimeType(); | 59 bool MigrateMimeType(); |
| 56 | 60 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 92 |
| 89 // Fixes state of the download entries. Sometimes entries with IN_PROGRESS | 93 // Fixes state of the download entries. Sometimes entries with IN_PROGRESS |
| 90 // state are not updated during browser shutdown (particularly when crashing). | 94 // state are not updated during browser shutdown (particularly when crashing). |
| 91 // On the next start such entries are considered interrupted with | 95 // On the next start such entries are considered interrupted with |
| 92 // interrupt reason |DOWNLOAD_INTERRUPT_REASON_CRASH|. This function | 96 // interrupt reason |DOWNLOAD_INTERRUPT_REASON_CRASH|. This function |
| 93 // fixes such entries. | 97 // fixes such entries. |
| 94 void EnsureInProgressEntriesCleanedUp(); | 98 void EnsureInProgressEntriesCleanedUp(); |
| 95 | 99 |
| 96 bool EnsureColumnExists(const std::string& name, const std::string& type); | 100 bool EnsureColumnExists(const std::string& name, const std::string& type); |
| 97 | 101 |
| 98 void RemoveDownloadURLs(uint32 id); | 102 void RemoveDownloadURLs(uint32_t id); |
| 99 | 103 |
| 100 bool owning_thread_set_; | 104 bool owning_thread_set_; |
| 101 base::PlatformThreadId owning_thread_; | 105 base::PlatformThreadId owning_thread_; |
| 102 | 106 |
| 103 // Initialized to false on construction, and checked in all functional | 107 // Initialized to false on construction, and checked in all functional |
| 104 // routines post-migration in the database for a possible call to | 108 // routines post-migration in the database for a possible call to |
| 105 // CleanUpInProgressEntries(). This allows us to avoid | 109 // CleanUpInProgressEntries(). This allows us to avoid |
| 106 // doing the cleanup until after any DB migration and unless we are | 110 // doing the cleanup until after any DB migration and unless we are |
| 107 // actually use the downloads database. | 111 // actually use the downloads database. |
| 108 bool in_progress_entry_cleanup_completed_; | 112 bool in_progress_entry_cleanup_completed_; |
| 109 | 113 |
| 110 // Those constants are defined in the embedder and injected into the | 114 // Those constants are defined in the embedder and injected into the |
| 111 // database in the constructor. They represent the interrupt reason | 115 // database in the constructor. They represent the interrupt reason |
| 112 // to use for respectively an undefined value and in case of a crash. | 116 // to use for respectively an undefined value and in case of a crash. |
| 113 DownloadInterruptReason download_interrupt_reason_none_; | 117 DownloadInterruptReason download_interrupt_reason_none_; |
| 114 DownloadInterruptReason download_interrupt_reason_crash_; | 118 DownloadInterruptReason download_interrupt_reason_crash_; |
| 115 | 119 |
| 116 DISALLOW_COPY_AND_ASSIGN(DownloadDatabase); | 120 DISALLOW_COPY_AND_ASSIGN(DownloadDatabase); |
| 117 }; | 121 }; |
| 118 | 122 |
| 119 } // namespace history | 123 } // namespace history |
| 120 | 124 |
| 121 #endif // COMPONENTS_HISTORY_CORE_BROWSER_DOWNLOAD_DATABASE_H_ | 125 #endif // COMPONENTS_HISTORY_CORE_BROWSER_DOWNLOAD_DATABASE_H_ |
| OLD | NEW |