Android Chromoting: Remove exit-fullscreen button.
[chromium-blink-merge.git] / components / invalidation / invalidation_notifier.cc
blob2319eef4f1c669d7a9c415f2cfb69f3f7e8a5520
1 // Copyright 2014 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.
5 #include "components/invalidation/invalidation_notifier.h"
7 #include "base/bind.h"
8 #include "base/logging.h"
9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/metrics/histogram.h"
11 #include "components/invalidation/invalidation_handler.h"
12 #include "google/cacheinvalidation/include/invalidation-client-factory.h"
13 #include "jingle/notifier/listener/push_client.h"
14 #include "net/url_request/url_request_context.h"
16 namespace syncer {
18 InvalidationNotifier::InvalidationNotifier(
19 scoped_ptr<SyncNetworkChannel> network_channel,
20 const std::string& invalidator_client_id,
21 const UnackedInvalidationsMap& saved_invalidations,
22 const std::string& invalidation_bootstrap_data,
23 const base::WeakPtr<InvalidationStateTracker>& invalidation_state_tracker,
24 scoped_refptr<base::SingleThreadTaskRunner>
25 invalidation_state_tracker_task_runner,
26 const std::string& client_info)
27 : state_(STOPPED),
28 saved_invalidations_(saved_invalidations),
29 invalidation_state_tracker_(invalidation_state_tracker),
30 invalidation_state_tracker_task_runner_(
31 invalidation_state_tracker_task_runner),
32 client_info_(client_info),
33 invalidator_client_id_(invalidator_client_id),
34 invalidation_bootstrap_data_(invalidation_bootstrap_data),
35 invalidation_listener_(network_channel.Pass()) {
38 InvalidationNotifier::~InvalidationNotifier() {
39 DCHECK(CalledOnValidThread());
42 void InvalidationNotifier::RegisterHandler(InvalidationHandler* handler) {
43 DCHECK(CalledOnValidThread());
44 registrar_.RegisterHandler(handler);
47 void InvalidationNotifier::UpdateRegisteredIds(InvalidationHandler* handler,
48 const ObjectIdSet& ids) {
49 DCHECK(CalledOnValidThread());
50 registrar_.UpdateRegisteredIds(handler, ids);
51 invalidation_listener_.UpdateRegisteredIds(registrar_.GetAllRegisteredIds());
54 void InvalidationNotifier::UnregisterHandler(InvalidationHandler* handler) {
55 DCHECK(CalledOnValidThread());
56 registrar_.UnregisterHandler(handler);
59 InvalidatorState InvalidationNotifier::GetInvalidatorState() const {
60 DCHECK(CalledOnValidThread());
61 return registrar_.GetInvalidatorState();
64 void InvalidationNotifier::UpdateCredentials(
65 const std::string& email, const std::string& token) {
66 if (state_ == STOPPED) {
67 invalidation_listener_.Start(
68 base::Bind(&invalidation::CreateInvalidationClient),
69 invalidator_client_id_,
70 client_info_,
71 invalidation_bootstrap_data_,
72 saved_invalidations_,
73 invalidation_state_tracker_,
74 invalidation_state_tracker_task_runner_,
75 this);
76 state_ = STARTED;
78 invalidation_listener_.UpdateCredentials(email, token);
81 void InvalidationNotifier::RequestDetailedStatus(
82 base::Callback<void(const base::DictionaryValue&)> callback) const {
83 DCHECK(CalledOnValidThread());
84 invalidation_listener_.RequestDetailedStatus(callback);
87 void InvalidationNotifier::OnInvalidate(
88 const ObjectIdInvalidationMap& invalidation_map) {
89 DCHECK(CalledOnValidThread());
90 registrar_.DispatchInvalidationsToHandlers(invalidation_map);
93 void InvalidationNotifier::OnInvalidatorStateChange(InvalidatorState state) {
94 DCHECK(CalledOnValidThread());
95 registrar_.UpdateInvalidatorState(state);
98 } // namespace syncer