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

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

Issue 2961723003: [USS] Implement ApplySyncChanges and OnURLVisited/Modified/Deleted. (Closed)
Patch Set: Created 3 years, 5 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 "base/scoped_observer.h"
9 #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" 10 #include "components/history/core/browser/typed_url_sync_metadata_database.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 // to the history DB. 95 // to the history DB.
96 // DIFF_LOCAL_VISITS_ADDED - |new_visits| contains a list of visits that 96 // DIFF_LOCAL_VISITS_ADDED - |new_visits| contains a list of visits that
97 // should be written to the history DB for this URL. Deletions are not 97 // should be written to the history DB for this URL. Deletions are not
98 // written to the DB - each client is left to age out visits on their own. 98 // written to the DB - each client is left to age out visits on their own.
99 static MergeResult MergeUrls(const sync_pb::TypedUrlSpecifics& typed_url, 99 static MergeResult MergeUrls(const sync_pb::TypedUrlSpecifics& typed_url,
100 const history::URLRow& url, 100 const history::URLRow& url,
101 history::VisitVector* visits, 101 history::VisitVector* visits,
102 history::URLRow* new_url, 102 history::URLRow* new_url,
103 std::vector<history::VisitInfo>* new_visits); 103 std::vector<history::VisitInfo>* new_visits);
104 104
105 // Diffs the set of visits between the history DB and the sync DB, using the
106 // sync DB as the canonical copy. Result is the set of |new_visits| and
107 // |removed_visits| that can be applied to the history DB to make it match
108 // the sync DB version. |removed_visits| can be null if the caller does not
109 // care about which visits to remove.
110 static void DiffVisits(const history::VisitVector& history_visits,
111 const sync_pb::TypedUrlSpecifics& sync_specifics,
112 std::vector<history::VisitInfo>* new_visits,
113 history::VisitVector* removed_visits);
114
105 // Fills |new_url| with formatted data from |typed_url|. 115 // Fills |new_url| with formatted data from |typed_url|.
106 static void UpdateURLRowFromTypedUrlSpecifics( 116 static void UpdateURLRowFromTypedUrlSpecifics(
107 const sync_pb::TypedUrlSpecifics& typed_url, 117 const sync_pb::TypedUrlSpecifics& typed_url,
108 history::URLRow* new_url); 118 history::URLRow* new_url);
109 119
110 // Synchronously load sync metadata from the TypedURLSyncMetadataDatabase and 120 // Synchronously load sync metadata from the TypedURLSyncMetadataDatabase and
111 // pass it to the processor so that it can start tracking changes. 121 // pass it to the processor so that it can start tracking changes.
112 void LoadMetadata(); 122 void LoadMetadata();
113 123
114 // Helper function that clears our error counters (used to reset stats after 124 // Helper function that clears our error counters (used to reset stats after
115 // merge so we can track merge errors separately). 125 // merge so we can track merge errors separately).
116 void ClearErrorStats(); 126 void ClearErrorStats();
117 127
118 // Compares |server_typed_url| from the server against local history to decide 128 // Compares |server_typed_url| from the server against local history to decide
119 // how to merge any existing data, and updates appropriate data containers to 129 // how to merge any existing data, and updates appropriate data containers to
120 // write to server and backend. 130 // write to server and backend.
121 void UpdateUrlFromServer(const sync_pb::TypedUrlSpecifics& server_typed_url, 131 void MergeURLWithSync(const sync_pb::TypedUrlSpecifics& server_typed_url,
122 TypedURLMap* local_typed_urls, 132 TypedURLMap* local_typed_urls,
123 URLVisitVectorMap* visit_vectors, 133 URLVisitVectorMap* visit_vectors,
124 history::URLRows* new_synced_urls, 134 history::URLRows* new_synced_urls,
125 TypedURLVisitVector* new_synced_visits, 135 TypedURLVisitVector* new_synced_visits,
126 history::URLRows* updated_synced_urls); 136 history::URLRows* updated_synced_urls);
137
138 // Given a typed URL in the sync DB, looks for an existing entry in the
139 // local history DB and generates a list of visits to add to the
140 // history DB to bring it up to date (avoiding duplicates).
141 // Updates the passed |visits_to_add| and |visits_to_remove| vectors with the
142 // visits to add to/remove from the history DB, and adds a new entry to either
143 // |updated_urls| or |new_urls| depending on whether the URL already existed
144 // in the history DB.
145 void UpdateFromSync(const sync_pb::TypedUrlSpecifics& typed_url,
146 TypedURLVisitVector* visits_to_add,
147 history::VisitVector* visits_to_remove,
148 history::URLRows* updated_urls,
149 history::URLRows* new_urls);
150
151 // Utility routine that either updates an existing sync node or creates a
152 // new one for the passed |typed_url| if one does not already exist. Returns
153 // false and sets an unrecoverable error if the operation failed.
pavely 2017/07/06 19:28:29 I don't think it sets unrecoverable error anymore.
Gang Wu 2017/07/10 19:53:25 Done.
154 bool UpdateSyncFromLocal(URLRow typed_url,
155 syncer::MetadataChangeList* metadata_change_list);
pavely 2017/07/06 19:28:29 I don't think callers check return value of this f
Gang Wu 2017/07/10 19:53:25 Done.
127 156
128 // Writes new typed url data from sync server to history backend. 157 // Writes new typed url data from sync server to history backend.
129 base::Optional<syncer::ModelError> WriteToHistoryBackend( 158 base::Optional<syncer::ModelError> WriteToHistoryBackend(
130 const history::URLRows* new_urls, 159 const history::URLRows* new_urls,
131 const history::URLRows* updated_urls, 160 const history::URLRows* updated_urls,
132 const std::vector<GURL>* deleted_urls, 161 const std::vector<GURL>* deleted_urls,
133 const TypedURLVisitVector* new_visits, 162 const TypedURLVisitVector* new_visits,
134 const history::VisitVector* deleted_visits); 163 const history::VisitVector* deleted_visits);
135 164
136 // Given a TypedUrlSpecifics object, removes all visits that are older than 165 // Given a TypedUrlSpecifics object, removes all visits that are older than
137 // the current expiration time. Note that this can result in having no visits 166 // the current expiration time. Note that this can result in having no visits
138 // at all. 167 // at all.
139 sync_pb::TypedUrlSpecifics FilterExpiredVisits( 168 sync_pb::TypedUrlSpecifics FilterExpiredVisits(
140 const sync_pb::TypedUrlSpecifics& specifics); 169 const sync_pb::TypedUrlSpecifics& specifics);
141 170
142 // Helper function that determines if we should ignore a URL for the purposes 171 // Helper function that determines if we should ignore a URL for the purposes
143 // of sync, because it contains invalid data. 172 // of sync, because it contains invalid data.
144 bool ShouldIgnoreUrl(const GURL& url); 173 bool ShouldIgnoreUrl(const GURL& url);
145 174
146 // Helper function that determines if we should ignore a URL for the purposes 175 // Helper function that determines if we should ignore a URL for the purposes
147 // of sync, based on the visits the URL had. 176 // of sync, based on the visits the URL had.
148 bool ShouldIgnoreVisits(const history::VisitVector& visits); 177 bool ShouldIgnoreVisits(const history::VisitVector& visits);
149 178
179 // Returns true if the caller should sync as a result of the passed visit
180 // notification. We use this to throttle the number of sync changes we send
181 // to the server so we don't hit the server for every
182 // single typed URL visit.
183 bool ShouldSyncVisit(int typed_count, ui::PageTransition transition);
184
150 // Fetches visits from the history DB corresponding to the passed URL. This 185 // Fetches visits from the history DB corresponding to the passed URL. This
151 // function compensates for the fact that the history DB has rather poor data 186 // function compensates for the fact that the history DB has rather poor data
152 // integrity (duplicate visits, visit timestamps that don't match the 187 // integrity (duplicate visits, visit timestamps that don't match the
153 // last_visit timestamp, huge data sets that exhaust memory when fetched, 188 // last_visit timestamp, huge data sets that exhaust memory when fetched,
154 // expired visits that are not deleted by |ExpireHistoryBackend|, etc) by 189 // expired visits that are not deleted by |ExpireHistoryBackend|, etc) by
155 // modifying the passed |url| object and |visits| vector. The order of 190 // modifying the passed |url| object and |visits| vector. The order of
156 // |visits| will be from the oldest to the newest order. 191 // |visits| will be from the oldest to the newest order.
157 // Returns false in two cases. 192 // Returns false in two cases.
158 // 1. we could not fetch the visits for the passed URL, DB error. 193 // 1. we could not fetch the visits for the passed URL, DB error.
159 // 2. No visits for the passed url, or all the visits are expired. 194 // 2. No visits for the passed url, or all the visits are expired.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 // backend. 229 // backend.
195 ScopedObserver<history::HistoryBackend, history::HistoryBackendObserver> 230 ScopedObserver<history::HistoryBackend, history::HistoryBackendObserver>
196 history_backend_observer_; 231 history_backend_observer_;
197 232
198 DISALLOW_COPY_AND_ASSIGN(TypedURLSyncBridge); 233 DISALLOW_COPY_AND_ASSIGN(TypedURLSyncBridge);
199 }; 234 };
200 235
201 } // namespace history 236 } // namespace history
202 237
203 #endif // COMPONENTS_HISTORY_CORE_BROWSER_TYPED_URL_SYNC_BRIDGE_H_ 238 #endif // COMPONENTS_HISTORY_CORE_BROWSER_TYPED_URL_SYNC_BRIDGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698