Home | History | Annotate | Download | only in 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_DOWNLOAD_DOWNLOAD_HISTORY_H_
      6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_HISTORY_H_
      7 #pragma once
      8 
      9 #include "base/basictypes.h"
     10 #include "chrome/browser/history/history.h"
     11 #include "content/browser/cancelable_request.h"
     12 
     13 class DownloadItem;
     14 class Profile;
     15 
     16 namespace base {
     17 class Time;
     18 }
     19 
     20 // Interacts with the HistoryService on behalf of the download subsystem.
     21 class DownloadHistory {
     22  public:
     23   // A fake download table ID which represents a download that has started,
     24   // but is not yet in the table.
     25   static const int kUninitializedHandle;
     26 
     27   explicit DownloadHistory(Profile* profile);
     28   ~DownloadHistory();
     29 
     30   // Retrieves DownloadCreateInfos saved in the history.
     31   void Load(HistoryService::DownloadQueryCallback* callback);
     32 
     33   // Adds a new entry for a download to the history database.
     34   void AddEntry(const DownloadCreateInfo& info,
     35                 DownloadItem* download_item,
     36                 HistoryService::DownloadCreateCallback* callback);
     37 
     38   // Updates the history entry for |download_item|.
     39   void UpdateEntry(DownloadItem* download_item);
     40 
     41   // Updates the download path for |download_item| to |new_path|.
     42   void UpdateDownloadPath(DownloadItem* download_item,
     43                           const FilePath& new_path);
     44 
     45   // Removes |download_item| from the history database.
     46   void RemoveEntry(DownloadItem* download_item);
     47 
     48   // Removes download-related history entries in the given time range.
     49   void RemoveEntriesBetween(const base::Time remove_begin,
     50                             const base::Time remove_end);
     51 
     52   // Returns a new unique database handle which will not collide with real ones.
     53   int64 GetNextFakeDbHandle();
     54 
     55  private:
     56   Profile* profile_;
     57 
     58   // In case we don't have a valid db_handle, we use |fake_db_handle_| instead.
     59   // This is useful for incognito mode or when the history database is offline.
     60   // Downloads are expected to have unique handles, so we decrement the next
     61   // fake handle value on every use.
     62   int64 next_fake_db_handle_;
     63 
     64   CancelableRequestConsumer history_consumer_;
     65 
     66   DISALLOW_COPY_AND_ASSIGN(DownloadHistory);
     67 };
     68 
     69 #endif  // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_HISTORY_H_
     70