Index: chrome/browser/history/visit_database.cc |
diff --git a/chrome/browser/history/visit_database.cc b/chrome/browser/history/visit_database.cc |
index 2280a1b65df4ae965995d9be1ee86e54764cc685..cfa56f146a81dd0bc396806a64249962e9389408 100644 |
--- a/chrome/browser/history/visit_database.cc |
+++ b/chrome/browser/history/visit_database.cc |
@@ -23,7 +23,8 @@ |
// Rows, in order, of the visit table. |
#define HISTORY_VISIT_ROW_FIELDS \ |
- " id,url,visit_time,from_visit,transition,segment_id,is_indexed " |
+ " id,url,visit_time,from_visit,transition,segment_id,is_indexed," \ |
GeorgeY
2012/03/27 21:15:57
nit: I think we should have 4 spaces indent here a
Wei Li
2012/03/27 23:01:50
Done.
|
+ "visit_duration " |
namespace history { |
@@ -344,17 +345,28 @@ bool VisitDatabase::InitVisitTable() { |
"transition INTEGER DEFAULT 0 NOT NULL," |
"segment_id INTEGER," |
// True when we have indexed data for this visit. |
- "is_indexed BOOLEAN)")) |
- return false; |
- } else if (!GetDB().DoesColumnExist("visits", "is_indexed")) { |
- // Old versions don't have the is_indexed column, we can just add that and |
- // not worry about different database revisions, since old ones will |
- // continue to work. |
- // |
- // TODO(brettw) this should be removed once we think everybody has been |
- // updated (added early Mar 2008). |
- if (!GetDB().Execute("ALTER TABLE visits ADD COLUMN is_indexed BOOLEAN")) |
+ "is_indexed BOOLEAN," |
+ "visit_duration INTEGER DEFAULT 0 NOT NULL)")) |
return false; |
+ } else { |
+ if (!GetDB().DoesColumnExist("visits", "is_indexed")) { |
+ // Old versions don't have the is_indexed column, we can just add that and |
+ // not worry about different database revisions, since old ones will |
+ // continue to work. |
+ // |
+ // TODO(brettw) this should be removed once we think everybody has been |
+ // updated (added early Mar 2008). |
+ if (!GetDB().Execute("ALTER TABLE visits ADD COLUMN is_indexed BOOLEAN")) |
+ return false; |
+ } |
+ if (!GetDB().DoesColumnExist("visits", "visit_duration")) { |
GeorgeY
2012/03/27 21:15:57
Why do we need to do here as well in addition to M
Wei Li
2012/03/27 23:01:50
I used this to guard some manual errors such as ve
|
+ // Old versions don't have the visit_duration column, we can just add that |
+ // without worrying about different database revisions since old ones will |
+ // continue to work. |
+ if (!GetDB().Execute("ALTER TABLE visits " |
+ "ADD COLUMN visit_duration INTEGER DEFAULT 0 NOT NULL")) |
+ return false; |
+ } |
} |
// Visit source table contains the source information for all the visits. To |
@@ -407,6 +419,8 @@ void VisitDatabase::FillVisitRow(sql::Statement& statement, VisitRow* visit) { |
visit->transition = content::PageTransitionFromInt(statement.ColumnInt(4)); |
visit->segment_id = statement.ColumnInt64(5); |
visit->is_indexed = !!statement.ColumnInt(6); |
+ visit->visit_duration = |
+ base::TimeDelta::FromInternalValue(statement.ColumnInt64(7)); |
} |
// static |
@@ -428,14 +442,15 @@ VisitID VisitDatabase::AddVisit(VisitRow* visit, VisitSource source) { |
visit_analysis_->AddVisit(visit); |
sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, |
"INSERT INTO visits " |
- "(url, visit_time, from_visit, transition, segment_id, is_indexed) " |
- "VALUES (?,?,?,?,?,?)")); |
+ "(url, visit_time, from_visit, transition, segment_id, is_indexed, " |
+ "visit_duration) VALUES (?,?,?,?,?,?,?)")); |
statement.BindInt64(0, visit->url_id); |
statement.BindInt64(1, visit->visit_time.ToInternalValue()); |
statement.BindInt64(2, visit->referring_visit); |
statement.BindInt64(3, visit->transition); |
statement.BindInt64(4, visit->segment_id); |
statement.BindInt64(5, visit->is_indexed); |
+ statement.BindInt64(6, visit->visit_duration.ToInternalValue()); |
if (!statement.Run()) { |
VLOG(0) << "Failed to execute visit insert statement: " |
@@ -454,7 +469,7 @@ VisitID VisitDatabase::AddVisit(VisitRow* visit, VisitSource source) { |
if (!statement1.Run()) { |
VLOG(0) << "Failed to execute visit_source insert statement: " |
- << "url_id = " << visit->visit_id; |
+ << "id = " << visit->visit_id; |
return 0; |
} |
} |
@@ -514,15 +529,16 @@ bool VisitDatabase::UpdateVisitRow(const VisitRow& visit) { |
sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, |
"UPDATE visits SET " |
- "url=?,visit_time=?,from_visit=?,transition=?,segment_id=?,is_indexed=? " |
- "WHERE id=?")); |
+ "url=?,visit_time=?,from_visit=?,transition=?,segment_id=?,is_indexed=?," |
+ "visit_duration=? WHERE id=?")); |
statement.BindInt64(0, visit.url_id); |
statement.BindInt64(1, visit.visit_time.ToInternalValue()); |
statement.BindInt64(2, visit.referring_visit); |
statement.BindInt64(3, visit.transition); |
statement.BindInt64(4, visit.segment_id); |
statement.BindInt64(5, visit.is_indexed); |
- statement.BindInt64(6, visit.visit_id); |
+ statement.BindInt64(6, visit.visit_duration.ToInternalValue()); |
+ statement.BindInt64(7, visit.visit_id); |
return statement.Run(); |
} |
@@ -842,4 +858,20 @@ void VisitDatabase::GetVisitsSource(const VisitVector& visits, |
} |
} |
+bool VisitDatabase::MigrateVisitsWithoutDuration() { |
+ if (!GetDB().DoesTableExist("visits")) { |
+ NOTREACHED() << " Visits table should exist before migration"; |
+ return false; |
+ } |
+ |
+ if (!GetDB().DoesColumnExist("visits", "visit_duration")) { |
+ // Old versions don't have the visit_duration column, we modify the table |
+ // to add that field. |
+ if (!GetDB().Execute( |
+ "ALTER TABLE visits ADD COLUMN visit_duration DEFAULT 0 NOT NULL")) |
+ return false; |
+ } |
+ return true; |
+} |
+ |
} // namespace history |