• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "components/invalidation/invalidation_notifier.h"
6 
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 "google/cacheinvalidation/include/invalidation-client-factory.h"
12 #include "jingle/notifier/listener/push_client.h"
13 #include "net/url_request/url_request_context.h"
14 #include "sync/notifier/invalidation_handler.h"
15 #include "talk/xmpp/jid.h"
16 #include "talk/xmpp/xmppclientsettings.h"
17 
18 namespace syncer {
19 
InvalidationNotifier(scoped_ptr<SyncNetworkChannel> network_channel,const std::string & invalidator_client_id,const UnackedInvalidationsMap & saved_invalidations,const std::string & invalidation_bootstrap_data,const WeakHandle<InvalidationStateTracker> & invalidation_state_tracker,const std::string & client_info)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 WeakHandle<InvalidationStateTracker>& invalidation_state_tracker,
26     const std::string& client_info)
27     : state_(STOPPED),
28       saved_invalidations_(saved_invalidations),
29       invalidation_state_tracker_(invalidation_state_tracker),
30       client_info_(client_info),
31       invalidator_client_id_(invalidator_client_id),
32       invalidation_bootstrap_data_(invalidation_bootstrap_data),
33       invalidation_listener_(network_channel.Pass()) {
34 }
35 
~InvalidationNotifier()36 InvalidationNotifier::~InvalidationNotifier() {
37   DCHECK(CalledOnValidThread());
38 }
39 
RegisterHandler(InvalidationHandler * handler)40 void InvalidationNotifier::RegisterHandler(InvalidationHandler* handler) {
41   DCHECK(CalledOnValidThread());
42   registrar_.RegisterHandler(handler);
43 }
44 
UpdateRegisteredIds(InvalidationHandler * handler,const ObjectIdSet & ids)45 void InvalidationNotifier::UpdateRegisteredIds(InvalidationHandler* handler,
46                                                const ObjectIdSet& ids) {
47   DCHECK(CalledOnValidThread());
48   registrar_.UpdateRegisteredIds(handler, ids);
49   invalidation_listener_.UpdateRegisteredIds(registrar_.GetAllRegisteredIds());
50 }
51 
UnregisterHandler(InvalidationHandler * handler)52 void InvalidationNotifier::UnregisterHandler(InvalidationHandler* handler) {
53   DCHECK(CalledOnValidThread());
54   registrar_.UnregisterHandler(handler);
55 }
56 
GetInvalidatorState() const57 InvalidatorState InvalidationNotifier::GetInvalidatorState() const {
58   DCHECK(CalledOnValidThread());
59   return registrar_.GetInvalidatorState();
60 }
61 
UpdateCredentials(const std::string & email,const std::string & token)62 void InvalidationNotifier::UpdateCredentials(
63     const std::string& email, const std::string& token) {
64   if (state_ == STOPPED) {
65     invalidation_listener_.Start(
66         base::Bind(&invalidation::CreateInvalidationClient),
67         invalidator_client_id_, client_info_, invalidation_bootstrap_data_,
68         saved_invalidations_,
69         invalidation_state_tracker_,
70         this);
71     state_ = STARTED;
72   }
73   invalidation_listener_.UpdateCredentials(email, token);
74 }
75 
RequestDetailedStatus(base::Callback<void (const base::DictionaryValue &)> callback) const76 void InvalidationNotifier::RequestDetailedStatus(
77     base::Callback<void(const base::DictionaryValue&)> callback) const {
78   DCHECK(CalledOnValidThread());
79   invalidation_listener_.RequestDetailedStatus(callback);
80 }
81 
OnInvalidate(const ObjectIdInvalidationMap & invalidation_map)82 void InvalidationNotifier::OnInvalidate(
83     const ObjectIdInvalidationMap& invalidation_map) {
84   DCHECK(CalledOnValidThread());
85   registrar_.DispatchInvalidationsToHandlers(invalidation_map);
86 }
87 
OnInvalidatorStateChange(InvalidatorState state)88 void InvalidationNotifier::OnInvalidatorStateChange(InvalidatorState state) {
89   DCHECK(CalledOnValidThread());
90   registrar_.UpdateInvalidatorState(state);
91 }
92 
93 }  // namespace syncer
94