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

Side by Side Diff: components/offline_pages/background/initialize_store_task.h

Issue 2489443002: Move all components/offline_pages/ files into component/offline_pages/core (Closed)
Patch Set: rebase Created 4 years 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_OFFLINE_PAGES_BACKGROUND_INITIALIZE_STORE_TASK_H_
6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_INITIALIZE_STORE_TASK_H_
7
8 #include <stdint.h>
9
10 #include "base/memory/weak_ptr.h"
11 #include "components/offline_pages/background/request_queue_store.h"
12 #include "components/offline_pages/core/task.h"
13
14 namespace offline_pages {
15
16 // Task performing a request queue store initialization and reset if one is
17 // necessary. Reset is triggered in case the initialization fails. If reset
18 // fails (perhaps not able to delete the folder or raze the database in case of
19 // SQLite-backed store) a new attempt can be made. Number of attempts is limited
20 // by |reset_attempts_left_|. Successful reset will be followed by another
21 // attempt to initialize the database.
22 //
23 // Task is completed when either the store is correctly initialized or there are
24 // not more reset attempts left.
25 class InitializeStoreTask : public Task {
26 public:
27 InitializeStoreTask(RequestQueueStore* store,
28 const RequestQueueStore::InitializeCallback& callback);
29 ~InitializeStoreTask() override;
30
31 // TaskQueue::Task implementation.
32 void Run() override;
33
34 private:
35 // Step 1. Initialize store.
36 void InitializeStore();
37 // Step 2a. Completes initialization if successful or tries to reset if there
38 // are more attempts left.
39 void CompleteIfSuccessful(bool success);
40 // Step 2b. Reset store in case initialization fails.
41 void TryToResetStore();
42 // Step 3. If 2b was successful go to step 1, else try 2b again.
43 void OnStoreResetDone(bool success);
44
45 // Store that this task initializes.
46 RequestQueueStore* store_;
47 // Number of attempts left to reset and reinitialize the store.
48 int reset_attempts_left_;
49 // Callback to complete the task.
50 RequestQueueStore::InitializeCallback callback_;
51
52 base::WeakPtrFactory<InitializeStoreTask> weak_ptr_factory_;
53 DISALLOW_COPY_AND_ASSIGN(InitializeStoreTask);
54 };
55
56 } // namespace offline_pages
57
58 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_INITIALIZE_STORE_TASK_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698