Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: sync/notifier/invalidator_factory.cc

Issue 15580002: Make use of InvalidationService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sync/notifier/invalidator_factory.h ('k') | sync/notifier/invalidator_factory_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 "sync/notifier/invalidator_factory.h"
6
7 #include <string>
8
9 #include "base/base64.h"
10 #include "base/logging.h"
11 #include "base/rand_util.h"
12 #include "jingle/notifier/listener/push_client.h"
13 #include "sync/notifier/invalidator.h"
14 #include "sync/notifier/non_blocking_invalidator.h"
15 #include "sync/notifier/p2p_invalidator.h"
16
17 namespace syncer {
18 namespace {
19
20 Invalidator* CreateDefaultInvalidator(
21 const notifier::NotifierOptions& notifier_options,
22 const std::string& invalidator_client_id,
23 const InvalidationStateMap& initial_invalidation_state_map,
24 const std::string& invalidation_bootstrap_data,
25 const WeakHandle<InvalidationStateTracker>& invalidation_state_tracker,
26 const std::string& client_info) {
27 if (notifier_options.notification_method == notifier::NOTIFICATION_P2P) {
28 // TODO(rlarocque): Ideally, the notification target would be
29 // NOTIFY_OTHERS. There's no good reason to notify ourselves of our own
30 // commits. We self-notify for now only because the integration tests rely
31 // on this behaviour. See crbug.com/97780.
32 return new P2PInvalidator(
33 notifier::PushClient::CreateDefault(notifier_options),
34 invalidator_client_id,
35 NOTIFY_ALL);
36 }
37
38 return new NonBlockingInvalidator(
39 notifier_options, invalidator_client_id, initial_invalidation_state_map,
40 invalidation_bootstrap_data, invalidation_state_tracker, client_info);
41 }
42
43 std::string GenerateInvalidatorClientId() {
44 // Generate a GUID with 128 bits worth of base64-encoded randomness.
45 // This format is similar to that of sync's cache_guid.
46 const int kGuidBytes = 128 / 8;
47 std::string guid;
48 base::Base64Encode(base::RandBytesAsString(kGuidBytes), &guid);
49 return guid;
50 }
51
52 } // namespace
53
54 // TODO(akalin): Remove the dependency on jingle if OS_ANDROID is defined.
55 InvalidatorFactory::InvalidatorFactory(
56 const notifier::NotifierOptions& notifier_options,
57 const std::string& client_info,
58 const base::WeakPtr<InvalidationStateTracker>&
59 invalidation_state_tracker)
60 : notifier_options_(notifier_options),
61 client_info_(client_info) {
62 if (!invalidation_state_tracker.get()) {
63 return;
64 }
65
66 // TODO(rlarocque): This is not the most obvious place for client ID
67 // generation code. We should try to find a better place for it when we
68 // refactor the invalidator into its own service.
69 if (invalidation_state_tracker->GetInvalidatorClientId().empty()) {
70 // This also clears any existing state. We can't reuse old invalidator
71 // state with the new ID anyway.
72 invalidation_state_tracker->SetInvalidatorClientId(
73 GenerateInvalidatorClientId());
74 }
75
76 initial_invalidation_state_map_ =
77 invalidation_state_tracker->GetAllInvalidationStates();
78 invalidator_client_id_ =
79 invalidation_state_tracker->GetInvalidatorClientId();
80 invalidation_bootstrap_data_ = invalidation_state_tracker->GetBootstrapData();
81 invalidation_state_tracker_ = WeakHandle<InvalidationStateTracker>(
82 invalidation_state_tracker);
83 }
84
85 InvalidatorFactory::~InvalidatorFactory() {
86 }
87
88 Invalidator* InvalidatorFactory::CreateInvalidator() {
89 #if defined(OS_ANDROID)
90 // Android uses AndroidInvalidatorBridge instead. See SyncManager
91 // initialization code in SyncBackendHost for more information.
92 return NULL;
93 #else
94 return CreateDefaultInvalidator(notifier_options_,
95 invalidator_client_id_,
96 initial_invalidation_state_map_,
97 invalidation_bootstrap_data_,
98 invalidation_state_tracker_,
99 client_info_);
100 #endif
101 }
102
103 std::string InvalidatorFactory::GetInvalidatorClientId() const {
104 return invalidator_client_id_;
105 }
106
107 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/notifier/invalidator_factory.h ('k') | sync/notifier/invalidator_factory_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698