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

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

Issue 2850943002: If MHTML saving is cancelled, delete the page afterwards. (Closed)
Patch Set: 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
« no previous file with comments | « no previous file | chrome/browser/android/offline_pages/background_loader_offliner_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/background_loader_offliner.h" 5 #include "chrome/browser/android/offline_pages/background_loader_offliner.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "base/sys_info.h" 10 #include "base/sys_info.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 "OfflinePages.Background.BackgroundLoadingFailedCode"), 74 "OfflinePages.Background.BackgroundLoadingFailedCode"),
75 std::abs(error_code)); 75 std::abs(error_code));
76 } 76 }
77 77
78 void HandleApplicationStateChangeCancel( 78 void HandleApplicationStateChangeCancel(
79 const Offliner::CompletionCallback& completion_callback, 79 const Offliner::CompletionCallback& completion_callback,
80 const SavePageRequest& canceled_request) { 80 const SavePageRequest& canceled_request) {
81 completion_callback.Run(canceled_request, 81 completion_callback.Run(canceled_request,
82 Offliner::RequestStatus::FOREGROUND_CANCELED); 82 Offliner::RequestStatus::FOREGROUND_CANCELED);
83 } 83 }
84
85 void LocalDeletePageCallback(DeletePageResult result) {}
84 } // namespace 86 } // namespace
85 87
86 BackgroundLoaderOffliner::BackgroundLoaderOffliner( 88 BackgroundLoaderOffliner::BackgroundLoaderOffliner(
87 content::BrowserContext* browser_context, 89 content::BrowserContext* browser_context,
88 const OfflinerPolicy* policy, 90 const OfflinerPolicy* policy,
89 OfflinePageModel* offline_page_model) 91 OfflinePageModel* offline_page_model)
90 : browser_context_(browser_context), 92 : browser_context_(browser_context),
91 offline_page_model_(offline_page_model), 93 offline_page_model_(offline_page_model),
92 policy_(policy), 94 policy_(policy),
93 is_low_end_device_(base::SysInfo::IsLowEndDevice()), 95 is_low_end_device_(base::SysInfo::IsLowEndDevice()),
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 void BackgroundLoaderOffliner::OnPageSaved(SavePageResult save_result, 409 void BackgroundLoaderOffliner::OnPageSaved(SavePageResult save_result,
408 int64_t offline_id) { 410 int64_t offline_id) {
409 if (!pending_request_) 411 if (!pending_request_)
410 return; 412 return;
411 413
412 SavePageRequest request(*pending_request_.get()); 414 SavePageRequest request(*pending_request_.get());
413 bool did_snapshot_on_last_retry = did_snapshot_on_last_retry_; 415 bool did_snapshot_on_last_retry = did_snapshot_on_last_retry_;
414 ResetState(); 416 ResetState();
415 417
416 if (save_state_ == DELETE_AFTER_SAVE) { 418 if (save_state_ == DELETE_AFTER_SAVE) {
419 // Delete the saved page off disk and from the OPM.
420 std::vector<int64_t> offline_ids;
421 offline_ids.push_back(offline_id);
422 offline_page_model_->DeletePagesByOfflineId(
423 offline_ids, base::Bind(&LocalDeletePageCallback));
chili 2017/04/29 00:11:33 should we only run the cancel_callback_.Run once t
Pete Williamson 2017/04/29 00:14:44 My thinking here is that it is fine to return cont
417 save_state_ = NONE; 424 save_state_ = NONE;
418 cancel_callback_.Run(request); 425 cancel_callback_.Run(request);
419 return; 426 return;
420 } 427 }
421 428
422 save_state_ = NONE; 429 save_state_ = NONE;
423 430
424 Offliner::RequestStatus save_status; 431 Offliner::RequestStatus save_status;
425 if (save_result == SavePageResult::ALREADY_EXISTS) { 432 if (save_result == SavePageResult::ALREADY_EXISTS) {
426 save_status = RequestStatus::SAVED; 433 save_status = RequestStatus::SAVED;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 // Given the choice between int and double, we choose to implicitly convert to 483 // Given the choice between int and double, we choose to implicitly convert to
477 // a double since it maintains more precision (we can get a longer time in 484 // a double since it maintains more precision (we can get a longer time in
478 // milliseconds than we can with a 2 bit int, 53 bits vs 32). 485 // milliseconds than we can with a 2 bit int, 53 bits vs 32).
479 double delay = delay_so_far.InMilliseconds(); 486 double delay = delay_so_far.InMilliseconds();
480 signal_data_.SetDouble(signal_name, delay); 487 signal_data_.SetDouble(signal_name, delay);
481 } 488 }
482 489
483 } // namespace offline_pages 490 } // namespace offline_pages
484 491
485 DEFINE_WEB_CONTENTS_USER_DATA_KEY(offline_pages::OfflinerData); 492 DEFINE_WEB_CONTENTS_USER_DATA_KEY(offline_pages::OfflinerData);
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/android/offline_pages/background_loader_offliner_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698