Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: chrome/browser/history/download_database.h

Issue 10915180: Make DownloadHistory observe manager, items (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 10
11 #include "base/threading/platform_thread.h" 11 #include "base/threading/platform_thread.h"
12 #include "chrome/browser/history/history_types.h" 12 #include "chrome/browser/history/history_types.h"
13 #include "sql/meta_table.h" 13 #include "sql/meta_table.h"
14 14
15 class FilePath; 15 class FilePath;
16
17 namespace content {
18 struct DownloadPersistentStoreInfo; 16 struct DownloadPersistentStoreInfo;
19 }
20 17
21 namespace sql { 18 namespace sql {
22 class Connection; 19 class Connection;
23 } 20 }
24 21
25 namespace history { 22 namespace history {
26 23
27 // Maintains a table of downloads. 24 // Maintains a table of downloads.
28 class DownloadDatabase { 25 class DownloadDatabase {
29 public: 26 public:
27 // The value of |db_handle| indicating that the associated DownloadItem is not
28 // yet persisted.
29 static const int64 kUninitializedHandle;
30
30 // Must call InitDownloadTable before using any other functions. 31 // Must call InitDownloadTable before using any other functions.
31 DownloadDatabase(); 32 DownloadDatabase();
32 virtual ~DownloadDatabase(); 33 virtual ~DownloadDatabase();
33 34
34 int next_download_id() const { return next_id_; } 35 int next_download_id() const { return next_id_; }
35 36
36 // Get all the downloads from the database. 37 // Get all the downloads from the database.
37 void QueryDownloads( 38 void QueryDownloads(
38 std::vector<content::DownloadPersistentStoreInfo>* results); 39 std::vector<DownloadPersistentStoreInfo>* results);
39 40
40 // Update the state of one download. Returns true if successful. 41 // Update the state of one download. Returns true if successful.
41 // Does not update |url|, |start_time|, |total_bytes|; uses |db_handle| only 42 // Does not update |url|, |start_time|; uses |db_handle| only
42 // to select the row in the database table to update. 43 // to select the row in the database table to update.
43 bool UpdateDownload(const content::DownloadPersistentStoreInfo& data); 44 bool UpdateDownload(const DownloadPersistentStoreInfo& data);
44
45 // Update the path of one download. Returns true if successful.
46 bool UpdateDownloadPath(const FilePath& path, DownloadID db_handle);
47 45
48 // Fixes state of the download entries. Sometimes entries with IN_PROGRESS 46 // Fixes state of the download entries. Sometimes entries with IN_PROGRESS
49 // state are not updated during browser shutdown (particularly when crashing). 47 // state are not updated during browser shutdown (particularly when crashing).
50 // On the next start such entries are considered canceled. This functions 48 // On the next start such entries are considered canceled. This functions
51 // fixes such entries. 49 // fixes such entries.
52 bool CleanUpInProgressEntries(); 50 bool CleanUpInProgressEntries();
53 51
54 // Create a new database entry for one download and return its primary db id. 52 // Create a new database entry for one download and return its primary db id.
55 int64 CreateDownload(const content::DownloadPersistentStoreInfo& info); 53 int64 CreateDownload(const DownloadPersistentStoreInfo& info);
56 54
57 // Remove a download from the database. 55 // Remove all |handles| from the database.
58 void RemoveDownload(DownloadID db_handle); 56 void RemoveDownloads(const std::set<int64>& handles);
59
60 // Remove all completed downloads that started after |remove_begin|
61 // (inclusive) and before |remove_end|. You may use null Time values
62 // to do an unbounded delete in either direction. This function ignores
63 // all downloads that are in progress or are waiting to be cancelled.
64 bool RemoveDownloadsBetween(base::Time remove_begin, base::Time remove_end);
65 57
66 protected: 58 protected:
67 // Returns the database for the functions in this interface. 59 // Returns the database for the functions in this interface.
68 virtual sql::Connection& GetDB() = 0; 60 virtual sql::Connection& GetDB() = 0;
69 61
70 // Returns the meta-table object for the functions in this interface. 62 // Returns the meta-table object for the functions in this interface.
71 virtual sql::MetaTable& GetMetaTable() = 0; 63 virtual sql::MetaTable& GetMetaTable() = 0;
72 64
73 // Returns true if able to successfully rewrite the invalid values for the 65 // Returns true if able to successfully rewrite the invalid values for the
74 // |state| field from 3 to 4. Returns false if there was an error fixing the 66 // |state| field from 3 to 4. Returns false if there was an error fixing the
75 // database. See http://crbug.com/140687 67 // database. See http://crbug.com/140687
76 bool MigrateDownloadsState(); 68 bool MigrateDownloadsState();
77 69
78 // Creates the downloads table if needed. 70 // Creates the downloads table if needed.
79 bool InitDownloadTable(); 71 bool InitDownloadTable();
80 72
81 // 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
82 // would re-initialize it. 74 // would re-initialize it.
83 bool DropDownloadTable(); 75 bool DropDownloadTable();
84 76
85 private: 77 private:
86 // TODO(rdsmith): Remove after http://crbug.com/96627 has been resolved. 78 bool EnsureColumnExists(const std::string& name, const std::string& type);
87 void CheckThread();
88 79
89 bool EnsureColumnExists(const std::string& name, const std::string& type); 80 int CountDownloads();
90 81
91 bool owning_thread_set_; 82 bool owning_thread_set_;
92 base::PlatformThreadId owning_thread_; 83 base::PlatformThreadId owning_thread_;
93 84
94 int next_id_; 85 int next_id_;
95 int next_db_handle_; 86 int next_db_handle_;
96 87
97 DISALLOW_COPY_AND_ASSIGN(DownloadDatabase); 88 DISALLOW_COPY_AND_ASSIGN(DownloadDatabase);
98 }; 89 };
99 90
100 } // namespace history 91 } // namespace history
101 92
102 #endif // CHROME_BROWSER_HISTORY_DOWNLOAD_DATABASE_H_ 93 #endif // CHROME_BROWSER_HISTORY_DOWNLOAD_DATABASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698