Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / invalidation / fake_invalidation_service.cc
blobfd6a211b818ae5949309a60b6dc7b808261c3bf4
1 // Copyright 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/fake_invalidation_service.h"
7 #include "base/callback.h"
8 #include "base/macros.h"
9 #include "components/invalidation/impl/invalidation_service_util.h"
10 #include "components/invalidation/public/object_id_invalidation_map.h"
12 namespace invalidation {
14 FakeInvalidationService::FakeInvalidationService()
15 : client_id_(GenerateInvalidatorClientId()),
16 identity_provider_(&token_service_) {
17 invalidator_registrar_.UpdateInvalidatorState(syncer::INVALIDATIONS_ENABLED);
18 token_service_.set_auto_post_fetch_response_on_message_loop(true);
21 FakeInvalidationService::~FakeInvalidationService() {
24 void FakeInvalidationService::RegisterInvalidationHandler(
25 syncer::InvalidationHandler* handler) {
26 invalidator_registrar_.RegisterHandler(handler);
29 bool FakeInvalidationService::UpdateRegisteredInvalidationIds(
30 syncer::InvalidationHandler* handler,
31 const syncer::ObjectIdSet& ids) {
32 return invalidator_registrar_.UpdateRegisteredIds(handler, ids);
35 void FakeInvalidationService::UnregisterInvalidationHandler(
36 syncer::InvalidationHandler* handler) {
37 invalidator_registrar_.UnregisterHandler(handler);
40 syncer::InvalidatorState FakeInvalidationService::GetInvalidatorState() const {
41 return invalidator_registrar_.GetInvalidatorState();
44 std::string FakeInvalidationService::GetInvalidatorClientId() const {
45 return client_id_;
48 InvalidationLogger* FakeInvalidationService::GetInvalidationLogger() {
49 return NULL;
52 void FakeInvalidationService::RequestDetailedStatus(
53 base::Callback<void(const base::DictionaryValue&)> caller) const {
54 base::DictionaryValue value;
55 caller.Run(value);
58 IdentityProvider* FakeInvalidationService::GetIdentityProvider() {
59 return &identity_provider_;
62 void FakeInvalidationService::SetInvalidatorState(
63 syncer::InvalidatorState state) {
64 invalidator_registrar_.UpdateInvalidatorState(state);
67 void FakeInvalidationService::EmitInvalidationForTest(
68 const syncer::Invalidation& invalidation) {
69 // This function might need to modify the invalidator, so we start by making
70 // an identical copy of it.
71 syncer::Invalidation invalidation_copy(invalidation);
73 // If no one is listening to this invalidation, do not send it out.
74 syncer::ObjectIdSet registered_ids =
75 invalidator_registrar_.GetAllRegisteredIds();
76 if (registered_ids.find(invalidation.object_id()) == registered_ids.end()) {
77 mock_ack_handler_.RegisterUnsentInvalidation(&invalidation_copy);
78 return;
81 // Otherwise, register the invalidation with the mock_ack_handler_ and deliver
82 // it to the appropriate consumer.
83 mock_ack_handler_.RegisterInvalidation(&invalidation_copy);
84 syncer::ObjectIdInvalidationMap invalidation_map;
85 invalidation_map.Insert(invalidation_copy);
86 invalidator_registrar_.DispatchInvalidationsToHandlers(invalidation_map);
89 syncer::MockAckHandler* FakeInvalidationService::GetMockAckHandler() {
90 return &mock_ack_handler_;
93 } // namespace invalidation