• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_EXTENSION_CHANGE_PROCESSOR_H_
6 #define CHROME_BROWSER_SYNC_GLUE_EXTENSION_CHANGE_PROCESSOR_H_
7 #pragma once
8 
9 #include "base/basictypes.h"
10 #include "chrome/browser/sync/engine/syncapi.h"
11 #include "chrome/browser/sync/glue/change_processor.h"
12 #include "chrome/browser/sync/glue/extension_sync_traits.h"
13 #include "content/common/notification_observer.h"
14 #include "content/common/notification_registrar.h"
15 #include "content/common/notification_type.h"
16 
17 class ExtensionServiceInterface;
18 
19 namespace browser_sync {
20 
21 class UnrecoverableErrorHandler;
22 
23 // This class is responsible for taking changes from the
24 // ExtensionService and applying them to the sync_api 'syncable'
25 // model, and vice versa. All operations and use of this class are
26 // from the UI thread.
27 class ExtensionChangeProcessor : public ChangeProcessor,
28                                  public NotificationObserver {
29  public:
30   // Does not take ownership of |error_handler|.
31   ExtensionChangeProcessor(
32       const ExtensionSyncTraits& traits,
33       UnrecoverableErrorHandler* error_handler);
34   virtual ~ExtensionChangeProcessor();
35 
36   // NotificationObserver implementation.
37   // BrowserExtensionProvider -> sync_api model change application.
38   virtual void Observe(NotificationType type,
39                        const NotificationSource& source,
40                        const NotificationDetails& details);
41 
42   // ChangeProcessor implementation.
43   // sync_api model -> BrowserExtensionProvider change application.
44   virtual void ApplyChangesFromSyncModel(
45       const sync_api::BaseTransaction* trans,
46       const sync_api::SyncManager::ChangeRecord* changes,
47       int change_count);
48 
49  protected:
50   // ChangeProcessor implementation.
51   virtual void StartImpl(Profile* profile);
52   virtual void StopImpl();
53 
54  private:
55   void StartObserving();
56   void StopObserving();
57 
58   NotificationRegistrar notification_registrar_;
59   const ExtensionSyncTraits traits_;
60 
61   // Non-NULL iff |running()| is true.
62   Profile* profile_;
63   ExtensionServiceInterface* extension_service_;
64   sync_api::UserShare* user_share_;
65 
66   DISALLOW_COPY_AND_ASSIGN(ExtensionChangeProcessor);
67 };
68 
69 }  // namespace browser_sync
70 
71 #endif  // CHROME_BROWSER_SYNC_GLUE_EXTENSION_CHANGE_PROCESSOR_H_
72