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

Side by Side Diff: chrome/browser/predictors/predictor_database.cc

Issue 10900037: Adding more histograms to ResourcePrefetchPredictor. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 3 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
OLDNEW
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 #include "chrome/browser/predictors/predictor_database.h" 5 #include "chrome/browser/predictors/predictor_database.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 29 matching lines...) Expand all
40 40
41 // Opens the database file from the profile path. Separated from the 41 // Opens the database file from the profile path. Separated from the
42 // constructor to ease construction/destruction of this object on one thread 42 // constructor to ease construction/destruction of this object on one thread
43 // but database access on the DB thread. 43 // but database access on the DB thread.
44 void Initialize(); 44 void Initialize();
45 void LogDatabaseStats(); // DB Thread. 45 void LogDatabaseStats(); // DB Thread.
46 46
47 // Cancels pending DB transactions. Should only be called on the UI thread. 47 // Cancels pending DB transactions. Should only be called on the UI thread.
48 void SetCancelled(); 48 void SetCancelled();
49 49
50 Profile* const profile_;
50 FilePath db_path_; 51 FilePath db_path_;
51 sql::Connection db_; 52 sql::Connection db_;
52 53
53 // TODO(shishir): These tables may not need to be refcounted. Maybe move them 54 // TODO(shishir): These tables may not need to be refcounted. Maybe move them
54 // to using a WeakPtr instead. 55 // to using a WeakPtr instead.
55 scoped_refptr<AutocompleteActionPredictorTable> autocomplete_table_; 56 scoped_refptr<AutocompleteActionPredictorTable> autocomplete_table_;
56 scoped_refptr<ResourcePrefetchPredictorTables> resource_prefetch_tables_; 57 scoped_refptr<ResourcePrefetchPredictorTables> resource_prefetch_tables_;
57 58
58 DISALLOW_COPY_AND_ASSIGN(PredictorDatabaseInternal); 59 DISALLOW_COPY_AND_ASSIGN(PredictorDatabaseInternal);
59 }; 60 };
60 61
61 62
62 PredictorDatabaseInternal::PredictorDatabaseInternal(Profile* profile) 63 PredictorDatabaseInternal::PredictorDatabaseInternal(Profile* profile)
63 : db_path_(profile->GetPath().Append(kPredictorDatabaseName)), 64 : profile_(profile),
65 db_path_(profile->GetPath().Append(kPredictorDatabaseName)),
64 autocomplete_table_(new AutocompleteActionPredictorTable()), 66 autocomplete_table_(new AutocompleteActionPredictorTable()),
65 resource_prefetch_tables_(new ResourcePrefetchPredictorTables()) { 67 resource_prefetch_tables_(new ResourcePrefetchPredictorTables()) {
66 } 68 }
67 69
68 PredictorDatabaseInternal::~PredictorDatabaseInternal() { 70 PredictorDatabaseInternal::~PredictorDatabaseInternal() {
69 } 71 }
70 72
71 void PredictorDatabaseInternal::Initialize() { 73 void PredictorDatabaseInternal::Initialize() {
72 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::DB)); 74 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::DB));
73 db_.set_exclusive_locking(); 75 db_.set_exclusive_locking();
(...skipping 17 matching lines...) Expand all
91 93
92 void PredictorDatabaseInternal::LogDatabaseStats() { 94 void PredictorDatabaseInternal::LogDatabaseStats() {
93 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::DB)); 95 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::DB));
94 96
95 int64 db_size; 97 int64 db_size;
96 bool success = file_util::GetFileSize(db_path_, &db_size); 98 bool success = file_util::GetFileSize(db_path_, &db_size);
97 DCHECK(success) << "Failed to get file size for " << db_path_.value(); 99 DCHECK(success) << "Failed to get file size for " << db_path_.value();
98 UMA_HISTOGRAM_MEMORY_KB("PredictorDatabase.DatabaseSizeKB", 100 UMA_HISTOGRAM_MEMORY_KB("PredictorDatabase.DatabaseSizeKB",
99 static_cast<int>(db_size / 1024)); 101 static_cast<int>(db_size / 1024));
100 102
101 autocomplete_table_->LogDatabaseStats(); 103 autocomplete_table_->LogDatabaseStats(profile_);
102 resource_prefetch_tables_->LogDatabaseStats(); 104 resource_prefetch_tables_->LogDatabaseStats(profile_);
103 } 105 }
104 106
105 PredictorDatabase::PredictorDatabase(Profile* profile) 107 PredictorDatabase::PredictorDatabase(Profile* profile)
106 : db_(new PredictorDatabaseInternal(profile)) { 108 : db_(new PredictorDatabaseInternal(profile)) {
107 content::BrowserThread::PostTask(content::BrowserThread::DB, FROM_HERE, 109 content::BrowserThread::PostTask(content::BrowserThread::DB, FROM_HERE,
108 base::Bind(&PredictorDatabaseInternal::Initialize, db_)); 110 base::Bind(&PredictorDatabaseInternal::Initialize, db_));
109 } 111 }
110 112
111 PredictorDatabase::~PredictorDatabase() { 113 PredictorDatabase::~PredictorDatabase() {
112 } 114 }
(...skipping 10 matching lines...) Expand all
123 scoped_refptr<ResourcePrefetchPredictorTables> 125 scoped_refptr<ResourcePrefetchPredictorTables>
124 PredictorDatabase::resource_prefetch_tables() { 126 PredictorDatabase::resource_prefetch_tables() {
125 return db_->resource_prefetch_tables_; 127 return db_->resource_prefetch_tables_;
126 } 128 }
127 129
128 sql::Connection* PredictorDatabase::GetDatabase() { 130 sql::Connection* PredictorDatabase::GetDatabase() {
129 return &db_->db_; 131 return &db_->db_;
130 } 132 }
131 133
132 } // namespace predictors 134 } // namespace predictors
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698