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

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: Review fixes 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();
83 return false; 78 return false;
84 }
85 79
86 // Copy URL data to memory. 80 // Copy URL data to memory.
87 base::TimeTicks begin_load = base::TimeTicks::Now(); 81 base::TimeTicks begin_load = base::TimeTicks::Now();
88 if (!db_.Execute( 82 if (!db_.Execute(
89 "INSERT INTO urls SELECT * FROM history.urls WHERE typed_count > 0")) { 83 "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 84 // Unable to get data from the history database. This is OK, the file may
91 // just not exist yet. 85 // just not exist yet.
92 } 86 }
93 base::TimeTicks end_load = base::TimeTicks::Now(); 87 base::TimeTicks end_load = base::TimeTicks::Now();
94 UMA_HISTOGRAM_MEDIUM_TIMES("History.InMemoryDBPopulate", 88 UMA_HISTOGRAM_MEDIUM_TIMES("History.InMemoryDBPopulate",
95 end_load - begin_load); 89 end_load - begin_load);
96 UMA_HISTOGRAM_COUNTS("History.InMemoryDBItemCount", db_.GetLastChangeCount()); 90 UMA_HISTOGRAM_COUNTS("History.InMemoryDBItemCount", db_.GetLastChangeCount());
97 91
98 { 92 {
99 // This calculation should be fast (since it's on an in-memory DB with 93 // This calculation should be fast (since it's on an in-memory DB with
100 // an average of only 35 rows). 94 // an average of only 35 rows).
101 sql::Statement visit_count(db_.GetUniqueStatement( 95 sql::Statement visit_count(db_.GetUniqueStatement(
102 "SELECT sum(visit_count) FROM urls")); 96 "SELECT sum(visit_count) FROM urls"));
103 if (visit_count && visit_count.Step()) { 97 if (visit_count.Step()) {
104 UMA_HISTOGRAM_COUNTS("History.InMemoryTypedUrlVisitCount", 98 UMA_HISTOGRAM_COUNTS("History.InMemoryTypedUrlVisitCount",
105 visit_count.ColumnInt(0)); 99 visit_count.ColumnInt(0));
106 } 100 }
107 } 101 }
108 102
109 // Insert keyword search related URLs. 103 // Insert keyword search related URLs.
110 begin_load = base::TimeTicks::Now(); 104 begin_load = base::TimeTicks::Now();
111 if (!db_.Execute( 105 if (!db_.Execute(
112 "INSERT INTO urls SELECT u.id, u.url, u.title, u.visit_count, " 106 "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 " 107 "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(); 142 CreateKeywordSearchTermsIndices();
149 143
150 return true; 144 return true;
151 } 145 }
152 146
153 sql::Connection& InMemoryDatabase::GetDB() { 147 sql::Connection& InMemoryDatabase::GetDB() {
154 return db_; 148 return db_;
155 } 149 }
156 150
157 } // namespace history 151 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698