1cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 2a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// found in the LICENSE file. 4a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 5a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/callback_forward.h" 6a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "base/memory/ref_counted.h" 7a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "base/threading/non_thread_safe.h" 80de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles)#include "components/invalidation/invalidation_service.h" 946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "components/invalidation/p2p_invalidator.h" 10a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "components/keyed_service/core/keyed_service.h" 11a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 12cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#ifndef COMPONENTS_INVALIDATION_P2P_INVALIDATION_SERVICE_H_ 13cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#define COMPONENTS_INVALIDATION_P2P_INVALIDATION_SERVICE_H_ 14a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 15a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochnamespace net { 16a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochclass URLRequestContextGetter; 17a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch} 18a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 19a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)namespace syncer { 20a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)class P2PInvalidator; 21a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)} 22a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 23a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)namespace invalidation { 24a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 25a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class InvalidationLogger; 26a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 27a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// This service is a wrapper around P2PInvalidator. Unlike other 28a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// InvalidationServices, it can both send and receive invalidations. It is used 29a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// only in tests, where we're unable to connect to a real invalidations server. 30f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)class P2PInvalidationService : public base::NonThreadSafe, 31f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) public InvalidationService { 32a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) public: 33a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch P2PInvalidationService( 340529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch scoped_ptr<IdentityProvider> identity_provider, 35a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch const scoped_refptr<net::URLRequestContextGetter>& request_context, 36a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch syncer::P2PNotificationTarget notification_target); 37a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual ~P2PInvalidationService(); 38a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 39eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // InvalidationService implementation. 40f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // It is an error to have registered handlers when the service is destroyed. 41a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual void RegisterInvalidationHandler( 42a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) syncer::InvalidationHandler* handler) OVERRIDE; 43a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual void UpdateRegisteredInvalidationIds( 44a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) syncer::InvalidationHandler* handler, 45a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) const syncer::ObjectIdSet& ids) OVERRIDE; 46a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual void UnregisterInvalidationHandler( 47a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) syncer::InvalidationHandler* handler) OVERRIDE; 48a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual syncer::InvalidatorState GetInvalidatorState() const OVERRIDE; 49eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch virtual std::string GetInvalidatorClientId() const OVERRIDE; 505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual InvalidationLogger* GetInvalidationLogger() OVERRIDE; 51a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual void RequestDetailedStatus( 52effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch base::Callback<void(const base::DictionaryValue&)> caller) const OVERRIDE; 530529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch virtual IdentityProvider* GetIdentityProvider() OVERRIDE; 54a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 55a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) void UpdateCredentials(const std::string& username, 56a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) const std::string& password); 57a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 584e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) void SendInvalidation(const syncer::ObjectIdSet& ids); 59a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 60a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) private: 610529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch scoped_ptr<IdentityProvider> identity_provider_; 62a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) scoped_ptr<syncer::P2PInvalidator> invalidator_; 63a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) std::string invalidator_id_; 64a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 65a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(P2PInvalidationService); 66a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}; 67a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 68a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)} // namespace invalidation 69a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 70cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#endif // COMPONENTS_INVALIDATION_P2P_INVALIDATION_SERVICE_H_ 71