| OLD | NEW |
| 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_VISITSEGMENT_DATABASE_H_ | 5 #ifndef CHROME_BROWSER_HISTORY_VISITSEGMENT_DATABASE_H_ |
| 6 #define CHROME_BROWSER_HISTORY_VISITSEGMENT_DATABASE_H_ | 6 #define CHROME_BROWSER_HISTORY_VISITSEGMENT_DATABASE_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "chrome/browser/history/history_types.h" | 9 #include "chrome/browser/history/history_types.h" |
| 10 | 10 |
| 11 class PageUsageData; | 11 class PageUsageData; |
| 12 | 12 |
| 13 namespace sql { | 13 namespace sql { |
| 14 class Connection; | 14 class Connection; |
| 15 class Statement; | |
| 16 } | 15 } |
| 17 | 16 |
| 18 namespace history { | 17 namespace history { |
| 19 | 18 |
| 20 // Tracks pages used for the most visited view. | 19 // Tracks pages used for the most visited view. |
| 21 class VisitSegmentDatabase { | 20 class VisitSegmentDatabase { |
| 22 public: | 21 public: |
| 23 // Must call InitSegmentTables before using any other part of this class. | 22 // Must call InitSegmentTables before using any other part of this class. |
| 24 VisitSegmentDatabase(); | 23 VisitSegmentDatabase(); |
| 25 virtual ~VisitSegmentDatabase(); | 24 virtual ~VisitSegmentDatabase(); |
| 26 | 25 |
| 27 // Compute a segment name given a URL. The segment name is currently the | 26 // Compute a segment name given a URL. The segment name is currently the |
| 28 // source url spec less some information such as query strings. | 27 // source url spec less some information such as query strings. |
| 29 static std::string ComputeSegmentName(const GURL& url); | 28 static std::string ComputeSegmentName(const GURL& url); |
| 30 | 29 |
| 31 // The segment tables use the time as a key for visit count and duration. This | |
| 32 // returns the appropriate time. | |
| 33 static base::Time SegmentTime(base::Time time); | |
| 34 | |
| 35 // Returns the ID of the segment with the corresponding name, or 0 if there | 30 // Returns the ID of the segment with the corresponding name, or 0 if there |
| 36 // is no segment with that name. | 31 // is no segment with that name. |
| 37 SegmentID GetSegmentNamed(const std::string& segment_name); | 32 SegmentID GetSegmentNamed(const std::string& segment_name); |
| 38 | 33 |
| 39 // Update the segment identified by |out_segment_id| with the provided URL ID. | 34 // Update the segment identified by |out_segment_id| with the provided URL ID. |
| 40 // The URL identifies the page that will now represent the segment. If url_id | 35 // The URL identifies the page that will now represent the segment. If url_id |
| 41 // is non zero, it is assumed to be the row id of |url|. | 36 // is non zero, it is assumed to be the row id of |url|. |
| 42 bool UpdateSegmentRepresentationURL(SegmentID segment_id, | 37 bool UpdateSegmentRepresentationURL(SegmentID segment_id, |
| 43 URLID url_id); | 38 URLID url_id); |
| 44 | 39 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 66 // stamp. | 61 // stamp. |
| 67 bool DeleteSegmentData(base::Time older_than); | 62 bool DeleteSegmentData(base::Time older_than); |
| 68 | 63 |
| 69 // Change the presentation id for the segment identified by |segment_id| | 64 // Change the presentation id for the segment identified by |segment_id| |
| 70 bool SetSegmentPresentationIndex(SegmentID segment_id, int index); | 65 bool SetSegmentPresentationIndex(SegmentID segment_id, int index); |
| 71 | 66 |
| 72 // Delete the segment currently using the provided url for representation. | 67 // Delete the segment currently using the provided url for representation. |
| 73 // This will also delete any associated segment usage data. | 68 // This will also delete any associated segment usage data. |
| 74 bool DeleteSegmentForURL(URLID url_id); | 69 bool DeleteSegmentForURL(URLID url_id); |
| 75 | 70 |
| 76 // Creates a new SegmentDurationID for the SegmentID and Time pair. The | |
| 77 // duration is set to |delta|. | |
| 78 SegmentDurationID CreateSegmentDuration(SegmentID segment_id, | |
| 79 base::Time time, | |
| 80 base::TimeDelta delta); | |
| 81 | |
| 82 // Sets the duration of the |duration_id| to |time_delta|. | |
| 83 bool SetSegmentDuration(SegmentDurationID duration_id, | |
| 84 base::TimeDelta time_delta); | |
| 85 | |
| 86 // Gets the SegmentDurationID of the |segment_id| and |time| pair. Returns | |
| 87 // true on success and sets |duration_id| and |time_delta| appropriately. | |
| 88 bool GetSegmentDuration(SegmentID segment_id, | |
| 89 base::Time time, | |
| 90 SegmentDurationID* duration_id, | |
| 91 base::TimeDelta* time_delta); | |
| 92 | |
| 93 // Queries segments by duration. | |
| 94 void QuerySegmentDuration(base::Time from_time, | |
| 95 int max_result_count, | |
| 96 std::vector<PageUsageData*>* result); | |
| 97 | |
| 98 protected: | 71 protected: |
| 99 // Returns the database for the functions in this interface. | 72 // Returns the database for the functions in this interface. |
| 100 virtual sql::Connection& GetDB() = 0; | 73 virtual sql::Connection& GetDB() = 0; |
| 101 | 74 |
| 102 // Creates the tables used by this class if necessary. Returns true on | 75 // Creates the tables used by this class if necessary. Returns true on |
| 103 // success. | 76 // success. |
| 104 bool InitSegmentTables(); | 77 bool InitSegmentTables(); |
| 105 | 78 |
| 106 // Deletes all the segment tables, returning true on success. | 79 // Deletes all the segment tables, returning true on success. |
| 107 bool DropSegmentTables(); | 80 bool DropSegmentTables(); |
| 108 | 81 |
| 109 // Removes the 'pres_index' column from the segments table and the | 82 // Removes the 'pres_index' column from the segments table and the |
| 110 // presentation table is removed entirely. | 83 // presentation table is removed entirely. |
| 111 bool MigratePresentationIndex(); | 84 bool MigratePresentationIndex(); |
| 112 | 85 |
| 113 private: | 86 private: |
| 114 enum QueryType { | |
| 115 QUERY_VISIT_COUNT, | |
| 116 QUERY_DURATION, | |
| 117 }; | |
| 118 | |
| 119 // Used by both QuerySegment fucntions. | |
| 120 void QuerySegmentsCommon(sql::Statement* statement, | |
| 121 base::Time from_time, | |
| 122 int max_result_count, | |
| 123 QueryType query_type, | |
| 124 std::vector<PageUsageData*>* result); | |
| 125 | |
| 126 // Was the |segment_duration| table created? | |
| 127 const bool has_duration_table_; | |
| 128 | |
| 129 DISALLOW_COPY_AND_ASSIGN(VisitSegmentDatabase); | 87 DISALLOW_COPY_AND_ASSIGN(VisitSegmentDatabase); |
| 130 }; | 88 }; |
| 131 | 89 |
| 132 } // namespace history | 90 } // namespace history |
| 133 | 91 |
| 134 #endif // CHROME_BROWSER_HISTORY_VISITSEGMENT_DATABASE_H_ | 92 #endif // CHROME_BROWSER_HISTORY_VISITSEGMENT_DATABASE_H_ |
| OLD | NEW |