OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_SYNC_GLUE_TYPED_URL_CHANGE_PROCESSOR_H_ | 5 #ifndef CHROME_BROWSER_SYNC_GLUE_TYPED_URL_CHANGE_PROCESSOR_H_ |
6 #define CHROME_BROWSER_SYNC_GLUE_TYPED_URL_CHANGE_PROCESSOR_H_ | 6 #define CHROME_BROWSER_SYNC_GLUE_TYPED_URL_CHANGE_PROCESSOR_H_ |
7 | 7 |
8 #include "components/sync_driver/change_processor.h" | 8 #include "components/sync_driver/change_processor.h" |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "chrome/browser/sync/glue/sync_backend_host.h" | 13 #include "chrome/browser/sync/glue/sync_backend_host.h" |
14 #include "chrome/browser/sync/glue/typed_url_model_associator.h" | 14 #include "chrome/browser/sync/glue/typed_url_model_associator.h" |
| 15 #include "components/history/core/browser/history_backend_observer.h" |
15 #include "components/sync_driver/data_type_error_handler.h" | 16 #include "components/sync_driver/data_type_error_handler.h" |
16 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
17 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
18 #include "content/public/browser/notification_types.h" | 19 #include "content/public/browser/notification_types.h" |
19 | 20 |
20 class Profile; | 21 class Profile; |
21 | 22 |
22 namespace base { | 23 namespace base { |
23 class MessageLoop; | 24 class MessageLoop; |
24 } | 25 } |
(...skipping 11 matching lines...) Expand all Loading... |
36 }; | 37 }; |
37 | 38 |
38 namespace browser_sync { | 39 namespace browser_sync { |
39 | 40 |
40 class DataTypeErrorHandler; | 41 class DataTypeErrorHandler; |
41 | 42 |
42 // This class is responsible for taking changes from the history backend and | 43 // This class is responsible for taking changes from the history backend and |
43 // applying them to the sync API 'syncable' model, and vice versa. All | 44 // applying them to the sync API 'syncable' model, and vice versa. All |
44 // operations and use of this class are from the UI thread. | 45 // operations and use of this class are from the UI thread. |
45 class TypedUrlChangeProcessor : public sync_driver::ChangeProcessor, | 46 class TypedUrlChangeProcessor : public sync_driver::ChangeProcessor, |
46 public content::NotificationObserver { | 47 public content::NotificationObserver, |
| 48 public history::HistoryBackendObserver { |
47 public: | 49 public: |
48 TypedUrlChangeProcessor(Profile* profile, | 50 TypedUrlChangeProcessor(Profile* profile, |
49 TypedUrlModelAssociator* model_associator, | 51 TypedUrlModelAssociator* model_associator, |
50 history::HistoryBackend* history_backend, | 52 history::HistoryBackend* history_backend, |
51 sync_driver::DataTypeErrorHandler* error_handler); | 53 sync_driver::DataTypeErrorHandler* error_handler); |
52 virtual ~TypedUrlChangeProcessor(); | 54 virtual ~TypedUrlChangeProcessor(); |
53 | 55 |
54 // content::NotificationObserver implementation. | 56 // content::NotificationObserver implementation. |
55 // History -> sync API change application. | 57 // History -> sync API change application. |
56 virtual void Observe(int type, | 58 virtual void Observe(int type, |
57 const content::NotificationSource& source, | 59 const content::NotificationSource& source, |
58 const content::NotificationDetails& details) override; | 60 const content::NotificationDetails& details) override; |
59 | 61 |
| 62 // history::HistoryBackendObserver: |
| 63 virtual void OnURLVisited(history::HistoryBackend* history_backend, |
| 64 ui::PageTransition transition, |
| 65 const history::URLRow& row, |
| 66 const history::RedirectList& redirects, |
| 67 base::Time visit_time) override; |
| 68 |
60 // sync API model -> WebDataService change application. | 69 // sync API model -> WebDataService change application. |
61 virtual void ApplyChangesFromSyncModel( | 70 virtual void ApplyChangesFromSyncModel( |
62 const syncer::BaseTransaction* trans, | 71 const syncer::BaseTransaction* trans, |
63 int64 model_version, | 72 int64 model_version, |
64 const syncer::ImmutableChangeRecordList& changes) override; | 73 const syncer::ImmutableChangeRecordList& changes) override; |
65 | 74 |
66 // Commit changes here, after we've released the transaction lock to avoid | 75 // Commit changes here, after we've released the transaction lock to avoid |
67 // jank. | 76 // jank. |
68 virtual void CommitChangesFromSyncModel() override; | 77 virtual void CommitChangesFromSyncModel() override; |
69 | 78 |
70 // Stop processing changes and wait for being destroyed. | 79 // Stop processing changes and wait for being destroyed. |
71 void Disconnect(); | 80 void Disconnect(); |
72 | 81 |
73 protected: | 82 protected: |
74 virtual void StartImpl() override; | 83 virtual void StartImpl() override; |
75 | 84 |
76 private: | 85 private: |
77 friend class ScopedStopObserving<TypedUrlChangeProcessor>; | 86 friend class ScopedStopObserving<TypedUrlChangeProcessor>; |
78 void StartObserving(); | 87 void StartObserving(); |
79 void StopObserving(); | 88 void StopObserving(); |
80 | 89 |
81 void HandleURLsModified(history::URLsModifiedDetails* details); | 90 void HandleURLsModified(history::URLsModifiedDetails* details); |
82 void HandleURLsDeleted(history::URLsDeletedDetails* details); | 91 void HandleURLsDeleted(history::URLsDeletedDetails* details); |
83 void HandleURLsVisited(history::URLVisitedDetails* details); | |
84 | 92 |
85 // Returns true if the caller should sync as a result of the passed visit | 93 // Returns true if the caller should sync as a result of the passed visit |
86 // notification. We use this to throttle the number of sync changes we send | 94 // notification. We use this to throttle the number of sync changes we send |
87 // to the server so we don't hit the server for every | 95 // to the server so we don't hit the server for every |
88 // single typed URL visit. | 96 // single typed URL visit. |
89 bool ShouldSyncVisit(history::URLVisitedDetails* details); | 97 bool ShouldSyncVisit(int typed_count, ui::PageTransition transition); |
90 | 98 |
91 // Utility routine that either updates an existing sync node or creates a | 99 // Utility routine that either updates an existing sync node or creates a |
92 // new one for the passed |typed_url| if one does not already exist. Returns | 100 // new one for the passed |typed_url| if one does not already exist. Returns |
93 // false and sets an unrecoverable error if the operation failed. | 101 // false and sets an unrecoverable error if the operation failed. |
94 bool CreateOrUpdateSyncNode(history::URLRow typed_url, | 102 bool CreateOrUpdateSyncNode(history::URLRow typed_url, |
95 syncer::WriteTransaction* transaction); | 103 syncer::WriteTransaction* transaction); |
96 | 104 |
97 // The profile with which we are associated. | 105 // The profile with which we are associated. |
98 Profile* profile_; | 106 Profile* profile_; |
99 | 107 |
(...skipping 20 matching lines...) Expand all Loading... |
120 | 128 |
121 bool disconnected_; | 129 bool disconnected_; |
122 base::Lock disconnect_lock_; | 130 base::Lock disconnect_lock_; |
123 | 131 |
124 DISALLOW_COPY_AND_ASSIGN(TypedUrlChangeProcessor); | 132 DISALLOW_COPY_AND_ASSIGN(TypedUrlChangeProcessor); |
125 }; | 133 }; |
126 | 134 |
127 } // namespace browser_sync | 135 } // namespace browser_sync |
128 | 136 |
129 #endif // CHROME_BROWSER_SYNC_GLUE_TYPED_URL_CHANGE_PROCESSOR_H_ | 137 #endif // CHROME_BROWSER_SYNC_GLUE_TYPED_URL_CHANGE_PROCESSOR_H_ |
OLD | NEW |