• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2009 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_VISITSEGMENT_DATABASE_H_
6 #define CHROME_BROWSER_HISTORY_VISITSEGMENT_DATABASE_H_
7 #pragma once
8 
9 #include "base/basictypes.h"
10 #include "chrome/browser/history/history_types.h"
11 
12 class PageUsageData;
13 
14 namespace sql {
15 class Connection;
16 }
17 
18 namespace history {
19 
20 // Tracks pages used for the most visited view.
21 class VisitSegmentDatabase {
22  public:
23   // Must call InitSegmentTables before using any other part of this class.
24   VisitSegmentDatabase();
25   virtual ~VisitSegmentDatabase();
26 
27   // Compute a segment name given a URL. The segment name is currently the
28   // source url spec less some information such as query strings.
29   static std::string ComputeSegmentName(const GURL& url);
30 
31   // Returns the ID of the segment with the corresponding name, or 0 if there
32   // is no segment with that name.
33   SegmentID GetSegmentNamed(const std::string& segment_name);
34 
35   // Update the segment identified by |out_segment_id| with the provided URL ID.
36   // The URL identifies the page that will now represent the segment. If url_id
37   // is non zero, it is assumed to be the row id of |url|.
38   bool UpdateSegmentRepresentationURL(SegmentID segment_id,
39                                       URLID url_id);
40 
41   // Return the ID of the URL currently used to represent this segment or 0 if
42   // an error occured.
43   URLID GetSegmentRepresentationURL(SegmentID segment_id);
44 
45   // Create a segment for the provided URL ID with the given name. Returns the
46   // ID of the newly created segment, or 0 on failure.
47   SegmentID CreateSegment(URLID url_id, const std::string& segment_name);
48 
49   // Increase the segment visit count by the provided amount. Return true on
50   // success.
51   bool IncreaseSegmentVisitCount(SegmentID segment_id, base::Time ts,
52                                  int amount);
53 
54   // Compute the segment usage since |from_time| using the provided aggregator.
55   // A PageUsageData is added in |result| for the highest-scored segments up to
56   // |max_result_count|.
57   void QuerySegmentUsage(base::Time from_time,
58                          int max_result_count,
59                          std::vector<PageUsageData*>* result);
60 
61   // Delete all the segment usage data which is older than the provided time
62   // stamp.
63   void DeleteSegmentData(base::Time older_than);
64 
65   // Change the presentation id for the segment identified by |segment_id|
66   void SetSegmentPresentationIndex(SegmentID segment_id, int index);
67 
68   // Delete the segment currently using the provided url for representation.
69   // This will also delete any associated segment usage data.
70   bool DeleteSegmentForURL(URLID url_id);
71 
72  protected:
73   // Returns the database for the functions in this interface.
74   virtual sql::Connection& GetDB() = 0;
75 
76   // Creates the tables used by this class if necessary. Returns true on
77   // success.
78   bool InitSegmentTables();
79 
80   // Deletes all the segment tables, returning true on success.
81   bool DropSegmentTables();
82 
83  private:
84   DISALLOW_COPY_AND_ASSIGN(VisitSegmentDatabase);
85 };
86 
87 }  // namespace history
88 
89 #endif  // CHROME_BROWSER_HISTORY_VISITSEGMENT_DATABASE_H_
90