Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / invalidation / p2p_invalidation_service.cc
blob1eda06eadc3485c604db7ece6ae9c011e90fe6ea
1 // Copyright (c) 2013 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 "chrome/browser/invalidation/p2p_invalidation_service.h"
7 #include "base/command_line.h"
8 #include "chrome/browser/invalidation/invalidation_service_util.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/common/chrome_switches.h"
11 #include "jingle/notifier/base/notifier_options.h"
12 #include "jingle/notifier/listener/push_client.h"
13 #include "sync/notifier/p2p_invalidator.h"
15 namespace net {
16 class URLRequestContextGetter;
19 namespace invalidation {
21 P2PInvalidationService::P2PInvalidationService(Profile* profile) {
22 notifier::NotifierOptions notifier_options =
23 ParseNotifierOptions(*CommandLine::ForCurrentProcess());
24 notifier_options.request_context_getter = profile->GetRequestContext();
25 invalidator_id_ = GenerateInvalidatorClientId();
26 invalidator_.reset(new syncer::P2PInvalidator(
27 notifier::PushClient::CreateDefault(notifier_options),
28 invalidator_id_,
29 syncer::NOTIFY_ALL));
32 P2PInvalidationService::~P2PInvalidationService() {
35 void P2PInvalidationService::UpdateCredentials(const std::string& username,
36 const std::string& password) {
37 invalidator_->UpdateCredentials(username, password);
40 void P2PInvalidationService::Shutdown() {
41 invalidator_.reset();
44 void P2PInvalidationService::RegisterInvalidationHandler(
45 syncer::InvalidationHandler* handler) {
46 invalidator_->RegisterHandler(handler);
49 void P2PInvalidationService::UpdateRegisteredInvalidationIds(
50 syncer::InvalidationHandler* handler,
51 const syncer::ObjectIdSet& ids) {
52 invalidator_->UpdateRegisteredIds(handler, ids);
55 void P2PInvalidationService::UnregisterInvalidationHandler(
56 syncer::InvalidationHandler* handler) {
57 invalidator_->UnregisterHandler(handler);
60 void P2PInvalidationService::SendInvalidation(
61 const syncer::ObjectIdSet& ids) {
62 invalidator_->SendInvalidation(ids);
65 syncer::InvalidatorState P2PInvalidationService::GetInvalidatorState() const {
66 return invalidator_->GetInvalidatorState();
69 std::string P2PInvalidationService::GetInvalidatorClientId() const {
70 return invalidator_id_;
73 } // namespace invalidation