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

Side by Side Diff: chrome/browser/android/offline_pages/offline_page_utils.cc

Issue 2860573004: [Offline Pages] Add cached offline page utils and show usage in settings. (Closed)
Patch Set: address missed comment Created 3 years, 7 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/android/offline_pages/offline_page_utils.h" 5 #include "chrome/browser/android/offline_pages/offline_page_utils.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 122
123 callback.Run( 123 callback.Run(
124 OfflinePageUtils::DuplicateCheckResult::DUPLICATE_REQUEST_FOUND); 124 OfflinePageUtils::DuplicateCheckResult::DUPLICATE_REQUEST_FOUND);
125 } 125 }
126 }; 126 };
127 127
128 request_coordinator->GetAllRequests(base::Bind( 128 request_coordinator->GetAllRequests(base::Bind(
129 request_coordinator_continuation, browser_context, url, callback)); 129 request_coordinator_continuation, browser_context, url, callback));
130 } 130 }
131 131
132 void DoCalculateSizeBetween(
133 const offline_pages::SizeInBytesCallback& callback,
134 const base::Time& begin_time,
135 const base::Time& end_time,
136 const offline_pages::MultipleOfflinePageItemResult& result) {
137 int64_t total_size = 0;
138 for (auto& page : result) {
139 if (begin_time <= page.creation_time && page.creation_time < end_time)
140 total_size += page.file_size;
141 }
142 callback.Run(total_size);
143 }
144
132 } // namespace 145 } // namespace
133 146
134 // static 147 // static
135 void OfflinePageUtils::SelectPageForURL( 148 void OfflinePageUtils::SelectPageForURL(
136 content::BrowserContext* browser_context, 149 content::BrowserContext* browser_context,
137 const GURL& url, 150 const GURL& url,
138 OfflinePageModel::URLSearchMode url_search_mode, 151 OfflinePageModel::URLSearchMode url_search_mode,
139 int tab_id, 152 int tab_id,
140 const base::Callback<void(const OfflinePageItem*)>& callback) { 153 const base::Callback<void(const OfflinePageItem*)>& callback) {
141 OfflinePageModel* offline_page_model = 154 OfflinePageModel* offline_page_model =
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 314
302 // static 315 // static
303 bool OfflinePageUtils::CanDownloadAsOfflinePage( 316 bool OfflinePageUtils::CanDownloadAsOfflinePage(
304 const GURL& url, 317 const GURL& url,
305 const std::string& contents_mime_type) { 318 const std::string& contents_mime_type) {
306 return url.SchemeIsHTTPOrHTTPS() && 319 return url.SchemeIsHTTPOrHTTPS() &&
307 (net::MatchesMimeType(contents_mime_type, "text/html") || 320 (net::MatchesMimeType(contents_mime_type, "text/html") ||
308 net::MatchesMimeType(contents_mime_type, "application/xhtml+xml")); 321 net::MatchesMimeType(contents_mime_type, "application/xhtml+xml"));
309 } 322 }
310 323
324 // static
325 bool OfflinePageUtils::GetCachedOfflinePageSizeBetween(
326 content::BrowserContext* browser_context,
327 const SizeInBytesCallback& callback,
328 const base::Time& begin_time,
329 const base::Time& end_time) {
330 OfflinePageModel* offline_page_model =
331 OfflinePageModelFactory::GetForBrowserContext(browser_context);
332 if (!offline_page_model || begin_time > end_time)
333 return false;
334 OfflinePageModelQueryBuilder builder;
335 builder.RequireRemovedOnCacheReset(
336 OfflinePageModelQuery::Requirement::INCLUDE_MATCHING);
337 offline_page_model->GetPagesMatchingQuery(
338 builder.Build(offline_page_model->GetPolicyController()),
339 base::Bind(&DoCalculateSizeBetween, callback, begin_time, end_time));
340 return true;
341 }
342
311 } // namespace offline_pages 343 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698