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

Side by Side Diff: chrome/browser/history/in_memory_database.cc

Issue 9071014: Database usage adjustment for .../history (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 11 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "chrome/browser/history/in_memory_database.h" 5 #include "chrome/browser/history/in_memory_database.h"
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/time.h" 10 #include "base/time.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 return true; 62 return true;
63 } 63 }
64 64
65 bool InMemoryDatabase::InitFromDisk(const FilePath& history_name) { 65 bool InMemoryDatabase::InitFromDisk(const FilePath& history_name) {
66 if (!InitDB()) 66 if (!InitDB())
67 return false; 67 return false;
68 68
69 // Attach to the history database on disk. (We can't ATTACH in the middle of 69 // Attach to the history database on disk. (We can't ATTACH in the middle of
70 // a transaction.) 70 // a transaction.)
71 sql::Statement attach(GetDB().GetUniqueStatement("ATTACH ? AS history")); 71 sql::Statement attach(GetDB().GetUniqueStatement("ATTACH ? AS history"));
72 if (!attach) {
73 NOTREACHED() << "Unable to attach to history database.";
74 return false;
75 }
76 #if defined(OS_POSIX) 72 #if defined(OS_POSIX)
77 attach.BindString(0, history_name.value()); 73 attach.BindString(0, history_name.value());
78 #else 74 #else
79 attach.BindString(0, WideToUTF8(history_name.value())); 75 attach.BindString(0, WideToUTF8(history_name.value()));
80 #endif 76 #endif
81 if (!attach.Run()) { 77 if (!attach.Run()) {
82 NOTREACHED() << GetDB().GetErrorMessage(); 78 NOTREACHED() << GetDB().GetErrorMessage();
Scott Hess - ex-Googler 2012/01/03 23:41:57 If there was an error, shouldn't it already have b
Greg Billock 2012/01/04 19:20:20 Yes. Fixed. This may have merged in on me, or I ju
83 return false; 79 return false;
84 } 80 }
85 81
86 // Copy URL data to memory. 82 // Copy URL data to memory.
87 base::TimeTicks begin_load = base::TimeTicks::Now(); 83 base::TimeTicks begin_load = base::TimeTicks::Now();
88 if (!db_.Execute( 84 if (!db_.Execute(
89 "INSERT INTO urls SELECT * FROM history.urls WHERE typed_count > 0")) { 85 "INSERT INTO urls SELECT * FROM history.urls WHERE typed_count > 0")) {
90 // Unable to get data from the history database. This is OK, the file may 86 // Unable to get data from the history database. This is OK, the file may
91 // just not exist yet. 87 // just not exist yet.
92 } 88 }
93 base::TimeTicks end_load = base::TimeTicks::Now(); 89 base::TimeTicks end_load = base::TimeTicks::Now();
94 UMA_HISTOGRAM_MEDIUM_TIMES("History.InMemoryDBPopulate", 90 UMA_HISTOGRAM_MEDIUM_TIMES("History.InMemoryDBPopulate",
95 end_load - begin_load); 91 end_load - begin_load);
96 UMA_HISTOGRAM_COUNTS("History.InMemoryDBItemCount", db_.GetLastChangeCount()); 92 UMA_HISTOGRAM_COUNTS("History.InMemoryDBItemCount", db_.GetLastChangeCount());
97 93
98 { 94 {
99 // This calculation should be fast (since it's on an in-memory DB with 95 // This calculation should be fast (since it's on an in-memory DB with
100 // an average of only 35 rows). 96 // an average of only 35 rows).
101 sql::Statement visit_count(db_.GetUniqueStatement( 97 sql::Statement visit_count(db_.GetUniqueStatement(
102 "SELECT sum(visit_count) FROM urls")); 98 "SELECT sum(visit_count) FROM urls"));
103 if (visit_count && visit_count.Step()) { 99 if (visit_count.Step()) {
104 UMA_HISTOGRAM_COUNTS("History.InMemoryTypedUrlVisitCount", 100 UMA_HISTOGRAM_COUNTS("History.InMemoryTypedUrlVisitCount",
105 visit_count.ColumnInt(0)); 101 visit_count.ColumnInt(0));
106 } 102 }
107 } 103 }
108 104
109 // Insert keyword search related URLs. 105 // Insert keyword search related URLs.
110 begin_load = base::TimeTicks::Now(); 106 begin_load = base::TimeTicks::Now();
111 if (!db_.Execute( 107 if (!db_.Execute(
112 "INSERT INTO urls SELECT u.id, u.url, u.title, u.visit_count, " 108 "INSERT INTO urls SELECT u.id, u.url, u.title, u.visit_count, "
113 "u.typed_count, u.last_visit_time, u.hidden, u.favicon_id " 109 "u.typed_count, u.last_visit_time, u.hidden, u.favicon_id "
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 CreateKeywordSearchTermsIndices(); 144 CreateKeywordSearchTermsIndices();
149 145
150 return true; 146 return true;
151 } 147 }
152 148
153 sql::Connection& InMemoryDatabase::GetDB() { 149 sql::Connection& InMemoryDatabase::GetDB() {
154 return db_; 150 return db_;
155 } 151 }
156 152
157 } // namespace history 153 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698