| 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 CHROME_BROWSER_HISTORY_DOWNLOAD_DATABASE_H_ | 5 #ifndef CHROME_BROWSER_HISTORY_DOWNLOAD_DATABASE_H_ |
| 6 #define CHROME_BROWSER_HISTORY_DOWNLOAD_DATABASE_H_ | 6 #define CHROME_BROWSER_HISTORY_DOWNLOAD_DATABASE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/threading/platform_thread.h" | 11 #include "base/threading/platform_thread.h" |
| 12 #include "sql/meta_table.h" | 12 #include "sql/meta_table.h" |
| 13 | 13 |
| 14 namespace sql { | 14 namespace sql { |
| 15 class Connection; | 15 class Connection; |
| 16 } | 16 } |
| 17 | 17 |
| 18 namespace history { | 18 namespace history { |
| 19 | 19 |
| 20 struct DownloadRow; | 20 struct DownloadRow; |
| 21 | 21 |
| 22 // Maintains a table of downloads. | 22 // Maintains a table of downloads. |
| 23 class DownloadDatabase { | 23 class DownloadDatabase { |
| 24 public: | 24 public: |
| 25 // Visible outside of download_database.cc only for testing. |
| 26 static const int kStateInvalid; |
| 27 static const int kStateInProgress; |
| 28 static const int kStateComplete; |
| 29 static const int kStateCancelled; |
| 30 static const int kStateBug140687; |
| 31 static const int kStateInterrupted; |
| 32 |
| 33 static const int kDangerTypeInvalid; |
| 34 static const int kDangerTypeNotDangerous; |
| 35 static const int kDangerTypeDangerousFile; |
| 36 static const int kDangerTypeDangerousUrl; |
| 37 static const int kDangerTypeDangerousContent; |
| 38 static const int kDangerTypeMaybeDangerousContent; |
| 39 static const int kDangerTypeUncommonContent; |
| 40 static const int kDangerTypeUserValidated; |
| 41 static const int kDangerTypeDangerousHost; |
| 42 |
| 25 // The value of |db_handle| indicating that the associated DownloadItem is not | 43 // The value of |db_handle| indicating that the associated DownloadItem is not |
| 26 // yet persisted. | 44 // yet persisted. |
| 27 static const int64 kUninitializedHandle; | 45 static const int64 kUninitializedHandle; |
| 28 | 46 |
| 29 // Must call InitDownloadTable before using any other functions. | 47 // Must call InitDownloadTable before using any other functions. |
| 30 DownloadDatabase(); | 48 DownloadDatabase(); |
| 31 virtual ~DownloadDatabase(); | 49 virtual ~DownloadDatabase(); |
| 32 | 50 |
| 33 int next_download_id() const { return next_id_; } | 51 int next_download_id() const { return next_id_; } |
| 34 | 52 |
| 35 // Get all the downloads from the database. | 53 // Get all the downloads from the database. |
| 36 void QueryDownloads( | 54 void QueryDownloads( |
| 37 std::vector<DownloadRow>* results); | 55 std::vector<DownloadRow>* results); |
| 38 | 56 |
| 39 // Update the state of one download. Returns true if successful. | 57 // Update the state of one download. Returns true if successful. |
| 40 // Does not update |url|, |start_time|; uses |db_handle| only | 58 // Does not update |url|, |start_time|; uses |db_handle| only |
| 41 // to select the row in the database table to update. | 59 // to select the row in the database table to update. |
| 42 bool UpdateDownload(const DownloadRow& data); | 60 bool UpdateDownload(const DownloadRow& data); |
| 43 | 61 |
| 44 // Fixes state of the download entries. Sometimes entries with IN_PROGRESS | |
| 45 // state are not updated during browser shutdown (particularly when crashing). | |
| 46 // On the next start such entries are considered canceled. This functions | |
| 47 // fixes such entries. | |
| 48 bool CleanUpInProgressEntries(); | |
| 49 | |
| 50 // Create a new database entry for one download and return its primary db id. | 62 // Create a new database entry for one download and return its primary db id. |
| 51 int64 CreateDownload(const DownloadRow& info); | 63 int64 CreateDownload(const DownloadRow& info); |
| 52 | 64 |
| 53 // Remove |handle| from the database. | 65 // Remove |handle| from the database. |
| 54 void RemoveDownload(int64 handle); | 66 void RemoveDownload(int64 handle); |
| 55 | 67 |
| 56 int CountDownloads(); | 68 int CountDownloads(); |
| 57 | 69 |
| 58 protected: | 70 protected: |
| 59 // Returns the database for the functions in this interface. | 71 // Returns the database for the functions in this interface. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 72 bool MigrateDownloadsReasonPathsAndDangerType(); | 84 bool MigrateDownloadsReasonPathsAndDangerType(); |
| 73 | 85 |
| 74 // Creates the downloads table if needed. | 86 // Creates the downloads table if needed. |
| 75 bool InitDownloadTable(); | 87 bool InitDownloadTable(); |
| 76 | 88 |
| 77 // Used to quickly clear the downloads. First you would drop it, then you | 89 // Used to quickly clear the downloads. First you would drop it, then you |
| 78 // would re-initialize it. | 90 // would re-initialize it. |
| 79 bool DropDownloadTable(); | 91 bool DropDownloadTable(); |
| 80 | 92 |
| 81 private: | 93 private: |
| 94 // Fixes state of the download entries. Sometimes entries with IN_PROGRESS |
| 95 // state are not updated during browser shutdown (particularly when crashing). |
| 96 // On the next start such entries are considered interrupted with |
| 97 // interrupt reason |DOWNLOAD_INTERRUPT_REASON_CRASH|. This functions |
| 98 // fixes such entries. |
| 99 void CleanUpInProgressEntries(); |
| 100 |
| 82 bool EnsureColumnExists(const std::string& name, const std::string& type); | 101 bool EnsureColumnExists(const std::string& name, const std::string& type); |
| 83 | 102 |
| 84 bool owning_thread_set_; | 103 bool owning_thread_set_; |
| 85 base::PlatformThreadId owning_thread_; | 104 base::PlatformThreadId owning_thread_; |
| 86 | 105 |
| 87 int next_id_; | 106 int next_id_; |
| 88 int next_db_handle_; | 107 int next_db_handle_; |
| 89 | 108 |
| 109 // Initialized to false on construction, and checked in all functional |
| 110 // routines post-migration in the database for a possible call to |
| 111 // CleanUpInProgressEntries(). This allows us to avoid |
| 112 // doing the cleanup until after any DB migration and unless we are |
| 113 // actually use the downloads database. |
| 114 bool in_progress_entry_cleanup_completed_; |
| 115 |
| 90 DISALLOW_COPY_AND_ASSIGN(DownloadDatabase); | 116 DISALLOW_COPY_AND_ASSIGN(DownloadDatabase); |
| 91 }; | 117 }; |
| 92 | 118 |
| 93 } // namespace history | 119 } // namespace history |
| 94 | 120 |
| 95 #endif // CHROME_BROWSER_HISTORY_DOWNLOAD_DATABASE_H_ | 121 #endif // CHROME_BROWSER_HISTORY_DOWNLOAD_DATABASE_H_ |
| OLD | NEW |