summaryrefslogtreecommitdiffstats
path: root/sync/sessions/sync_session_context.cc
blob: 2ebe6552e8840109d9c4b86a938528c1699b11b7 (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
79
80
81
82
83
84
85
86
87
// 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/sessions/sync_session_context.h"

#include "sync/sessions/debug_info_getter.h"
#include "sync/sessions/session_state.h"
#include "sync/util/extensions_activity_monitor.h"

namespace browser_sync {
namespace sessions {

const unsigned int kMaxMessagesToRecord = 10;
const unsigned int kMaxMessageSizeToRecord = 5 * 1024;

SyncSessionContext::SyncSessionContext(
    ServerConnectionManager* connection_manager,
    syncable::Directory* directory,
    ModelSafeWorkerRegistrar* model_safe_worker_registrar,
    ExtensionsActivityMonitor* extensions_activity_monitor,
    const std::vector<SyncEngineEventListener*>& listeners,
    DebugInfoGetter* debug_info_getter,
    browser_sync::TrafficRecorder* traffic_recorder)
    : resolver_(NULL),
      connection_manager_(connection_manager),
      directory_(directory),
      registrar_(model_safe_worker_registrar),
      extensions_activity_monitor_(extensions_activity_monitor),
      notifications_enabled_(false),
      max_commit_batch_size_(kDefaultMaxCommitBatchSize),
      debug_info_getter_(debug_info_getter),
      traffic_recorder_(traffic_recorder) {
  std::vector<SyncEngineEventListener*>::const_iterator it;
  for (it = listeners.begin(); it != listeners.end(); ++it)
    listeners_.AddObserver(*it);
}

SyncSessionContext::SyncSessionContext()
    : connection_manager_(NULL),
      directory_(NULL),
      registrar_(NULL),
      extensions_activity_monitor_(NULL),
      debug_info_getter_(NULL),
      traffic_recorder_(NULL) {
}

SyncSessionContext::~SyncSessionContext() {
}

void SyncSessionContext::SetUnthrottleTime(syncable::ModelTypeSet types,
                                           const base::TimeTicks& time) {
  for (syncable::ModelTypeSet::Iterator it = types.First();
       it.Good(); it.Inc()) {
    unthrottle_times_[it.Get()] = time;
  }
}

void SyncSessionContext::PruneUnthrottledTypes(const base::TimeTicks& time) {
  UnthrottleTimes::iterator it = unthrottle_times_.begin();
  while (it != unthrottle_times_.end()) {
    if (it->second <= time) {
      // Delete and increment the iterator.
      UnthrottleTimes::iterator iterator_to_delete = it;
      ++it;
      unthrottle_times_.erase(iterator_to_delete);
    } else {
      // Just increment the iterator.
      ++it;
    }
  }
}

// TODO(lipalani): Call this function and fill the return values in snapshot
// so it could be shown in the about:sync page.
syncable::ModelTypeSet SyncSessionContext::GetThrottledTypes() const {
  syncable::ModelTypeSet types;
  for (UnthrottleTimes::const_iterator it = unthrottle_times_.begin();
       it != unthrottle_times_.end();
       ++it) {
    types.Put(it->first);
  }
  return types;
}

}  // namespace sessions
}  // namespace browser_sync