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 COMPONENTS_HISTORY_CORE_BROWSER_DOWNLOAD_DATABASE_H_ |
6 #define CHROME_BROWSER_HISTORY_DOWNLOAD_DATABASE_H_ | 6 #define COMPONENTS_HISTORY_CORE_BROWSER_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/gtest_prod_util.h" |
12 #include "base/threading/platform_thread.h" | 12 #include "base/threading/platform_thread.h" |
13 #include "content/public/browser/download_item.h" | 13 #include "components/history/core/browser/download_types.h" |
14 #include "sql/meta_table.h" | 14 #include "sql/meta_table.h" |
15 | 15 |
16 namespace sql { | 16 namespace sql { |
17 class Connection; | 17 class Connection; |
18 } | 18 } |
19 | 19 |
20 namespace history { | 20 namespace history { |
21 | 21 |
22 struct DownloadRow; | 22 struct DownloadRow; |
23 | 23 |
24 // Maintains a table of downloads. | 24 // Maintains a table of downloads. |
25 class DownloadDatabase { | 25 class DownloadDatabase { |
26 public: | 26 public: |
27 // Must call InitDownloadTable before using any other functions. | 27 // Must call InitDownloadTable before using any other functions. |
28 DownloadDatabase(); | 28 DownloadDatabase(DownloadInterruptReason download_interrupt_no_reason, |
| 29 DownloadInterruptReason download_interrupt_crash); |
29 virtual ~DownloadDatabase(); | 30 virtual ~DownloadDatabase(); |
30 | 31 |
31 uint32 GetNextDownloadId(); | 32 uint32 GetNextDownloadId(); |
32 | 33 |
33 // Get all the downloads from the database. | 34 // Get all the downloads from the database. |
34 void QueryDownloads( | 35 void QueryDownloads( |
35 std::vector<DownloadRow>* results); | 36 std::vector<DownloadRow>* results); |
36 | 37 |
37 // Update the state of one download. Returns true if successful. | 38 // Update the state of one download. Returns true if successful. |
38 // Does not update |url|, |start_time|; uses |id| only | 39 // Does not update |url|, |start_time|; uses |id| only |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 bool InitDownloadTable(); | 81 bool InitDownloadTable(); |
81 | 82 |
82 // Used to quickly clear the downloads. First you would drop it, then you | 83 // Used to quickly clear the downloads. First you would drop it, then you |
83 // would re-initialize it. | 84 // would re-initialize it. |
84 bool DropDownloadTable(); | 85 bool DropDownloadTable(); |
85 | 86 |
86 private: | 87 private: |
87 FRIEND_TEST_ALL_PREFIXES( | 88 FRIEND_TEST_ALL_PREFIXES( |
88 HistoryBackendDBTest, ConfirmDownloadInProgressCleanup); | 89 HistoryBackendDBTest, ConfirmDownloadInProgressCleanup); |
89 | 90 |
90 // Values used in the database for DownloadItem::State. | |
91 static const int kStateInvalid; | |
92 static const int kStateInProgress; | |
93 static const int kStateComplete; | |
94 static const int kStateCancelled; | |
95 static const int kStateBug140687; | |
96 static const int kStateInterrupted; | |
97 | |
98 // Values used in the database for DownloadItem::DangerType | |
99 static const int kDangerTypeInvalid; | |
100 static const int kDangerTypeNotDangerous; | |
101 static const int kDangerTypeDangerousFile; | |
102 static const int kDangerTypeDangerousUrl; | |
103 static const int kDangerTypeDangerousContent; | |
104 static const int kDangerTypeMaybeDangerousContent; | |
105 static const int kDangerTypeUncommonContent; | |
106 static const int kDangerTypeUserValidated; | |
107 static const int kDangerTypeDangerousHost; | |
108 static const int kDangerTypePotentiallyUnwanted; | |
109 | |
110 // Fixes state of the download entries. Sometimes entries with IN_PROGRESS | 91 // Fixes state of the download entries. Sometimes entries with IN_PROGRESS |
111 // state are not updated during browser shutdown (particularly when crashing). | 92 // state are not updated during browser shutdown (particularly when crashing). |
112 // On the next start such entries are considered interrupted with | 93 // On the next start such entries are considered interrupted with |
113 // interrupt reason |DOWNLOAD_INTERRUPT_REASON_CRASH|. This function | 94 // interrupt reason |DOWNLOAD_INTERRUPT_REASON_CRASH|. This function |
114 // fixes such entries. | 95 // fixes such entries. |
115 void EnsureInProgressEntriesCleanedUp(); | 96 void EnsureInProgressEntriesCleanedUp(); |
116 | 97 |
117 bool EnsureColumnExists(const std::string& name, const std::string& type); | 98 bool EnsureColumnExists(const std::string& name, const std::string& type); |
118 | 99 |
119 void RemoveDownloadURLs(uint32 id); | 100 void RemoveDownloadURLs(uint32 id); |
120 | 101 |
121 // Utility functions for conversion between DownloadItem types | |
122 // and DownloadDatabase constants. | |
123 static int StateToInt(content::DownloadItem::DownloadState state); | |
124 static content::DownloadItem::DownloadState IntToState(int state); | |
125 static int DangerTypeToInt(content::DownloadDangerType danger_type); | |
126 static content::DownloadDangerType IntToDangerType(int danger_type); | |
127 | |
128 bool owning_thread_set_; | 102 bool owning_thread_set_; |
129 base::PlatformThreadId owning_thread_; | 103 base::PlatformThreadId owning_thread_; |
130 | 104 |
131 // Initialized to false on construction, and checked in all functional | 105 // Initialized to false on construction, and checked in all functional |
132 // routines post-migration in the database for a possible call to | 106 // routines post-migration in the database for a possible call to |
133 // CleanUpInProgressEntries(). This allows us to avoid | 107 // CleanUpInProgressEntries(). This allows us to avoid |
134 // doing the cleanup until after any DB migration and unless we are | 108 // doing the cleanup until after any DB migration and unless we are |
135 // actually use the downloads database. | 109 // actually use the downloads database. |
136 bool in_progress_entry_cleanup_completed_; | 110 bool in_progress_entry_cleanup_completed_; |
137 | 111 |
| 112 // Those constants are defined in the embedder and injected into the |
| 113 // database in the constructor. They represent the interrupt reason |
| 114 // to use for respectively an undefined value and in case of a crash. |
| 115 DownloadInterruptReason download_interrupt_no_reason_; |
| 116 DownloadInterruptReason download_interrupt_crash_; |
| 117 |
138 DISALLOW_COPY_AND_ASSIGN(DownloadDatabase); | 118 DISALLOW_COPY_AND_ASSIGN(DownloadDatabase); |
139 }; | 119 }; |
140 | 120 |
141 } // namespace history | 121 } // namespace history |
142 | 122 |
143 #endif // CHROME_BROWSER_HISTORY_DOWNLOAD_DATABASE_H_ | 123 #endif // COMPONENTS_HISTORY_CORE_BROWSER_DOWNLOAD_DATABASE_H_ |
OLD | NEW |