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

Side by Side Diff: components/offline_pages/background/request_queue_store_sql.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_REQUEST_QUEUE_STORE_SQL_H_
6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_STORE_SQL_H_
7
8 #include <stdint.h>
9 #include <memory>
10 #include <vector>
11
12 #include "base/files/file_path.h"
13 #include "base/memory/weak_ptr.h"
14 #include "components/offline_pages/background/request_queue_store.h"
15
16 namespace base {
17 class SequencedTaskRunner;
18 }
19
20 namespace sql {
21 class Connection;
22 }
23
24 namespace offline_pages {
25
26 // SQLite implementation of RequestQueueStore.
27 class RequestQueueStoreSQL : public RequestQueueStore {
28 public:
29 RequestQueueStoreSQL(
30 scoped_refptr<base::SequencedTaskRunner> background_task_runner,
31 const base::FilePath& database_dir);
32 ~RequestQueueStoreSQL() override;
33
34 // RequestQueueStore implementation.
35 void Initialize(const InitializeCallback& callback) override;
36 void GetRequests(const GetRequestsCallback& callback) override;
37 // Note: current implementation of this method makes a SQL query per ID. This
38 // is OK as long as number of IDs stays low, which is a typical case.
39 // Implementation should be revisited in case that presumption changes.
40 void GetRequestsByIds(const std::vector<int64_t>& request_ids,
41 const UpdateCallback& callback) override;
42 void AddRequest(const SavePageRequest& offline_page,
43 const AddCallback& callback) override;
44 void UpdateRequests(const std::vector<SavePageRequest>& requests,
45 const UpdateCallback& callback) override;
46 void RemoveRequests(const std::vector<int64_t>& request_ids,
47 const UpdateCallback& callback) override;
48 void Reset(const ResetCallback& callback) override;
49 StoreState state() const override;
50
51 private:
52 // Used to finalize DB connection initialization.
53 void OnOpenConnectionDone(const InitializeCallback& callback, bool success);
54
55 // Used to finalize DB connection reset.
56 void OnResetDone(const ResetCallback& callback, bool success);
57
58 // Helper function to return immediately if no database is found.
59 bool CheckDb() const;
60
61 // Background thread where all SQL access should be run.
62 scoped_refptr<base::SequencedTaskRunner> background_task_runner_;
63
64 // Path to the database on disk.
65 base::FilePath db_file_path_;
66
67 // Database connection.
68 std::unique_ptr<sql::Connection> db_;
69
70 // State of the store.
71 StoreState state_;
72
73 base::WeakPtrFactory<RequestQueueStoreSQL> weak_ptr_factory_;
74 DISALLOW_COPY_AND_ASSIGN(RequestQueueStoreSQL);
75 };
76
77 } // namespace offline_pages
78
79 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_STORE_SQL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698