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

Side by Side Diff: components/offline_pages/offline_page_metadata_store_sql.h

Issue 2329283002: [Offline pages] OPM SQL store: moving load to constructor, updating read to GetOfflinePages (Closed)
Patch Set: Addressing CR feedback Created 4 years, 3 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 #ifndef COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_SQL_H_ 5 #ifndef COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_SQL_H_
6 #define COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_SQL_H_ 6 #define COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_SQL_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 16 matching lines...) Expand all
27 // OfflinePageMetadataStoreSQL is an instance of OfflinePageMetadataStore 27 // OfflinePageMetadataStoreSQL is an instance of OfflinePageMetadataStore
28 // which is implemented using a SQLite database. 28 // which is implemented using a SQLite database.
29 class OfflinePageMetadataStoreSQL : public OfflinePageMetadataStore { 29 class OfflinePageMetadataStoreSQL : public OfflinePageMetadataStore {
30 public: 30 public:
31 OfflinePageMetadataStoreSQL( 31 OfflinePageMetadataStoreSQL(
32 scoped_refptr<base::SequencedTaskRunner> background_task_runner, 32 scoped_refptr<base::SequencedTaskRunner> background_task_runner,
33 const base::FilePath& database_dir); 33 const base::FilePath& database_dir);
34 ~OfflinePageMetadataStoreSQL() override; 34 ~OfflinePageMetadataStoreSQL() override;
35 35
36 // Implementation methods. 36 // Implementation methods.
37 void Load(const LoadCallback& callback) override; 37 void GetOfflinePages(const LoadCallback& callback) override;
38 void AddOrUpdateOfflinePage(const OfflinePageItem& offline_page, 38 void AddOrUpdateOfflinePage(const OfflinePageItem& offline_page,
39 const UpdateCallback& callback) override; 39 const UpdateCallback& callback) override;
40 void RemoveOfflinePages(const std::vector<int64_t>& offline_ids, 40 void RemoveOfflinePages(const std::vector<int64_t>& offline_ids,
41 const UpdateCallback& callback) override; 41 const UpdateCallback& callback) override;
42 void Reset(const ResetCallback& callback) override; 42 void Reset(const ResetCallback& callback) override;
43 StoreState state() const override;
43 44
44 private: 45 private:
45 // Synchronous implementations, these are run on the background thread 46 // Synchronous implementations, these are run on the background thread
46 // and actually do the work to access SQL. The implementations above 47 // and actually do the work to access SQL. The implementations above
47 // simply dispatch to the corresponding *Sync method on the background thread. 48 // simply dispatch to the corresponding *Sync method on the background thread.
48 // 'runner' is where to run the callback. 49 // 'runner' is where to run the callback.
49 static void LoadSync(sql::Connection* db,
50 const base::FilePath& path,
51 scoped_refptr<base::SingleThreadTaskRunner> runner,
52 const LoadCallback& callback);
53 static void AddOrUpdateOfflinePageSync( 50 static void AddOrUpdateOfflinePageSync(
54 const OfflinePageItem& offline_page, 51 const OfflinePageItem& offline_page,
55 sql::Connection* db, 52 sql::Connection* db,
56 scoped_refptr<base::SingleThreadTaskRunner> runner, 53 scoped_refptr<base::SingleThreadTaskRunner> runner,
57 const UpdateCallback& callback); 54 const UpdateCallback& callback);
58 static void RemoveOfflinePagesSync( 55 static void RemoveOfflinePagesSync(
59 const std::vector<int64_t>& offline_ids, 56 const std::vector<int64_t>& offline_ids,
60 sql::Connection* db, 57 sql::Connection* db,
61 scoped_refptr<base::SingleThreadTaskRunner> runner, 58 scoped_refptr<base::SingleThreadTaskRunner> runner,
62 const UpdateCallback& callback); 59 const UpdateCallback& callback);
63 static void ResetSync(std::unique_ptr<sql::Connection> db,
64 scoped_refptr<base::SingleThreadTaskRunner> runner,
65 const ResetCallback& callback);
66 60
67 static void NotifyLoadResult( 61 // Used to initialize DB connection.
68 scoped_refptr<base::SingleThreadTaskRunner> runner, 62 void OpenConnection();
69 const LoadCallback& callback, 63 void OnOpenConnectionDone(StoreState state);
70 LoadStatus status, 64
71 const std::vector<OfflinePageItem>& result); 65 // Used to reset DB connection.
66 void OnResetDone(const ResetCallback& callback, StoreState state);
67
68 // Helper function that checks whether a valid DB connection is present.
69 // Returns true if valid connection is present, otherwise it returns false and
70 // calls the provided callback as a shortcut.
71 bool CheckDb(const base::Closure& callback);
72 72
73 // Background thread where all SQL access should be run. 73 // Background thread where all SQL access should be run.
74 scoped_refptr<base::SequencedTaskRunner> background_task_runner_; 74 scoped_refptr<base::SequencedTaskRunner> background_task_runner_;
75 75
76 // Path to the database on disk. 76 // Path to the database on disk.
77 base::FilePath db_file_path_; 77 base::FilePath db_file_path_;
78 std::unique_ptr<sql::Connection> db_; 78 std::unique_ptr<sql::Connection> db_;
79 79
80 StoreState state_;
81 base::WeakPtrFactory<OfflinePageMetadataStoreSQL> weak_ptr_factory_;
82
80 DISALLOW_COPY_AND_ASSIGN(OfflinePageMetadataStoreSQL); 83 DISALLOW_COPY_AND_ASSIGN(OfflinePageMetadataStoreSQL);
81 }; 84 };
82 85
83 } // namespace offline_pages 86 } // namespace offline_pages
84 87
85 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_SQL_H_ 88 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_SQL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698