Home | History | Annotate | Download | only in glue
      1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_SYNC_GLUE_TYPED_URL_CHANGE_PROCESSOR_H_
      6 #define CHROME_BROWSER_SYNC_GLUE_TYPED_URL_CHANGE_PROCESSOR_H_
      7 #pragma once
      8 
      9 #include "chrome/browser/sync/glue/change_processor.h"
     10 
     11 #include "base/basictypes.h"
     12 #include "base/memory/scoped_ptr.h"
     13 #include "base/time.h"
     14 #include "chrome/browser/sync/glue/sync_backend_host.h"
     15 #include "content/common/notification_observer.h"
     16 #include "content/common/notification_registrar.h"
     17 #include "content/common/notification_type.h"
     18 
     19 class MessageLoop;
     20 class NotificationService;
     21 
     22 namespace history {
     23 class HistoryBackend;
     24 struct URLsDeletedDetails;
     25 struct URLsModifiedDetails;
     26 struct URLVisitedDetails;
     27 class URLRow;
     28 };
     29 
     30 namespace browser_sync {
     31 
     32 class TypedUrlModelAssociator;
     33 class UnrecoverableErrorHandler;
     34 
     35 // This class is responsible for taking changes from the history backend and
     36 // applying them to the sync_api 'syncable' model, and vice versa. All
     37 // operations and use of this class are from the UI thread.
     38 class TypedUrlChangeProcessor : public ChangeProcessor,
     39                                 public NotificationObserver {
     40  public:
     41   TypedUrlChangeProcessor(TypedUrlModelAssociator* model_associator,
     42                           history::HistoryBackend* history_backend,
     43                           UnrecoverableErrorHandler* error_handler);
     44   virtual ~TypedUrlChangeProcessor();
     45 
     46   // NotificationObserver implementation.
     47   // History -> sync_api model change application.
     48   virtual void Observe(NotificationType type,
     49                        const NotificationSource& source,
     50                        const NotificationDetails& details);
     51 
     52   // sync_api model -> WebDataService change application.
     53   virtual void ApplyChangesFromSyncModel(
     54       const sync_api::BaseTransaction* trans,
     55       const sync_api::SyncManager::ChangeRecord* changes,
     56       int change_count);
     57 
     58  protected:
     59   virtual void StartImpl(Profile* profile);
     60   virtual void StopImpl();
     61 
     62  private:
     63   void StartObserving();
     64   void StopObserving();
     65 
     66   void HandleURLsModified(history::URLsModifiedDetails* details);
     67   void HandleURLsDeleted(history::URLsDeletedDetails* details);
     68   void HandleURLsVisited(history::URLVisitedDetails* details);
     69 
     70   // The two models should be associated according to this ModelAssociator.
     71   TypedUrlModelAssociator* model_associator_;
     72 
     73   // The model we are processing changes from.  This is owned by the
     74   // WebDataService which is kept alive by our data type controller
     75   // holding a reference.
     76   history::HistoryBackend* history_backend_;
     77 
     78   NotificationRegistrar notification_registrar_;
     79 
     80   bool observing_;
     81 
     82   MessageLoop* expected_loop_;
     83 
     84   scoped_ptr<NotificationService> notification_service_;
     85 
     86   DISALLOW_COPY_AND_ASSIGN(TypedUrlChangeProcessor);
     87 };
     88 
     89 }  // namespace browser_sync
     90 
     91 #endif  // CHROME_BROWSER_SYNC_GLUE_TYPED_URL_CHANGE_PROCESSOR_H_
     92