1 // Copyright 2017 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CONTENT_BROWSER_BACKGROUND_FETCH_STORAGE_MARK_REGISTRATION_FOR_DELETION_TASK_H_ 6 #define CONTENT_BROWSER_BACKGROUND_FETCH_STORAGE_MARK_REGISTRATION_FOR_DELETION_TASK_H_ 7 8 #include <string> 9 #include <vector> 10 11 #include "content/browser/background_fetch/storage/database_task.h" 12 #include "third_party/blink/public/common/service_worker/service_worker_status_code.h" 13 14 namespace content { 15 namespace background_fetch { 16 17 // Marks Background Fetch registrations for deletion from the database. This is 18 // used when some parts of the registration may still be in use and cannot be 19 // completely removed. 20 class MarkRegistrationForDeletionTask : public background_fetch::DatabaseTask { 21 public: 22 using MarkRegistrationForDeletionCallback = 23 base::OnceCallback<void(blink::mojom::BackgroundFetchError, 24 blink::mojom::BackgroundFetchFailureReason)>; 25 26 MarkRegistrationForDeletionTask( 27 DatabaseTaskHost* host, 28 const BackgroundFetchRegistrationId& registration_id, 29 bool check_for_failure, 30 MarkRegistrationForDeletionCallback callback); 31 32 ~MarkRegistrationForDeletionTask() override; 33 34 void Start() override; 35 36 private: 37 void DidGetActiveUniqueId(const std::vector<std::string>& data, 38 blink::ServiceWorkerStatusCode status); 39 40 void DidDeactivate(blink::ServiceWorkerStatusCode status); 41 42 void DidGetCompletedRequests(const std::vector<std::string>& data, 43 blink::ServiceWorkerStatusCode status); 44 45 void FinishWithError(blink::mojom::BackgroundFetchError error) override; 46 47 std::string HistogramName() const override; 48 49 BackgroundFetchRegistrationId registration_id_; 50 bool check_for_failure_; 51 MarkRegistrationForDeletionCallback callback_; 52 53 blink::mojom::BackgroundFetchFailureReason failure_reason_ = 54 blink::mojom::BackgroundFetchFailureReason::NONE; 55 56 base::WeakPtrFactory<MarkRegistrationForDeletionTask> weak_factory_{ 57 this}; // Keep as last. 58 59 DISALLOW_COPY_AND_ASSIGN(MarkRegistrationForDeletionTask); 60 }; 61 62 } // namespace background_fetch 63 } // namespace content 64 65 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_STORAGE_MARK_REGISTRATION_FOR_DELETION_TASK_H_ 66