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

Side by Side Diff: components/offline_pages/offline_page_model.cc

Issue 1442433003: Add "Show saved copy" button in dino page when there's offline copy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix trybots Created 5 years, 1 month 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 "components/offline_pages/offline_page_model.h" 5 #include "components/offline_pages/offline_page_model.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 std::vector<int64> bookmark_ids; 244 std::vector<int64> bookmark_ids;
245 for (const auto& id_page_pair : offline_pages_) 245 for (const auto& id_page_pair : offline_pages_)
246 bookmark_ids.push_back(id_page_pair.first); 246 bookmark_ids.push_back(id_page_pair.first);
247 DeletePagesByBookmarkId( 247 DeletePagesByBookmarkId(
248 bookmark_ids, 248 bookmark_ids,
249 base::Bind(&OfflinePageModel::OnRemoveAllFilesDoneForClearAll, 249 base::Bind(&OfflinePageModel::OnRemoveAllFilesDoneForClearAll,
250 weak_ptr_factory_.GetWeakPtr(), 250 weak_ptr_factory_.GetWeakPtr(),
251 callback)); 251 callback));
252 } 252 }
253 253
254 bool OfflinePageModel::HasOfflinePages() const {
255 DCHECK(is_loaded_);
256 return !offline_pages_.empty();
257 }
258
254 const std::vector<OfflinePageItem> OfflinePageModel::GetAllPages() const { 259 const std::vector<OfflinePageItem> OfflinePageModel::GetAllPages() const {
255 DCHECK(is_loaded_); 260 DCHECK(is_loaded_);
256 std::vector<OfflinePageItem> offline_pages; 261 std::vector<OfflinePageItem> offline_pages;
257 for (const auto& id_page_pair : offline_pages_) { 262 for (const auto& id_page_pair : offline_pages_) {
258 if (id_page_pair.second.IsMarkedForDeletion()) 263 if (id_page_pair.second.IsMarkedForDeletion())
259 continue; 264 continue;
260 offline_pages.push_back(id_page_pair.second); 265 offline_pages.push_back(id_page_pair.second);
261 } 266 }
262 return offline_pages; 267 return offline_pages;
263 } 268 }
(...skipping 21 matching lines...) Expand all
285 const GURL& offline_url) const { 290 const GURL& offline_url) const {
286 for (auto iter = offline_pages_.begin(); 291 for (auto iter = offline_pages_.begin();
287 iter != offline_pages_.end(); 292 iter != offline_pages_.end();
288 ++iter) { 293 ++iter) {
289 if (iter->second.GetOfflineURL() == offline_url) 294 if (iter->second.GetOfflineURL() == offline_url)
290 return &(iter->second); 295 return &(iter->second);
291 } 296 }
292 return nullptr; 297 return nullptr;
293 } 298 }
294 299
300 const OfflinePageItem* OfflinePageModel::GetPageByOnlineURL(
301 const GURL& online_url) const {
302 for (auto iter = offline_pages_.begin();
303 iter != offline_pages_.end();
304 ++iter) {
305 if (iter->second.url == online_url)
306 return &(iter->second);
307 }
308 return nullptr;
309 }
310
295 void OfflinePageModel::CheckForExternalFileDeletion() { 311 void OfflinePageModel::CheckForExternalFileDeletion() {
296 DCHECK(is_loaded_); 312 DCHECK(is_loaded_);
297 313
298 std::vector<std::pair<int64, base::FilePath>> id_path_pairs; 314 std::vector<std::pair<int64, base::FilePath>> id_path_pairs;
299 for (const auto& id_page_pair : offline_pages_) { 315 for (const auto& id_page_pair : offline_pages_) {
300 id_path_pairs.push_back( 316 id_path_pairs.push_back(
301 std::make_pair(id_page_pair.first, id_page_pair.second.file_path)); 317 std::make_pair(id_page_pair.first, id_page_pair.second.file_path));
302 } 318 }
303 319
304 std::vector<int64>* ids_of_pages_missing_archive_file = 320 std::vector<int64>* ids_of_pages_missing_archive_file =
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 } 648 }
633 649
634 void OfflinePageModel::CacheLoadedData( 650 void OfflinePageModel::CacheLoadedData(
635 const std::vector<OfflinePageItem>& offline_pages) { 651 const std::vector<OfflinePageItem>& offline_pages) {
636 offline_pages_.clear(); 652 offline_pages_.clear();
637 for (const auto& offline_page : offline_pages) 653 for (const auto& offline_page : offline_pages)
638 offline_pages_[offline_page.bookmark_id] = offline_page; 654 offline_pages_[offline_page.bookmark_id] = offline_page;
639 } 655 }
640 656
641 } // namespace offline_pages 657 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698