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"
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"
15 #include "talk/xmpp/jid.h"
16 #include "talk/xmpp/xmppclientsettings.h"
20 InvalidationNotifier::InvalidationNotifier(
21 scoped_ptr
<SyncNetworkChannel
> network_channel
,
22 const std::string
& invalidator_client_id
,
23 const UnackedInvalidationsMap
& saved_invalidations
,
24 const std::string
& invalidation_bootstrap_data
,
25 const base::WeakPtr
<InvalidationStateTracker
>& invalidation_state_tracker
,
26 scoped_refptr
<base::SingleThreadTaskRunner
>
27 invalidation_state_tracker_task_runner
,
28 const std::string
& client_info
)
30 saved_invalidations_(saved_invalidations
),
31 invalidation_state_tracker_(invalidation_state_tracker
),
32 invalidation_state_tracker_task_runner_(
33 invalidation_state_tracker_task_runner
),
34 client_info_(client_info
),
35 invalidator_client_id_(invalidator_client_id
),
36 invalidation_bootstrap_data_(invalidation_bootstrap_data
),
37 invalidation_listener_(network_channel
.Pass()) {
40 InvalidationNotifier::~InvalidationNotifier() {
41 DCHECK(CalledOnValidThread());
44 void InvalidationNotifier::RegisterHandler(InvalidationHandler
* handler
) {
45 DCHECK(CalledOnValidThread());
46 registrar_
.RegisterHandler(handler
);
49 void InvalidationNotifier::UpdateRegisteredIds(InvalidationHandler
* handler
,
50 const ObjectIdSet
& ids
) {
51 DCHECK(CalledOnValidThread());
52 registrar_
.UpdateRegisteredIds(handler
, ids
);
53 invalidation_listener_
.UpdateRegisteredIds(registrar_
.GetAllRegisteredIds());
56 void InvalidationNotifier::UnregisterHandler(InvalidationHandler
* handler
) {
57 DCHECK(CalledOnValidThread());
58 registrar_
.UnregisterHandler(handler
);
61 InvalidatorState
InvalidationNotifier::GetInvalidatorState() const {
62 DCHECK(CalledOnValidThread());
63 return registrar_
.GetInvalidatorState();
66 void InvalidationNotifier::UpdateCredentials(
67 const std::string
& email
, const std::string
& token
) {
68 if (state_
== STOPPED
) {
69 invalidation_listener_
.Start(
70 base::Bind(&invalidation::CreateInvalidationClient
),
71 invalidator_client_id_
,
73 invalidation_bootstrap_data_
,
75 invalidation_state_tracker_
,
76 invalidation_state_tracker_task_runner_
,
80 invalidation_listener_
.UpdateCredentials(email
, token
);
83 void InvalidationNotifier::RequestDetailedStatus(
84 base::Callback
<void(const base::DictionaryValue
&)> callback
) const {
85 DCHECK(CalledOnValidThread());
86 invalidation_listener_
.RequestDetailedStatus(callback
);
89 void InvalidationNotifier::OnInvalidate(
90 const ObjectIdInvalidationMap
& invalidation_map
) {
91 DCHECK(CalledOnValidThread());
92 registrar_
.DispatchInvalidationsToHandlers(invalidation_map
);
95 void InvalidationNotifier::OnInvalidatorStateChange(InvalidatorState state
) {
96 DCHECK(CalledOnValidThread());
97 registrar_
.UpdateInvalidatorState(state
);
100 } // namespace syncer