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_THEME_CHANGE_PROCESSOR_H_
6#define CHROME_BROWSER_SYNC_GLUE_THEME_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 "content/common/notification_observer.h"
13#include "content/common/notification_registrar.h"
14#include "content/common/notification_type.h"
15
16class NotificationDetails;
17class NotificationSource;
18class Profile;
19
20namespace browser_sync {
21
22class UnrecoverableErrorHandler;
23
24// This class is responsible for taking changes from the
25// ThemeService and applying them to the sync_api 'syncable'
26// model, and vice versa. All operations and use of this class are
27// from the UI thread.
28class ThemeChangeProcessor : public ChangeProcessor,
29                             public NotificationObserver {
30 public:
31  explicit ThemeChangeProcessor(UnrecoverableErrorHandler* error_handler);
32  virtual ~ThemeChangeProcessor();
33
34  // NotificationObserver implementation.
35  // ThemeService -> sync_api model change application.
36  virtual void Observe(NotificationType type,
37                       const NotificationSource& source,
38                       const NotificationDetails& details);
39
40  // ChangeProcessor implementation.
41  // sync_api model -> ThemeService change application.
42  virtual void ApplyChangesFromSyncModel(
43      const sync_api::BaseTransaction* trans,
44      const sync_api::SyncManager::ChangeRecord* changes,
45      int change_count);
46
47 protected:
48  // ChangeProcessor implementation.
49  virtual void StartImpl(Profile* profile);
50  virtual void StopImpl();
51
52 private:
53  void StartObserving();
54  void StopObserving();
55
56  NotificationRegistrar notification_registrar_;
57  // Profile associated with the ThemeService.  Non-NULL iff |running()| is
58  // true.
59  Profile* profile_;
60
61  DISALLOW_COPY_AND_ASSIGN(ThemeChangeProcessor);
62};
63
64}  // namespace browser_sync
65
66#endif  // CHROME_BROWSER_SYNC_GLUE_THEME_CHANGE_PROCESSOR_H_
67