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: components/precache/core/precache_database.cc

Issue 656363002: Type conversion fixes, components/ edition. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "components/precache/core/precache_database.h" 5 #include "components/precache/core/precache_database.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 // Since the precache came from the cache, and there's no entry in the URL 93 // Since the precache came from the cache, and there's no entry in the URL
94 // table for the URL, this means that the resource was already in the cache 94 // table for the URL, this means that the resource was already in the cache
95 // because of user browsing. Thus, this precache had no effect, so ignore 95 // because of user browsing. Thus, this precache had no effect, so ignore
96 // it. 96 // it.
97 return; 97 return;
98 } 98 }
99 99
100 if (!was_cached) { 100 if (!was_cached) {
101 // The precache only counts as overhead if it was downloaded over the 101 // The precache only counts as overhead if it was downloaded over the
102 // network. 102 // network.
103 UMA_HISTOGRAM_COUNTS("Precache.DownloadedPrecacheMotivated", size); 103 UMA_HISTOGRAM_COUNTS("Precache.DownloadedPrecacheMotivated",
104 static_cast<base::HistogramBase::Sample>(size));
104 } 105 }
105 106
106 // Use the URL table to keep track of URLs that are in the cache thanks to 107 // Use the URL table to keep track of URLs that are in the cache thanks to
107 // precaching. If a row for the URL already exists, than update the timestamp 108 // precaching. If a row for the URL already exists, than update the timestamp
108 // to |fetch_time|. 109 // to |fetch_time|.
109 buffered_writes_.push_back( 110 buffered_writes_.push_back(
110 base::Bind(&PrecacheURLTable::AddURL, 111 base::Bind(&PrecacheURLTable::AddURL,
111 base::Unretained(&precache_url_table_), url, fetch_time)); 112 base::Unretained(&precache_url_table_), url, fetch_time));
112 buffered_urls_.insert(url.spec()); 113 buffered_urls_.insert(url.spec());
113 MaybePostFlush(); 114 MaybePostFlush();
(...skipping 12 matching lines...) Expand all
126 // If the URL for this fetch is in the write buffer, then flush the write 127 // If the URL for this fetch is in the write buffer, then flush the write
127 // buffer. 128 // buffer.
128 Flush(); 129 Flush();
129 } 130 }
130 131
131 if (was_cached && !precache_url_table_.HasURL(url)) { 132 if (was_cached && !precache_url_table_.HasURL(url)) {
132 // Ignore cache hits that precache can't take credit for. 133 // Ignore cache hits that precache can't take credit for.
133 return; 134 return;
134 } 135 }
135 136
137 base::HistogramBase::Sample size_sample =
138 static_cast<base::HistogramBase::Sample>(size);
136 if (!was_cached) { 139 if (!was_cached) {
137 // The fetch was served over the network during user browsing, so count it 140 // The fetch was served over the network during user browsing, so count it
138 // as downloaded non-precache bytes. 141 // as downloaded non-precache bytes.
139 UMA_HISTOGRAM_COUNTS("Precache.DownloadedNonPrecache", size); 142 UMA_HISTOGRAM_COUNTS("Precache.DownloadedNonPrecache", size_sample);
140 if (is_connection_cellular) { 143 if (is_connection_cellular) {
141 UMA_HISTOGRAM_COUNTS("Precache.DownloadedNonPrecache.Cellular", size); 144 UMA_HISTOGRAM_COUNTS("Precache.DownloadedNonPrecache.Cellular",
145 size_sample);
142 } 146 }
143 } else { 147 } else {
144 // The fetch was served from the cache, and since there's an entry for this 148 // The fetch was served from the cache, and since there's an entry for this
145 // URL in the URL table, this means that the resource was served from the 149 // URL in the URL table, this means that the resource was served from the
146 // cache only because precaching put it there. Thus, precaching was helpful, 150 // cache only because precaching put it there. Thus, precaching was helpful,
147 // so count the fetch as saved bytes. 151 // so count the fetch as saved bytes.
148 UMA_HISTOGRAM_COUNTS("Precache.Saved", size); 152 UMA_HISTOGRAM_COUNTS("Precache.Saved", size_sample);
149 if (is_connection_cellular) { 153 if (is_connection_cellular) {
150 UMA_HISTOGRAM_COUNTS("Precache.Saved.Cellular", size); 154 UMA_HISTOGRAM_COUNTS("Precache.Saved.Cellular", size_sample);
151 } 155 }
152 } 156 }
153 157
154 // Since the resource has been fetched during user browsing, remove any record 158 // Since the resource has been fetched during user browsing, remove any record
155 // of that URL having been precached from the URL table, if any exists. 159 // of that URL having been precached from the URL table, if any exists.
156 // The current fetch would have put this resource in the cache regardless of 160 // The current fetch would have put this resource in the cache regardless of
157 // whether or not it was previously precached, so delete any record of that 161 // whether or not it was previously precached, so delete any record of that
158 // URL having been precached from the URL table. 162 // URL having been precached from the URL table.
159 buffered_writes_.push_back( 163 buffered_writes_.push_back(
160 base::Bind(&PrecacheURLTable::DeleteURL, 164 base::Bind(&PrecacheURLTable::DeleteURL,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 // database writes can be buffered up and flushed together in the same 222 // database writes can be buffered up and flushed together in the same
219 // transaction. 223 // transaction.
220 base::MessageLoop::current()->PostDelayedTask( 224 base::MessageLoop::current()->PostDelayedTask(
221 FROM_HERE, base::Bind(&PrecacheDatabase::PostedFlush, 225 FROM_HERE, base::Bind(&PrecacheDatabase::PostedFlush,
222 scoped_refptr<PrecacheDatabase>(this)), 226 scoped_refptr<PrecacheDatabase>(this)),
223 base::TimeDelta::FromSeconds(1)); 227 base::TimeDelta::FromSeconds(1));
224 is_flush_posted_ = true; 228 is_flush_posted_ = true;
225 } 229 }
226 230
227 } // namespace precache 231 } // namespace precache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698