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

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

Issue 2901093009: [USS] Implement GetAllData and GetStorageKey. (Closed)
Patch Set: add include Created 3 years, 7 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 // Returns the percentage of DB accesses that have resulted in an error.
56 int GetErrorPercentage() const;
57
58 // Return true if this function successfully converts the passed URL
59 // information to a TypedUrlSpecifics structure for writing to the sync DB.
60 static bool WriteToTypedUrlSpecifics(const URLRow& url,
61 const VisitVector& visits,
62 sync_pb::TypedUrlSpecifics* specifics)
63 WARN_UNUSED_RESULT;
64
57 private: 65 private:
66 friend class TypedURLSyncBridgeTest;
67
68 // Synchronously load sync metadata from the TypedURLSyncMetadataDatabase and
69 // pass it to the processor so that it can start tracking changes.
70 void LoadMetadata();
71
72 // Helper function that clears our error counters (used to reset stats after
73 // merge so we can track merge errors separately).
74 void ClearErrorStats();
75
76 // Fetches visits from the history DB corresponding to the passed URL. This
77 // function compensates for the fact that the history DB has rather poor data
78 // integrity (duplicate visits, visit timestamps that don't match the
79 // last_visit timestamp, huge data sets that exhaust memory when fetched,
80 // expired visits that are not deleted by |ExpireHistoryBackend|, etc) by
81 // modifying the passed |url| object and |visits| vector.
82 // Returns false in two cases.
83 // 1. we could not fetch the visits for the passed URL, DB error.
84 // 2. No visits fpr the passed url, or all the visits are expired.
pavely 2017/05/30 14:25:41 fpr => for
Gang Wu 2017/05/31 00:17:32 Done.
85 bool FixupURLAndGetVisits(URLRow* url, VisitVector* visits);
86
87 // Create an EntityData by URL |row| and its visits |visits|.
88 std::unique_ptr<syncer::EntityData> CreateEntityData(
89 const URLRow& row,
90 const VisitVector& visits);
91
58 // A non-owning pointer to the backend, which we're syncing local changes from 92 // A non-owning pointer to the backend, which we're syncing local changes from
59 // and sync changes to. 93 // and sync changes to.
60 HistoryBackend* const history_backend_; 94 HistoryBackend* const history_backend_;
61 95
62 // A non-owning pointer to the database, which is for storing typed urls sync 96 // A non-owning pointer to the database, which is for storing typed urls sync
63 // metadata and state. 97 // metadata and state.
64 syncer::SyncMetadataStore* const sync_metadata_store_; 98 TypedURLSyncMetadataDatabase* const sync_metadata_store_;
99
100 // Statistics for the purposes of tracking the percentage of DB accesses that
101 // fail for each client via UMA.
102 int num_db_accesses_;
103 int num_db_errors_;
65 104
66 // Since HistoryBackend use SequencedTaskRunner, so should use SequenceChecker 105 // Since HistoryBackend use SequencedTaskRunner, so should use SequenceChecker
67 // here. 106 // here.
68 base::SequenceChecker sequence_checker_; 107 base::SequenceChecker sequence_checker_;
69 108
109 // Tracks observed history backend, for receiving updates from history
110 // backend.
111 ScopedObserver<history::HistoryBackend, history::HistoryBackendObserver>
112 history_backend_observer_;
113
70 DISALLOW_COPY_AND_ASSIGN(TypedURLSyncBridge); 114 DISALLOW_COPY_AND_ASSIGN(TypedURLSyncBridge);
71 }; 115 };
72 116
73 } // namespace history 117 } // namespace history
74 118
75 #endif // COMPONENTS_HISTORY_CORE_BROWSER_TYPED_URL_SYNC_BRIDGE_H_ 119 #endif // COMPONENTS_HISTORY_CORE_BROWSER_TYPED_URL_SYNC_BRIDGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698