| OLD | NEW |
| 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> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "components/offline_pages/offline_page_metadata_store.h" | 15 #include "components/offline_pages/offline_page_metadata_store.h" |
| 16 | 16 |
| 17 namespace base { | 17 namespace base { |
| 18 class SequencedTaskRunner; | 18 class SequencedTaskRunner; |
| 19 } | 19 } |
| 20 | 20 |
| 21 namespace sql { | 21 namespace sql { |
| 22 class Connection; | 22 class Connection; |
| 23 } | 23 } |
| 24 | 24 |
| 25 namespace offline_pages { | 25 namespace offline_pages { |
| 26 | 26 |
| 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 // |
| 30 // This store has a history of schema updates in pretty much every release. |
| 31 // Original schema was delivered in M52. Since then, the following changes |
| 32 // happened: |
| 33 // * In M53 expiration_time was added, |
| 34 // * In M54 title was added, |
| 35 // * In M55 we dropped the following fields (never used): version, status, |
| 36 // offline_url, user_initiated. |
| 37 // |
| 38 // Here is a procedure to update the schema for this store: |
| 39 // * Decide how to detect that the store is on a particular version, which |
| 40 // typically means that a certain field exists or is missing. This happens in |
| 41 // Upgrade section of |CreateSchema| |
| 42 // * Work out appropriate change and apply it to all existing upgrade paths. In |
| 43 // the interest of performing a single update of the store, it upgrades from a |
| 44 // detected version to the current one. This means that when making a change, |
| 45 // more than a single query may have to be updated (in case of fields being |
| 46 // removed or needed to be initialized to a specific, non-default value). |
| 47 // Such approach is preferred to doing N updates for every changed version on |
| 48 // a startup after browser update. |
| 49 // * New upgrade method should specify which version it is upgrading from, e.g. |
| 50 // |UpgradeFrom54|. |
| 51 // * Upgrade should use |UpgradeWithQuery| and simply specify SQL command to |
| 52 // move data from old table (prefixed by temp_) to the new one. |
| 29 class OfflinePageMetadataStoreSQL : public OfflinePageMetadataStore { | 53 class OfflinePageMetadataStoreSQL : public OfflinePageMetadataStore { |
| 30 public: | 54 public: |
| 31 OfflinePageMetadataStoreSQL( | 55 OfflinePageMetadataStoreSQL( |
| 32 scoped_refptr<base::SequencedTaskRunner> background_task_runner, | 56 scoped_refptr<base::SequencedTaskRunner> background_task_runner, |
| 33 const base::FilePath& database_dir); | 57 const base::FilePath& database_dir); |
| 34 ~OfflinePageMetadataStoreSQL() override; | 58 ~OfflinePageMetadataStoreSQL() override; |
| 35 | 59 |
| 36 // Implementation methods. | 60 // Implementation methods. |
| 37 void GetOfflinePages(const LoadCallback& callback) override; | 61 void GetOfflinePages(const LoadCallback& callback) override; |
| 38 void AddOrUpdateOfflinePage(const OfflinePageItem& offline_page, | 62 void AddOrUpdateOfflinePage(const OfflinePageItem& offline_page, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 68 StoreState state_; | 92 StoreState state_; |
| 69 | 93 |
| 70 base::WeakPtrFactory<OfflinePageMetadataStoreSQL> weak_ptr_factory_; | 94 base::WeakPtrFactory<OfflinePageMetadataStoreSQL> weak_ptr_factory_; |
| 71 | 95 |
| 72 DISALLOW_COPY_AND_ASSIGN(OfflinePageMetadataStoreSQL); | 96 DISALLOW_COPY_AND_ASSIGN(OfflinePageMetadataStoreSQL); |
| 73 }; | 97 }; |
| 74 | 98 |
| 75 } // namespace offline_pages | 99 } // namespace offline_pages |
| 76 | 100 |
| 77 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_SQL_H_ | 101 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_SQL_H_ |
| OLD | NEW |