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

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: Moving to WeakPtrs and RVHD. 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 18 matching lines...) Expand all
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_;
51 scoped_refptr<AutocompleteActionPredictorTable> autocomplete_table_; 52 scoped_refptr<AutocompleteActionPredictorTable> autocomplete_table_;
53 scoped_refptr<ResourcePrefetchPredictorTables> resource_prefetch_tables_;
52 54
53 DISALLOW_COPY_AND_ASSIGN(PredictorDatabaseInternal); 55 DISALLOW_COPY_AND_ASSIGN(PredictorDatabaseInternal);
54 }; 56 };
55 57
56 58
57 PredictorDatabaseInternal::PredictorDatabaseInternal(Profile* profile) 59 PredictorDatabaseInternal::PredictorDatabaseInternal(Profile* profile)
58 : db_path_(profile->GetPath().Append(kPredictorDatabaseName)), 60 : db_path_(profile->GetPath().Append(kPredictorDatabaseName)),
59 autocomplete_table_(new AutocompleteActionPredictorTable()) { 61 autocomplete_table_(new AutocompleteActionPredictorTable()),
62 resource_prefetch_tables_(new ResourcePrefetchPredictorTables()) {
60 } 63 }
61 64
62 PredictorDatabaseInternal::~PredictorDatabaseInternal() { 65 PredictorDatabaseInternal::~PredictorDatabaseInternal() {
63 } 66 }
64 67
65 void PredictorDatabaseInternal::Initialize() { 68 void PredictorDatabaseInternal::Initialize() {
66 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::DB)); 69 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::DB));
67 70
68 db_.set_exclusive_locking(); 71 db_.set_exclusive_locking();
69 bool success = db_.Open(db_path_); 72 bool success = db_.Open(db_path_);
70 73
71 if (!success) 74 if (!success)
72 return; 75 return;
73 76
74 autocomplete_table_->Initialize(&db_); 77 autocomplete_table_->Initialize(&db_);
78 resource_prefetch_tables_->Initialize(&db_);
75 79
76 LogDatabaseStats(); 80 LogDatabaseStats();
77 } 81 }
78 82
79 void PredictorDatabaseInternal::SetCancelled() { 83 void PredictorDatabaseInternal::SetCancelled() {
80 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 84 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
81 85
82 autocomplete_table_->cancelled_.Set(); 86 autocomplete_table_->cancelled_.Set();
87 resource_prefetch_tables_->cancelled_.Set();
83 } 88 }
84 89
85 void PredictorDatabaseInternal::LogDatabaseStats() { 90 void PredictorDatabaseInternal::LogDatabaseStats() {
86 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::DB)); 91 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::DB));
87 92
88 int64 db_size; 93 int64 db_size;
89 bool success = file_util::GetFileSize(db_path_, &db_size); 94 bool success = file_util::GetFileSize(db_path_, &db_size);
90 DCHECK(success) << "Failed to get file size for " << db_path_.value(); 95 DCHECK(success) << "Failed to get file size for " << db_path_.value();
91 UMA_HISTOGRAM_MEMORY_KB("PredictorDatabase.DatabaseSizeKB", 96 UMA_HISTOGRAM_MEMORY_KB("PredictorDatabase.DatabaseSizeKB",
92 static_cast<int>(db_size / 1024)); 97 static_cast<int>(db_size / 1024));
93 98
94 autocomplete_table_->LogDatabaseStats(); 99 autocomplete_table_->LogDatabaseStats();
100 resource_prefetch_tables_->LogDatabaseStats();
95 } 101 }
96 102
97
98 PredictorDatabase::PredictorDatabase(Profile* profile) 103 PredictorDatabase::PredictorDatabase(Profile* profile)
99 : db_(new PredictorDatabaseInternal(profile)) { 104 : db_(new PredictorDatabaseInternal(profile)) {
100 content::BrowserThread::PostTask(content::BrowserThread::DB, FROM_HERE, 105 content::BrowserThread::PostTask(content::BrowserThread::DB, FROM_HERE,
101 base::Bind(&PredictorDatabaseInternal::Initialize, db_)); 106 base::Bind(&PredictorDatabaseInternal::Initialize, db_));
102 } 107 }
103 108
104 PredictorDatabase::~PredictorDatabase() { 109 PredictorDatabase::~PredictorDatabase() {
105 } 110 }
106 111
107 void PredictorDatabase::Shutdown() { 112 void PredictorDatabase::Shutdown() {
108 db_->SetCancelled(); 113 db_->SetCancelled();
109 } 114 }
110 115
111 scoped_refptr<AutocompleteActionPredictorTable> 116 scoped_refptr<AutocompleteActionPredictorTable>
112 PredictorDatabase::autocomplete_table() { 117 PredictorDatabase::autocomplete_table() {
113 return db_->autocomplete_table_; 118 return db_->autocomplete_table_;
114 } 119 }
115 120
121 scoped_refptr<ResourcePrefetchPredictorTables>
122 PredictorDatabase::resource_prefetch_tables() {
123 return db_->resource_prefetch_tables_;
124 }
125
116 sql::Connection* PredictorDatabase::GetDatabase() { 126 sql::Connection* PredictorDatabase::GetDatabase() {
117 return &db_->db_; 127 return &db_->db_;
118 } 128 }
119 129
120 } // namespace predictors 130 } // namespace predictors
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698