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

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

Issue 10416002: Seculative resource prefetching for URLs CL. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Resolving conflicts. Created 8 years, 6 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"
11 #include "base/stringprintf.h" 11 #include "base/stringprintf.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "chrome/browser/predictors/autocomplete_action_predictor_table.h" 13 #include "chrome/browser/predictors/autocomplete_action_predictor_table.h"
14 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h"
14 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
15 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
16 #include "sql/connection.h" 17 #include "sql/connection.h"
17 #include "sql/statement.h" 18 #include "sql/statement.h"
18 19
19 namespace { 20 namespace {
20 21
21 // TODO(shishir): This should move to a more generic name. 22 // TODO(shishir): This should move to a more generic name.
22 const FilePath::CharType kPredictorDatabaseName[] = 23 const FilePath::CharType kPredictorDatabaseName[] =
23 FILE_PATH_LITERAL("Network Action Predictor"); 24 FILE_PATH_LITERAL("Network Action Predictor");
(...skipping 17 matching lines...) Expand all
41 // constructor to ease construction/destruction of this object on one thread 42 // constructor to ease construction/destruction of this object on one thread
42 // but database access on the DB thread. 43 // but database access on the DB thread.
43 void Initialize(); 44 void Initialize();
44 void LogDatabaseStats(); // DB Thread. 45 void LogDatabaseStats(); // DB Thread.
45 46
46 // 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.
47 void SetCancelled(); 48 void SetCancelled();
48 49
49 FilePath db_path_; 50 FilePath db_path_;
50 sql::Connection db_; 51 sql::Connection db_;
52
53 // TODO(shishir): These tables may not need to be refcounted. Maybe move them
54 // to using a WeakPtr instead.
51 scoped_refptr<AutocompleteActionPredictorTable> autocomplete_table_; 55 scoped_refptr<AutocompleteActionPredictorTable> autocomplete_table_;
56 scoped_refptr<ResourcePrefetchPredictorTables> resource_prefetch_tables_;
52 57
53 DISALLOW_COPY_AND_ASSIGN(PredictorDatabaseInternal); 58 DISALLOW_COPY_AND_ASSIGN(PredictorDatabaseInternal);
54 }; 59 };
55 60
56 61
57 PredictorDatabaseInternal::PredictorDatabaseInternal(Profile* profile) 62 PredictorDatabaseInternal::PredictorDatabaseInternal(Profile* profile)
58 : db_path_(profile->GetPath().Append(kPredictorDatabaseName)), 63 : db_path_(profile->GetPath().Append(kPredictorDatabaseName)),
59 autocomplete_table_(new AutocompleteActionPredictorTable()) { 64 autocomplete_table_(new AutocompleteActionPredictorTable()),
65 resource_prefetch_tables_(new ResourcePrefetchPredictorTables()) {
60 } 66 }
61 67
62 PredictorDatabaseInternal::~PredictorDatabaseInternal() { 68 PredictorDatabaseInternal::~PredictorDatabaseInternal() {
63 } 69 }
64 70
65 void PredictorDatabaseInternal::Initialize() { 71 void PredictorDatabaseInternal::Initialize() {
66 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::DB)); 72 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::DB));
67 73
68 db_.set_exclusive_locking(); 74 db_.set_exclusive_locking();
69 bool success = db_.Open(db_path_); 75 bool success = db_.Open(db_path_);
70 76
71 if (!success) 77 if (!success)
72 return; 78 return;
73 79
74 autocomplete_table_->Initialize(&db_); 80 autocomplete_table_->Initialize(&db_);
81 resource_prefetch_tables_->Initialize(&db_);
75 82
76 LogDatabaseStats(); 83 LogDatabaseStats();
77 } 84 }
78 85
79 void PredictorDatabaseInternal::SetCancelled() { 86 void PredictorDatabaseInternal::SetCancelled() {
80 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 87 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
81 88
82 autocomplete_table_->cancelled_.Set(); 89 autocomplete_table_->SetCancelled();
90 resource_prefetch_tables_->SetCancelled();
83 } 91 }
84 92
85 void PredictorDatabaseInternal::LogDatabaseStats() { 93 void PredictorDatabaseInternal::LogDatabaseStats() {
86 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::DB)); 94 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::DB));
87 95
88 int64 db_size; 96 int64 db_size;
89 bool success = file_util::GetFileSize(db_path_, &db_size); 97 bool success = file_util::GetFileSize(db_path_, &db_size);
90 DCHECK(success) << "Failed to get file size for " << db_path_.value(); 98 DCHECK(success) << "Failed to get file size for " << db_path_.value();
91 UMA_HISTOGRAM_MEMORY_KB("PredictorDatabase.DatabaseSizeKB", 99 UMA_HISTOGRAM_MEMORY_KB("PredictorDatabase.DatabaseSizeKB",
92 static_cast<int>(db_size / 1024)); 100 static_cast<int>(db_size / 1024));
93 101
94 autocomplete_table_->LogDatabaseStats(); 102 autocomplete_table_->LogDatabaseStats();
103 resource_prefetch_tables_->LogDatabaseStats();
95 } 104 }
96 105
97
98 PredictorDatabase::PredictorDatabase(Profile* profile) 106 PredictorDatabase::PredictorDatabase(Profile* profile)
99 : db_(new PredictorDatabaseInternal(profile)) { 107 : db_(new PredictorDatabaseInternal(profile)) {
100 content::BrowserThread::PostTask(content::BrowserThread::DB, FROM_HERE, 108 content::BrowserThread::PostTask(content::BrowserThread::DB, FROM_HERE,
101 base::Bind(&PredictorDatabaseInternal::Initialize, db_)); 109 base::Bind(&PredictorDatabaseInternal::Initialize, db_));
102 } 110 }
103 111
104 PredictorDatabase::~PredictorDatabase() { 112 PredictorDatabase::~PredictorDatabase() {
105 } 113 }
106 114
107 void PredictorDatabase::Shutdown() { 115 void PredictorDatabase::Shutdown() {
108 db_->SetCancelled(); 116 db_->SetCancelled();
109 } 117 }
110 118
111 scoped_refptr<AutocompleteActionPredictorTable> 119 scoped_refptr<AutocompleteActionPredictorTable>
112 PredictorDatabase::autocomplete_table() { 120 PredictorDatabase::autocomplete_table() {
113 return db_->autocomplete_table_; 121 return db_->autocomplete_table_;
114 } 122 }
115 123
124 scoped_refptr<ResourcePrefetchPredictorTables>
125 PredictorDatabase::resource_prefetch_tables() {
126 return db_->resource_prefetch_tables_;
127 }
128
116 sql::Connection* PredictorDatabase::GetDatabase() { 129 sql::Connection* PredictorDatabase::GetDatabase() {
117 return &db_->db_; 130 return &db_->db_;
118 } 131 }
119 132
120 } // namespace predictors 133 } // namespace predictors
OLDNEW
« no previous file with comments | « chrome/browser/predictors/predictor_database.h ('k') | chrome/browser/predictors/predictor_table_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698