| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "chrome/browser/history/history_types.h" | 9 #include "chrome/browser/history/history_types.h" |
| 10 | 10 |
| 11 struct DownloadCreateInfo; | 11 struct DownloadHistoryInfo; |
| 12 class FilePath; | 12 class FilePath; |
| 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 // Maintains a table of downloads. | 20 // Maintains a table of downloads. |
| 21 class DownloadDatabase { | 21 class DownloadDatabase { |
| 22 public: | 22 public: |
| 23 // Must call InitDownloadTable before using any other functions. | 23 // Must call InitDownloadTable before using any other functions. |
| 24 DownloadDatabase(); | 24 DownloadDatabase(); |
| 25 virtual ~DownloadDatabase(); | 25 virtual ~DownloadDatabase(); |
| 26 | 26 |
| 27 // Get all the downloads from the database. | 27 // Get all the downloads from the database. |
| 28 void QueryDownloads(std::vector<DownloadCreateInfo>* results); | 28 void QueryDownloads(std::vector<DownloadHistoryInfo>* results); |
| 29 | 29 |
| 30 // Update the state of one download. Returns true if successful. | 30 // Update the state of one download. Returns true if successful. |
| 31 bool UpdateDownload(int64 received_bytes, int32 state, DownloadID db_handle); | 31 bool UpdateDownload(int64 received_bytes, int32 state, DownloadID db_handle); |
| 32 | 32 |
| 33 // Update the path of one download. Returns true if successful. | 33 // Update the path of one download. Returns true if successful. |
| 34 bool UpdateDownloadPath(const FilePath& path, DownloadID db_handle); | 34 bool UpdateDownloadPath(const FilePath& path, DownloadID db_handle); |
| 35 | 35 |
| 36 // Fixes state of the download entries. Sometimes entries with IN_PROGRESS | 36 // Fixes state of the download entries. Sometimes entries with IN_PROGRESS |
| 37 // state are not updated during browser shutdown (particularly when crashing). | 37 // state are not updated during browser shutdown (particularly when crashing). |
| 38 // On the next start such entries are considered canceled. This functions | 38 // On the next start such entries are considered canceled. This functions |
| 39 // fixes such entries. | 39 // fixes such entries. |
| 40 bool CleanUpInProgressEntries(); | 40 bool CleanUpInProgressEntries(); |
| 41 | 41 |
| 42 // Create a new database entry for one download and return its primary db id. | 42 // Create a new database entry for one download and return its primary db id. |
| 43 int64 CreateDownload(const DownloadCreateInfo& info); | 43 int64 CreateDownload(const DownloadHistoryInfo& info); |
| 44 | 44 |
| 45 // Remove a download from the database. | 45 // Remove a download from the database. |
| 46 void RemoveDownload(DownloadID db_handle); | 46 void RemoveDownload(DownloadID db_handle); |
| 47 | 47 |
| 48 // Remove all completed downloads that started after |remove_begin| | 48 // Remove all completed downloads that started after |remove_begin| |
| 49 // (inclusive) and before |remove_end|. You may use null Time values | 49 // (inclusive) and before |remove_end|. You may use null Time values |
| 50 // to do an unbounded delete in either direction. This function ignores | 50 // to do an unbounded delete in either direction. This function ignores |
| 51 // all downloads that are in progress or are waiting to be cancelled. | 51 // all downloads that are in progress or are waiting to be cancelled. |
| 52 void RemoveDownloadsBetween(base::Time remove_begin, base::Time remove_end); | 52 void RemoveDownloadsBetween(base::Time remove_begin, base::Time remove_end); |
| 53 | 53 |
| 54 protected: | 54 protected: |
| 55 // Returns the database for the functions in this interface. | 55 // Returns the database for the functions in this interface. |
| 56 virtual sql::Connection& GetDB() = 0; | 56 virtual sql::Connection& GetDB() = 0; |
| 57 | 57 |
| 58 // Creates the downloads table if needed. | 58 // Creates the downloads table if needed. |
| 59 bool InitDownloadTable(); | 59 bool InitDownloadTable(); |
| 60 | 60 |
| 61 // Used to quickly clear the downloads. First you would drop it, then you | 61 // Used to quickly clear the downloads. First you would drop it, then you |
| 62 // would re-initialize it. | 62 // would re-initialize it. |
| 63 bool DropDownloadTable(); | 63 bool DropDownloadTable(); |
| 64 | 64 |
| 65 private: | 65 private: |
| 66 DISALLOW_COPY_AND_ASSIGN(DownloadDatabase); | 66 DISALLOW_COPY_AND_ASSIGN(DownloadDatabase); |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 } // namespace history | 69 } // namespace history |
| 70 | 70 |
| 71 #endif // CHROME_BROWSER_HISTORY_DOWNLOAD_DATABASE_H_ | 71 #endif // CHROME_BROWSER_HISTORY_DOWNLOAD_DATABASE_H_ |
| OLD | NEW |