summaryrefslogtreecommitdiffstats
path: root/chrome/browser/sync/glue/session_change_processor.h
blob: 62134434a455d1606d1f021ae896eef495ada749 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_SYNC_GLUE_SESSION_CHANGE_PROCESSOR_H_
#define CHROME_BROWSER_SYNC_GLUE_SESSION_CHANGE_PROCESSOR_H_
#pragma once

#include "base/basictypes.h"
#include "chrome/browser/sessions/session_backend.h"
#include "chrome/browser/sessions/session_service.h"
#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/glue/change_processor.h"
#include "content/common/notification_observer.h"
#include "content/common/notification_registrar.h"
#include "content/common/notification_type.h"

class NotificationDetails;
class NotificationSource;
class Profile;

namespace browser_sync {

class SessionModelAssociator;
class UnrecoverableErrorHandler;

// This class is responsible for taking changes from the
// SessionService and applying them to the sync_api 'syncable'
// model, and vice versa. All operations and use of this class are
// from the UI thread.
class SessionChangeProcessor : public ChangeProcessor,
                               public NotificationObserver {
 public:
  // Does not take ownership of either argument.
  SessionChangeProcessor(
      UnrecoverableErrorHandler* error_handler,
      SessionModelAssociator* session_model_associator);
  SessionChangeProcessor(
      UnrecoverableErrorHandler* error_handler,
      SessionModelAssociator* session_model_associator,
      bool setup_for_test);
  virtual ~SessionChangeProcessor();

  // NotificationObserver implementation.
  // BrowserSessionProvider -> sync_api model change application.
  virtual void Observe(NotificationType type,
                       const NotificationSource& source,
                       const NotificationDetails& details);

  // ChangeProcessor implementation.
  // sync_api model -> BrowserSessionProvider change application.
  virtual void ApplyChangesFromSyncModel(
      const sync_api::BaseTransaction* trans,
      const sync_api::SyncManager::ChangeRecord* changes,
      int change_count);

 protected:
  // ChangeProcessor implementation.
  virtual void StartImpl(Profile* profile);
  virtual void StopImpl();
 private:
  void StartObserving();
  void StopObserving();
  SessionModelAssociator* session_model_associator_;
  NotificationRegistrar notification_registrar_;

  // Owner of the SessionService.  Non-NULL iff |running()| is true.
  Profile* profile_;

  // To bypass some checks/codepaths not applicable in tests.
  bool setup_for_test_;

  DISALLOW_COPY_AND_ASSIGN(SessionChangeProcessor);
};

}  // namespace browser_sync

#endif  // CHROME_BROWSER_SYNC_GLUE_SESSION_CHANGE_PROCESSOR_H_