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