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/gtest_prod_util.h" |
11 #include "base/threading/platform_thread.h" | 12 #include "base/threading/platform_thread.h" |
| 13 #include "content/public/browser/download_item.h" |
12 #include "sql/meta_table.h" | 14 #include "sql/meta_table.h" |
13 | 15 |
14 namespace sql { | 16 namespace sql { |
15 class Connection; | 17 class Connection; |
16 } | 18 } |
17 | 19 |
18 namespace history { | 20 namespace history { |
19 | 21 |
20 struct DownloadRow; | 22 struct DownloadRow; |
21 | 23 |
(...skipping 12 matching lines...) Expand all Loading... |
34 | 36 |
35 // Get all the downloads from the database. | 37 // Get all the downloads from the database. |
36 void QueryDownloads( | 38 void QueryDownloads( |
37 std::vector<DownloadRow>* results); | 39 std::vector<DownloadRow>* results); |
38 | 40 |
39 // Update the state of one download. Returns true if successful. | 41 // Update the state of one download. Returns true if successful. |
40 // Does not update |url|, |start_time|; uses |db_handle| only | 42 // Does not update |url|, |start_time|; uses |db_handle| only |
41 // to select the row in the database table to update. | 43 // to select the row in the database table to update. |
42 bool UpdateDownload(const DownloadRow& data); | 44 bool UpdateDownload(const DownloadRow& data); |
43 | 45 |
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. | 46 // Create a new database entry for one download and return its primary db id. |
51 int64 CreateDownload(const DownloadRow& info); | 47 int64 CreateDownload(const DownloadRow& info); |
52 | 48 |
53 // Remove |handle| from the database. | 49 // Remove |handle| from the database. |
54 void RemoveDownload(int64 handle); | 50 void RemoveDownload(int64 handle); |
55 | 51 |
56 int CountDownloads(); | 52 int CountDownloads(); |
57 | 53 |
58 protected: | 54 protected: |
59 // Returns the database for the functions in this interface. | 55 // Returns the database for the functions in this interface. |
(...skipping 12 matching lines...) Expand all Loading... |
72 bool MigrateDownloadsReasonPathsAndDangerType(); | 68 bool MigrateDownloadsReasonPathsAndDangerType(); |
73 | 69 |
74 // Creates the downloads table if needed. | 70 // Creates the downloads table if needed. |
75 bool InitDownloadTable(); | 71 bool InitDownloadTable(); |
76 | 72 |
77 // Used to quickly clear the downloads. First you would drop it, then you | 73 // Used to quickly clear the downloads. First you would drop it, then you |
78 // would re-initialize it. | 74 // would re-initialize it. |
79 bool DropDownloadTable(); | 75 bool DropDownloadTable(); |
80 | 76 |
81 private: | 77 private: |
| 78 FRIEND_TEST_ALL_PREFIXES( |
| 79 HistoryBackendDBTest, ConfirmDownloadInProgressCleanup); |
| 80 |
| 81 // Values used in the database for DownloadItem::State. |
| 82 static const int kStateInvalid; |
| 83 static const int kStateInProgress; |
| 84 static const int kStateComplete; |
| 85 static const int kStateCancelled; |
| 86 static const int kStateBug140687; |
| 87 static const int kStateInterrupted; |
| 88 |
| 89 // Values used in the database for DownloadItem::DangerType |
| 90 static const int kDangerTypeInvalid; |
| 91 static const int kDangerTypeNotDangerous; |
| 92 static const int kDangerTypeDangerousFile; |
| 93 static const int kDangerTypeDangerousUrl; |
| 94 static const int kDangerTypeDangerousContent; |
| 95 static const int kDangerTypeMaybeDangerousContent; |
| 96 static const int kDangerTypeUncommonContent; |
| 97 static const int kDangerTypeUserValidated; |
| 98 static const int kDangerTypeDangerousHost; |
| 99 |
| 100 // Fixes state of the download entries. Sometimes entries with IN_PROGRESS |
| 101 // state are not updated during browser shutdown (particularly when crashing). |
| 102 // On the next start such entries are considered interrupted with |
| 103 // interrupt reason |DOWNLOAD_INTERRUPT_REASON_CRASH|. This function |
| 104 // fixes such entries. |
| 105 void EnsureInProgressEntriesCleanedUp(); |
| 106 |
82 bool EnsureColumnExists(const std::string& name, const std::string& type); | 107 bool EnsureColumnExists(const std::string& name, const std::string& type); |
83 | 108 |
84 void RemoveDownloadURLs(int64 handle); | 109 void RemoveDownloadURLs(int64 handle); |
85 | 110 |
| 111 // Utility functions for conversion between DownloadItem types |
| 112 // and DownloadDatabase constants. |
| 113 static int StateToInt(content::DownloadItem::DownloadState state); |
| 114 static content::DownloadItem::DownloadState IntToState(int state); |
| 115 static int DangerTypeToInt(content::DownloadDangerType danger_type); |
| 116 static content::DownloadDangerType IntToDangerType(int danger_type); |
| 117 |
86 bool owning_thread_set_; | 118 bool owning_thread_set_; |
87 base::PlatformThreadId owning_thread_; | 119 base::PlatformThreadId owning_thread_; |
88 | 120 |
89 int next_id_; | 121 int next_id_; |
90 int next_db_handle_; | 122 int next_db_handle_; |
91 | 123 |
| 124 // Initialized to false on construction, and checked in all functional |
| 125 // routines post-migration in the database for a possible call to |
| 126 // CleanUpInProgressEntries(). This allows us to avoid |
| 127 // doing the cleanup until after any DB migration and unless we are |
| 128 // actually use the downloads database. |
| 129 bool in_progress_entry_cleanup_completed_; |
| 130 |
92 DISALLOW_COPY_AND_ASSIGN(DownloadDatabase); | 131 DISALLOW_COPY_AND_ASSIGN(DownloadDatabase); |
93 }; | 132 }; |
94 | 133 |
95 } // namespace history | 134 } // namespace history |
96 | 135 |
97 #endif // CHROME_BROWSER_HISTORY_DOWNLOAD_DATABASE_H_ | 136 #endif // CHROME_BROWSER_HISTORY_DOWNLOAD_DATABASE_H_ |
OLD | NEW |