Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_DOM_DISTILLER_CORE_DOM_DISTILLER_STORE_H_ | 5 #ifndef COMPONENTS_DOM_DISTILLER_CORE_DOM_DISTILLER_STORE_H_ |
| 6 #define COMPONENTS_DOM_DISTILLER_CORE_DOM_DISTILLER_STORE_H_ | 6 #define COMPONENTS_DOM_DISTILLER_CORE_DOM_DISTILLER_STORE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
| 14 #include "components/dom_distiller/core/article_attachments_data.h" | |
| 14 #include "components/dom_distiller/core/article_entry.h" | 15 #include "components/dom_distiller/core/article_entry.h" |
| 15 #include "components/dom_distiller/core/dom_distiller_model.h" | 16 #include "components/dom_distiller/core/dom_distiller_model.h" |
| 16 #include "components/dom_distiller/core/dom_distiller_observer.h" | 17 #include "components/dom_distiller/core/dom_distiller_observer.h" |
| 17 #include "components/leveldb_proto/proto_database.h" | 18 #include "components/leveldb_proto/proto_database.h" |
| 18 #include "sync/api/sync_change.h" | 19 #include "sync/api/sync_change.h" |
| 19 #include "sync/api/sync_data.h" | 20 #include "sync/api/sync_data.h" |
| 20 #include "sync/api/sync_error.h" | 21 #include "sync/api/sync_error.h" |
| 21 #include "sync/api/sync_error_factory.h" | 22 #include "sync/api/sync_error_factory.h" |
| 22 #include "sync/api/sync_merge_result.h" | 23 #include "sync/api/sync_merge_result.h" |
| 23 #include "sync/api/syncable_service.h" | 24 #include "sync/api/syncable_service.h" |
| 24 #include "url/gurl.h" | 25 #include "url/gurl.h" |
| 25 | 26 |
| 26 namespace base { | 27 namespace base { |
| 27 class FilePath; | 28 class FilePath; |
| 28 } | 29 } |
| 29 | 30 |
| 31 namespace syncer { | |
| 32 class AttachmentStore; | |
| 33 } | |
| 34 | |
| 30 namespace dom_distiller { | 35 namespace dom_distiller { |
| 31 | 36 |
| 32 // Interface for accessing the stored/synced DomDistiller entries. | 37 // Interface for accessing the stored/synced DomDistiller entries. |
| 33 class DomDistillerStoreInterface { | 38 class DomDistillerStoreInterface { |
| 34 public: | 39 public: |
| 35 virtual ~DomDistillerStoreInterface() {} | 40 virtual ~DomDistillerStoreInterface() {} |
| 36 | 41 |
| 37 // Gets the syncable service for this store or null if it is not synced. | 42 // Gets the syncable service for this store or null if it is not synced. |
| 38 virtual syncer::SyncableService* GetSyncableService() = 0; | 43 virtual syncer::SyncableService* GetSyncableService() = 0; |
| 39 | 44 |
| 40 virtual bool AddEntry(const ArticleEntry& entry) = 0; | 45 virtual bool AddEntry(const ArticleEntry& entry) = 0; |
| 41 | |
|
maniscalco
2014/11/12 18:59:44
Accidental line removal?
cjhopman
2014/11/14 02:45:15
Done. pulled the line removal into different chang
| |
| 42 // Returns false if |entry| is not present or |entry| was not updated. | 46 // Returns false if |entry| is not present or |entry| was not updated. |
| 43 virtual bool UpdateEntry(const ArticleEntry& entry) = 0; | 47 virtual bool UpdateEntry(const ArticleEntry& entry) = 0; |
| 48 virtual bool RemoveEntry(const ArticleEntry& entry) = 0; | |
| 44 | 49 |
| 45 virtual bool RemoveEntry(const ArticleEntry& entry) = 0; | 50 // Updates the attachments for an entry. |
| 51 typedef base::Callback<void(bool)> | |
|
maniscalco
2014/11/12 18:59:44
What does the bool indicate?
cjhopman
2014/11/14 02:45:15
Done. added names here and documentation to the fu
| |
| 52 UpdateAttachmentsCallback; | |
| 53 typedef base::Callback<void(bool, scoped_ptr<ArticleAttachmentsData>)> | |
| 54 GetAttachmentsCallback; | |
| 55 virtual void UpdateAttachments( | |
| 56 const std::string& entry_id, | |
| 57 scoped_ptr<ArticleAttachmentsData> attachments, | |
| 58 UpdateAttachmentsCallback callback) = 0; | |
| 59 virtual void GetAttachments(const std::string& entry_id, | |
| 60 GetAttachmentsCallback callback) = 0; | |
| 46 | 61 |
| 47 // Lookup an ArticleEntry by ID or URL. Returns whether a corresponding entry | 62 // Lookup an ArticleEntry by ID or URL. Returns whether a corresponding entry |
| 48 // was found. On success, if |entry| is not null, it will contain the entry. | 63 // was found. On success, if |entry| is not null, it will contain the entry. |
| 49 virtual bool GetEntryById(const std::string& entry_id, | 64 virtual bool GetEntryById(const std::string& entry_id, |
| 50 ArticleEntry* entry) = 0; | 65 ArticleEntry* entry) = 0; |
| 51 virtual bool GetEntryByUrl(const GURL& url, ArticleEntry* entry) = 0; | 66 virtual bool GetEntryByUrl(const GURL& url, ArticleEntry* entry) = 0; |
| 52 | 67 |
| 53 // Gets a copy of all the current entries. | 68 // Gets a copy of all the current entries. |
| 54 virtual std::vector<ArticleEntry> GetEntries() const = 0; | 69 virtual std::vector<ArticleEntry> GetEntries() const = 0; |
| 55 | 70 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 // |initial_model|. | 104 // |initial_model|. |
| 90 DomDistillerStore( | 105 DomDistillerStore( |
| 91 scoped_ptr<leveldb_proto::ProtoDatabase<ArticleEntry> > database, | 106 scoped_ptr<leveldb_proto::ProtoDatabase<ArticleEntry> > database, |
| 92 const std::vector<ArticleEntry>& initial_data, | 107 const std::vector<ArticleEntry>& initial_data, |
| 93 const base::FilePath& database_dir); | 108 const base::FilePath& database_dir); |
| 94 | 109 |
| 95 ~DomDistillerStore() override; | 110 ~DomDistillerStore() override; |
| 96 | 111 |
| 97 // DomDistillerStoreInterface implementation. | 112 // DomDistillerStoreInterface implementation. |
| 98 syncer::SyncableService* GetSyncableService() override; | 113 syncer::SyncableService* GetSyncableService() override; |
| 114 | |
| 99 bool AddEntry(const ArticleEntry& entry) override; | 115 bool AddEntry(const ArticleEntry& entry) override; |
| 100 bool UpdateEntry(const ArticleEntry& entry) override; | 116 bool UpdateEntry(const ArticleEntry& entry) override; |
| 101 bool RemoveEntry(const ArticleEntry& entry) override; | 117 bool RemoveEntry(const ArticleEntry& entry) override; |
| 118 | |
| 119 virtual void UpdateAttachments( | |
| 120 const std::string& entry_id, | |
| 121 scoped_ptr<ArticleAttachmentsData> attachments_data, | |
| 122 UpdateAttachmentsCallback callback) override; | |
| 123 virtual void GetAttachments(const std::string& entry_id, | |
| 124 GetAttachmentsCallback callback) override; | |
| 125 | |
| 102 bool GetEntryById(const std::string& entry_id, ArticleEntry* entry) override; | 126 bool GetEntryById(const std::string& entry_id, ArticleEntry* entry) override; |
| 103 bool GetEntryByUrl(const GURL& url, ArticleEntry* entry) override; | 127 bool GetEntryByUrl(const GURL& url, ArticleEntry* entry) override; |
| 104 std::vector<ArticleEntry> GetEntries() const override; | 128 std::vector<ArticleEntry> GetEntries() const override; |
| 129 | |
| 105 void AddObserver(DomDistillerObserver* observer) override; | 130 void AddObserver(DomDistillerObserver* observer) override; |
| 106 void RemoveObserver(DomDistillerObserver* observer) override; | 131 void RemoveObserver(DomDistillerObserver* observer) override; |
| 107 | 132 |
| 108 // syncer::SyncableService implementation. | 133 // syncer::SyncableService implementation. |
| 109 syncer::SyncMergeResult MergeDataAndStartSyncing( | 134 syncer::SyncMergeResult MergeDataAndStartSyncing( |
| 110 syncer::ModelType type, | 135 syncer::ModelType type, |
| 111 const syncer::SyncDataList& initial_sync_data, | 136 const syncer::SyncDataList& initial_sync_data, |
| 112 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, | 137 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |
| 113 scoped_ptr<syncer::SyncErrorFactory> error_handler) override; | 138 scoped_ptr<syncer::SyncErrorFactory> error_handler) override; |
| 114 void StopSyncing(syncer::ModelType type) override; | 139 void StopSyncing(syncer::ModelType type) override; |
| 115 syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const override; | 140 syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const override; |
| 116 syncer::SyncError ProcessSyncChanges( | 141 syncer::SyncError ProcessSyncChanges( |
| 117 const tracked_objects::Location& from_here, | 142 const tracked_objects::Location& from_here, |
| 118 const syncer::SyncChangeList& change_list) override; | 143 const syncer::SyncChangeList& change_list) override; |
| 119 | 144 |
| 120 private: | 145 private: |
| 121 void OnDatabaseInit(bool success); | 146 void OnDatabaseInit(bool success); |
| 122 void OnDatabaseLoad(bool success, scoped_ptr<EntryVector> entries); | 147 void OnDatabaseLoad(bool success, scoped_ptr<EntryVector> entries); |
| 123 void OnDatabaseSave(bool success); | 148 void OnDatabaseSave(bool success); |
| 124 | 149 |
| 125 bool ChangeEntry(const ArticleEntry& entry, | 150 bool ChangeEntry(const ArticleEntry& entry, |
| 126 syncer::SyncChange::SyncChangeType changeType); | 151 syncer::SyncChange::SyncChangeType changeType); |
| 127 | 152 |
| 153 void OnAttachmentsWrite( | |
| 154 const std::string& entry_id, | |
| 155 scoped_ptr<sync_pb::ArticleAttachments> article_attachments, | |
| 156 UpdateAttachmentsCallback callback, | |
| 157 const syncer::AttachmentStore::Result& result); | |
| 158 | |
| 159 void OnAttachmentsRead(const sync_pb::ArticleAttachments& attachments_proto, | |
| 160 GetAttachmentsCallback callback, | |
| 161 const syncer::AttachmentStore::Result& result, | |
| 162 scoped_ptr<syncer::AttachmentMap> attachments, | |
| 163 scoped_ptr<syncer::AttachmentIdList> missing); | |
| 164 | |
| 128 syncer::SyncMergeResult MergeDataWithModel( | 165 syncer::SyncMergeResult MergeDataWithModel( |
| 129 const syncer::SyncDataList& data, syncer::SyncChangeList* changes_applied, | 166 const syncer::SyncDataList& data, syncer::SyncChangeList* changes_applied, |
| 130 syncer::SyncChangeList* changes_missing); | 167 syncer::SyncChangeList* changes_missing); |
| 131 | 168 |
| 132 // Convert a SyncDataList to a SyncChangeList of add or update changes based | 169 // Convert a SyncDataList to a SyncChangeList of add or update changes based |
| 133 // on the state of the in-memory model. Also calculate the entries missing | 170 // on the state of the in-memory model. Also calculate the entries missing |
| 134 // from the SyncDataList. | 171 // from the SyncDataList. |
| 135 void CalculateChangesForMerge(const syncer::SyncDataList& data, | 172 void CalculateChangesForMerge(const syncer::SyncDataList& data, |
| 136 syncer::SyncChangeList* changes_to_apply, | 173 syncer::SyncChangeList* changes_to_apply, |
| 137 syncer::SyncChangeList* changes_missing); | 174 syncer::SyncChangeList* changes_missing); |
| 138 | 175 |
| 139 bool ApplyChangesToSync(const tracked_objects::Location& from_here, | 176 bool ApplyChangesToSync(const tracked_objects::Location& from_here, |
| 140 const syncer::SyncChangeList& change_list); | 177 const syncer::SyncChangeList& change_list); |
| 141 bool ApplyChangesToDatabase(const syncer::SyncChangeList& change_list); | 178 bool ApplyChangesToDatabase(const syncer::SyncChangeList& change_list); |
| 142 | 179 |
| 143 // Applies the changes to |model_|. If the model returns an error, disables | 180 // Applies the changes to |model_|. If the model returns an error, disables |
| 144 // syncing and database changes and returns false. | 181 // syncing and database changes and returns false. |
| 145 void ApplyChangesToModel(const syncer::SyncChangeList& change_list, | 182 void ApplyChangesToModel(const syncer::SyncChangeList& change_list, |
| 146 syncer::SyncChangeList* changes_applied, | 183 syncer::SyncChangeList* changes_applied, |
| 147 syncer::SyncChangeList* changes_missing); | 184 syncer::SyncChangeList* changes_missing); |
| 148 | 185 |
| 149 void NotifyObservers(const syncer::SyncChangeList& changes); | 186 void NotifyObservers(const syncer::SyncChangeList& changes); |
| 150 | 187 |
| 151 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; | 188 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; |
| 152 scoped_ptr<syncer::SyncErrorFactory> error_factory_; | 189 scoped_ptr<syncer::SyncErrorFactory> error_factory_; |
| 153 scoped_ptr<leveldb_proto::ProtoDatabase<ArticleEntry> > database_; | 190 scoped_ptr<leveldb_proto::ProtoDatabase<ArticleEntry> > database_; |
| 154 bool database_loaded_; | 191 bool database_loaded_; |
| 192 scoped_refptr<syncer::AttachmentStore> attachment_store_; | |
| 155 ObserverList<DomDistillerObserver> observers_; | 193 ObserverList<DomDistillerObserver> observers_; |
| 156 | 194 |
| 157 DomDistillerModel model_; | 195 DomDistillerModel model_; |
| 158 | 196 |
| 159 base::WeakPtrFactory<DomDistillerStore> weak_ptr_factory_; | 197 base::WeakPtrFactory<DomDistillerStore> weak_ptr_factory_; |
| 160 | 198 |
| 161 DISALLOW_COPY_AND_ASSIGN(DomDistillerStore); | 199 DISALLOW_COPY_AND_ASSIGN(DomDistillerStore); |
| 162 }; | 200 }; |
| 163 | 201 |
| 164 } // namespace dom_distiller | 202 } // namespace dom_distiller |
| 165 | 203 |
| 166 #endif // COMPONENTS_DOM_DISTILLER_CORE_DOM_DISTILLER_STORE_H_ | 204 #endif // COMPONENTS_DOM_DISTILLER_CORE_DOM_DISTILLER_STORE_H_ |
| OLD | NEW |