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

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: Fix unit tests on Android N5X swarming bot 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 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
84 } // namespace 85 } // namespace
85 86
86 BackgroundLoaderOffliner::BackgroundLoaderOffliner( 87 BackgroundLoaderOffliner::BackgroundLoaderOffliner(
87 content::BrowserContext* browser_context, 88 content::BrowserContext* browser_context,
88 const OfflinerPolicy* policy, 89 const OfflinerPolicy* policy,
89 OfflinePageModel* offline_page_model) 90 OfflinePageModel* offline_page_model)
90 : browser_context_(browser_context), 91 : browser_context_(browser_context),
91 offline_page_model_(offline_page_model), 92 offline_page_model_(offline_page_model),
92 policy_(policy), 93 policy_(policy),
93 is_low_end_device_(base::SysInfo::IsLowEndDevice()), 94 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, 408 void BackgroundLoaderOffliner::OnPageSaved(SavePageResult save_result,
408 int64_t offline_id) { 409 int64_t offline_id) {
409 if (!pending_request_) 410 if (!pending_request_)
410 return; 411 return;
411 412
412 SavePageRequest request(*pending_request_.get()); 413 SavePageRequest request(*pending_request_.get());
413 bool did_snapshot_on_last_retry = did_snapshot_on_last_retry_; 414 bool did_snapshot_on_last_retry = did_snapshot_on_last_retry_;
414 ResetState(); 415 ResetState();
415 416
416 if (save_state_ == DELETE_AFTER_SAVE) { 417 if (save_state_ == DELETE_AFTER_SAVE) {
418 // Delete the saved page off disk and from the OPM.
419 std::vector<int64_t> offline_ids;
420 offline_ids.push_back(offline_id);
421 offline_page_model_->DeletePagesByOfflineId(
422 offline_ids,
423 base::Bind(&BackgroundLoaderOffliner::DeleteOfflinePageCallback,
424 weak_ptr_factory_.GetWeakPtr(), request));
417 save_state_ = NONE; 425 save_state_ = NONE;
418 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;
427 } else if (save_result == SavePageResult::SUCCESS) { 434 } else if (save_result == SavePageResult::SUCCESS) {
428 if (did_snapshot_on_last_retry) 435 if (did_snapshot_on_last_retry)
429 save_status = RequestStatus::SAVED_ON_LAST_RETRY; 436 save_status = RequestStatus::SAVED_ON_LAST_RETRY;
430 else 437 else
431 save_status = RequestStatus::SAVED; 438 save_status = RequestStatus::SAVED;
432 } else { 439 } else {
433 save_status = RequestStatus::SAVE_FAILED; 440 save_status = RequestStatus::SAVE_FAILED;
434 } 441 }
435 442
436 completion_callback_.Run(request, save_status); 443 completion_callback_.Run(request, save_status);
437 } 444 }
438 445
446 void BackgroundLoaderOffliner::DeleteOfflinePageCallback(
447 const SavePageRequest& request,
448 DeletePageResult result) {
449 cancel_callback_.Run(request);
450 }
451
439 void BackgroundLoaderOffliner::ResetState() { 452 void BackgroundLoaderOffliner::ResetState() {
440 pending_request_.reset(); 453 pending_request_.reset();
441 snapshot_controller_.reset(); 454 snapshot_controller_.reset();
442 page_load_state_ = SUCCESS; 455 page_load_state_ = SUCCESS;
443 network_bytes_ = 0LL; 456 network_bytes_ = 0LL;
444 is_low_bar_met_ = false; 457 is_low_bar_met_ = false;
445 did_snapshot_on_last_retry_ = false; 458 did_snapshot_on_last_retry_ = false;
446 // TODO(chili): Remove after RequestCoordinator can handle multiple offliners. 459 // TODO(chili): Remove after RequestCoordinator can handle multiple offliners.
447 // We reset the loader and observer after completion so loaders 460 // We reset the loader and observer after completion so loaders
448 // will not be re-used across different requests/tries. This is a temporary 461 // will not be re-used across different requests/tries. This is a temporary
(...skipping 27 matching lines...) Expand all
476 // Given the choice between int and double, we choose to implicitly convert to 489 // 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 490 // 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). 491 // milliseconds than we can with a 2 bit int, 53 bits vs 32).
479 double delay = delay_so_far.InMilliseconds(); 492 double delay = delay_so_far.InMilliseconds();
480 signal_data_.SetDouble(signal_name, delay); 493 signal_data_.SetDouble(signal_name, delay);
481 } 494 }
482 495
483 } // namespace offline_pages 496 } // namespace offline_pages
484 497
485 DEFINE_WEB_CONTENTS_USER_DATA_KEY(offline_pages::OfflinerData); 498 DEFINE_WEB_CONTENTS_USER_DATA_KEY(offline_pages::OfflinerData);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698