summaryrefslogtreecommitdiffstats
path: root/sync/notifier/sync_notifier_factory.cc
blob: 10621067d83576c10634315505aa2f63b6101841 (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
// Copyright (c) 2012 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.

#include "sync/notifier/sync_notifier_factory.h"

#include <string>

#include "base/logging.h"
#include "sync/notifier/non_blocking_invalidation_notifier.h"
#include "sync/notifier/p2p_notifier.h"
#include "sync/notifier/sync_notifier.h"

namespace sync_notifier {
namespace {

SyncNotifier* CreateDefaultSyncNotifier(
    const notifier::NotifierOptions& notifier_options,
    const InvalidationVersionMap& initial_max_invalidation_versions,
    const browser_sync::WeakHandle<InvalidationVersionTracker>&
        invalidation_version_tracker,
    const std::string& client_info) {
  if (notifier_options.notification_method == notifier::NOTIFICATION_P2P) {
    // TODO(rlarocque): Ideally, the notification target would be
    // NOTIFY_OTHERS.  There's no good reason to notify ourselves of our own
    // commits.  We self-notify for now only because the integration tests rely
    // on this behaviour.  See crbug.com/97780.
    return new P2PNotifier(notifier_options, NOTIFY_ALL);
  }

  return new NonBlockingInvalidationNotifier(
      notifier_options, initial_max_invalidation_versions,
      invalidation_version_tracker, client_info);
}

}  // namespace

// TODO(akalin): Remove the dependency on jingle if OS_ANDROID is defined.
SyncNotifierFactory::SyncNotifierFactory(
    const notifier::NotifierOptions& notifier_options,
    const std::string& client_info,
    const base::WeakPtr<InvalidationVersionTracker>&
        invalidation_version_tracker)
    : notifier_options_(notifier_options),
      client_info_(client_info),
      initial_max_invalidation_versions_(
          invalidation_version_tracker.get() ?
          invalidation_version_tracker->GetAllMaxVersions() :
          InvalidationVersionMap()),
      invalidation_version_tracker_(invalidation_version_tracker) {
}

SyncNotifierFactory::~SyncNotifierFactory() {
}

SyncNotifier* SyncNotifierFactory::CreateSyncNotifier() {
#if defined(OS_ANDROID)
  // Android uses ChromeSyncNotificationBridge exclusively.
  return NULL;
#else
  return CreateDefaultSyncNotifier(notifier_options_,
                                   initial_max_invalidation_versions_,
                                   invalidation_version_tracker_,
                                   client_info_);
#endif
}
}  // namespace sync_notifier