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

Side by Side Diff: components/history/core/browser/typed_url_sync_bridge.h

Issue 2901093009: [USS] Implement GetAllData and GetStorageKey. (Closed)
Patch Set: brettw review and rebase Created 3 years, 6 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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_HISTORY_CORE_BROWSER_TYPED_URL_SYNC_BRIDGE_H_ 5 #ifndef COMPONENTS_HISTORY_CORE_BROWSER_TYPED_URL_SYNC_BRIDGE_H_
6 #define COMPONENTS_HISTORY_CORE_BROWSER_TYPED_URL_SYNC_BRIDGE_H_ 6 #define COMPONENTS_HISTORY_CORE_BROWSER_TYPED_URL_SYNC_BRIDGE_H_
7 7
8 #include "base/scoped_observer.h"
8 #include "components/history/core/browser/history_backend_observer.h" 9 #include "components/history/core/browser/history_backend_observer.h"
10 #include "components/history/core/browser/typed_url_sync_metadata_database.h"
9 #include "components/sync/model/metadata_change_list.h" 11 #include "components/sync/model/metadata_change_list.h"
10 #include "components/sync/model/model_type_sync_bridge.h" 12 #include "components/sync/model/model_type_sync_bridge.h"
11 #include "components/sync/model/sync_error.h" 13 #include "components/sync/model/sync_error.h"
12 14
13 namespace syncer {
14 class SyncMetadataStore;
15 }
16
17 namespace history { 15 namespace history {
18 16
19 class TypedURLSyncBridge : public syncer::ModelTypeSyncBridge, 17 class TypedURLSyncBridge : public syncer::ModelTypeSyncBridge,
20 public history::HistoryBackendObserver { 18 public history::HistoryBackendObserver {
21 public: 19 public:
22 // |sync_metadata_store| is owned by |history_backend|, and must outlive 20 // |sync_metadata_store| is owned by |history_backend|, and must outlive
23 // TypedURLSyncBridge. 21 // TypedURLSyncBridge.
24 TypedURLSyncBridge(HistoryBackend* history_backend, 22 TypedURLSyncBridge(HistoryBackend* history_backend,
25 syncer::SyncMetadataStore* sync_metadata_store, 23 TypedURLSyncMetadataDatabase* sync_metadata_store,
26 const ChangeProcessorFactory& change_processor_factory); 24 const ChangeProcessorFactory& change_processor_factory);
27 ~TypedURLSyncBridge() override; 25 ~TypedURLSyncBridge() override;
28 26
29 // syncer::ModelTypeService implementation. 27 // syncer::ModelTypeService implementation.
30 std::unique_ptr<syncer::MetadataChangeList> CreateMetadataChangeList() 28 std::unique_ptr<syncer::MetadataChangeList> CreateMetadataChangeList()
31 override; 29 override;
32 base::Optional<syncer::ModelError> MergeSyncData( 30 base::Optional<syncer::ModelError> MergeSyncData(
33 std::unique_ptr<syncer::MetadataChangeList> metadata_change_list, 31 std::unique_ptr<syncer::MetadataChangeList> metadata_change_list,
34 syncer::EntityDataMap entity_data_map) override; 32 syncer::EntityDataMap entity_data_map) override;
35 base::Optional<syncer::ModelError> ApplySyncChanges( 33 base::Optional<syncer::ModelError> ApplySyncChanges(
(...skipping 11 matching lines...) Expand all
47 const history::RedirectList& redirects, 45 const history::RedirectList& redirects,
48 base::Time visit_time) override; 46 base::Time visit_time) override;
49 void OnURLsModified(history::HistoryBackend* history_backend, 47 void OnURLsModified(history::HistoryBackend* history_backend,
50 const history::URLRows& changed_urls) override; 48 const history::URLRows& changed_urls) override;
51 void OnURLsDeleted(history::HistoryBackend* history_backend, 49 void OnURLsDeleted(history::HistoryBackend* history_backend,
52 bool all_history, 50 bool all_history,
53 bool expired, 51 bool expired,
54 const history::URLRows& deleted_rows, 52 const history::URLRows& deleted_rows,
55 const std::set<GURL>& favicon_urls) override; 53 const std::set<GURL>& favicon_urls) override;
56 54
55 // Must be called after creation and before any operations.
56 void Init();
57
58 // Returns the percentage of DB accesses that have resulted in an error.
59 int GetErrorPercentage() const;
60
61 // Return true if this function successfully converts the passed URL
62 // information to a TypedUrlSpecifics structure for writing to the sync DB.
63 static bool WriteToTypedUrlSpecifics(const URLRow& url,
64 const VisitVector& visits,
65 sync_pb::TypedUrlSpecifics* specifics)
66 WARN_UNUSED_RESULT;
67
57 private: 68 private:
69 friend class TypedURLSyncBridgeTest;
70
71 // Synchronously load sync metadata from the TypedURLSyncMetadataDatabase and
72 // pass it to the processor so that it can start tracking changes.
73 void LoadMetadata();
74
75 // Helper function that clears our error counters (used to reset stats after
76 // merge so we can track merge errors separately).
77 void ClearErrorStats();
78
79 // Fetches visits from the history DB corresponding to the passed URL. This
80 // function compensates for the fact that the history DB has rather poor data
81 // integrity (duplicate visits, visit timestamps that don't match the
82 // last_visit timestamp, huge data sets that exhaust memory when fetched,
83 // expired visits that are not deleted by |ExpireHistoryBackend|, etc) by
84 // modifying the passed |url| object and |visits| vector. The order of
85 // |visits| will be from the oldest to the newest order.
86 // Returns false in two cases.
87 // 1. we could not fetch the visits for the passed URL, DB error.
88 // 2. No visits for the passed url, or all the visits are expired.
89 bool FixupURLAndGetVisits(URLRow* url, VisitVector* visits);
90
91 // Create an EntityData by URL |row| and its visits |visits|.
92 std::unique_ptr<syncer::EntityData> CreateEntityData(
93 const URLRow& row,
94 const VisitVector& visits);
95
58 // A non-owning pointer to the backend, which we're syncing local changes from 96 // A non-owning pointer to the backend, which we're syncing local changes from
59 // and sync changes to. 97 // and sync changes to.
60 HistoryBackend* const history_backend_; 98 HistoryBackend* const history_backend_;
61 99
62 // A non-owning pointer to the database, which is for storing typed urls sync 100 // A non-owning pointer to the database, which is for storing typed urls sync
63 // metadata and state. 101 // metadata and state.
64 syncer::SyncMetadataStore* const sync_metadata_store_; 102 TypedURLSyncMetadataDatabase* const sync_metadata_database_;
103
104 // Statistics for the purposes of tracking the percentage of DB accesses that
105 // fail for each client via UMA.
106 int num_db_accesses_;
107 int num_db_errors_;
65 108
66 // Since HistoryBackend use SequencedTaskRunner, so should use SequenceChecker 109 // Since HistoryBackend use SequencedTaskRunner, so should use SequenceChecker
67 // here. 110 // here.
68 base::SequenceChecker sequence_checker_; 111 base::SequenceChecker sequence_checker_;
69 112
113 // Tracks observed history backend, for receiving updates from history
114 // backend.
115 ScopedObserver<history::HistoryBackend, history::HistoryBackendObserver>
116 history_backend_observer_;
117
70 DISALLOW_COPY_AND_ASSIGN(TypedURLSyncBridge); 118 DISALLOW_COPY_AND_ASSIGN(TypedURLSyncBridge);
71 }; 119 };
72 120
73 } // namespace history 121 } // namespace history
74 122
75 #endif // COMPONENTS_HISTORY_CORE_BROWSER_TYPED_URL_SYNC_BRIDGE_H_ 123 #endif // COMPONENTS_HISTORY_CORE_BROWSER_TYPED_URL_SYNC_BRIDGE_H_
OLDNEW
« no previous file with comments | « components/history/core/browser/history_backend.cc ('k') | components/history/core/browser/typed_url_sync_bridge.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698