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

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

Issue 10451060: sync: migrate invalidation state from syncable::Directory to InvalidationStorage (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: init Created 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "sync/notifier/chrome_invalidation_client.h" 5 #include "sync/notifier/chrome_invalidation_client.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 14 matching lines...) Expand all
25 25
26 } // anonymous namespace 26 } // anonymous namespace
27 27
28 namespace sync_notifier { 28 namespace sync_notifier {
29 29
30 ChromeInvalidationClient::Listener::~Listener() {} 30 ChromeInvalidationClient::Listener::~Listener() {}
31 31
32 ChromeInvalidationClient::ChromeInvalidationClient() 32 ChromeInvalidationClient::ChromeInvalidationClient()
33 : chrome_system_resources_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 33 : chrome_system_resources_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
34 listener_(NULL), 34 listener_(NULL),
35 state_writer_(NULL),
36 ticl_ready_(false) { 35 ticl_ready_(false) {
37 DCHECK(non_thread_safe_.CalledOnValidThread()); 36 DCHECK(non_thread_safe_.CalledOnValidThread());
38 } 37 }
39 38
40 ChromeInvalidationClient::~ChromeInvalidationClient() { 39 ChromeInvalidationClient::~ChromeInvalidationClient() {
41 DCHECK(non_thread_safe_.CalledOnValidThread()); 40 DCHECK(non_thread_safe_.CalledOnValidThread());
42 Stop(); 41 Stop();
43 DCHECK(!listener_); 42 DCHECK(!listener_);
44 DCHECK(!state_writer_);
45 } 43 }
46 44
47 void ChromeInvalidationClient::Start( 45 void ChromeInvalidationClient::Start(
48 const std::string& client_id, const std::string& client_info, 46 const std::string& client_id, const std::string& client_info,
49 const std::string& state, 47 const std::string& state,
50 const InvalidationVersionMap& initial_max_invalidation_versions, 48 const InvalidationVersionMap& initial_max_invalidation_versions,
51 const browser_sync::WeakHandle<InvalidationStateTracker>& 49 const browser_sync::WeakHandle<InvalidationStateTracker>&
52 invalidation_state_tracker, 50 invalidation_state_tracker,
53 Listener* listener, 51 Listener* listener,
54 StateWriter* state_writer,
55 base::WeakPtr<buzz::XmppTaskParentInterface> base_task) { 52 base::WeakPtr<buzz::XmppTaskParentInterface> base_task) {
56 DCHECK(non_thread_safe_.CalledOnValidThread()); 53 DCHECK(non_thread_safe_.CalledOnValidThread());
57 Stop(); 54 Stop();
58 55
59 chrome_system_resources_.set_platform(client_info); 56 chrome_system_resources_.set_platform(client_info);
60 chrome_system_resources_.Start(); 57 chrome_system_resources_.Start();
61 58
62 // The Storage resource is implemented as a write-through cache. We populate 59 // The Storage resource is implemented as a write-through cache. We populate
63 // it with the initial state on startup, so subsequent writes go to disk and 60 // it with the initial state on startup, so subsequent writes go to disk and
64 // update the in-memory cache, while reads just return the cached state. 61 // update the in-memory cache, while reads just return the cached state.
(...skipping 10 matching lines...) Expand all
75 << syncable::ModelTypeToString(it->first) << " is " 72 << syncable::ModelTypeToString(it->first) << " is "
76 << it->second; 73 << it->second;
77 } 74 }
78 } 75 }
79 invalidation_state_tracker_ = invalidation_state_tracker; 76 invalidation_state_tracker_ = invalidation_state_tracker;
80 DCHECK(invalidation_state_tracker_.IsInitialized()); 77 DCHECK(invalidation_state_tracker_.IsInitialized());
81 78
82 DCHECK(!listener_); 79 DCHECK(!listener_);
83 DCHECK(listener); 80 DCHECK(listener);
84 listener_ = listener; 81 listener_ = listener;
85 DCHECK(!state_writer_);
86 DCHECK(state_writer);
87 state_writer_ = state_writer;
88 82
89 int client_type = ipc::invalidation::ClientType::CHROME_SYNC; 83 int client_type = ipc::invalidation::ClientType::CHROME_SYNC;
90 invalidation_client_.reset( 84 invalidation_client_.reset(
91 invalidation::CreateInvalidationClient( 85 invalidation::CreateInvalidationClient(
92 &chrome_system_resources_, client_type, client_id, 86 &chrome_system_resources_, client_type, client_id,
93 kApplicationName, this)); 87 kApplicationName, this));
94 ChangeBaseTask(base_task); 88 ChangeBaseTask(base_task);
95 invalidation_client_->Start(); 89 invalidation_client_->Start();
96 90
97 registration_manager_.reset( 91 registration_manager_.reset(
(...skipping 16 matching lines...) Expand all
114 DCHECK(!cache_invalidation_packet_handler_.get()); 108 DCHECK(!cache_invalidation_packet_handler_.get());
115 return; 109 return;
116 } 110 }
117 111
118 registration_manager_.reset(); 112 registration_manager_.reset();
119 cache_invalidation_packet_handler_.reset(); 113 cache_invalidation_packet_handler_.reset();
120 chrome_system_resources_.Stop(); 114 chrome_system_resources_.Stop();
121 invalidation_client_->Stop(); 115 invalidation_client_->Stop();
122 116
123 invalidation_client_.reset(); 117 invalidation_client_.reset();
124 state_writer_ = NULL;
125 listener_ = NULL; 118 listener_ = NULL;
126 119
127 invalidation_state_tracker_.Reset(); 120 invalidation_state_tracker_.Reset();
128 max_invalidation_versions_.clear(); 121 max_invalidation_versions_.clear();
129 } 122 }
130 123
131 void ChromeInvalidationClient::RegisterTypes(syncable::ModelTypeSet types) { 124 void ChromeInvalidationClient::RegisterTypes(syncable::ModelTypeSet types) {
132 DCHECK(non_thread_safe_.CalledOnValidThread()); 125 DCHECK(non_thread_safe_.CalledOnValidThread());
133 registered_types_ = types; 126 registered_types_ = types;
134 if (ticl_ready_ && registration_manager_.get()) { 127 if (ticl_ready_ && registration_manager_.get()) {
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 void ChromeInvalidationClient::InformError( 292 void ChromeInvalidationClient::InformError(
300 invalidation::InvalidationClient* client, 293 invalidation::InvalidationClient* client,
301 const invalidation::ErrorInfo& error_info) { 294 const invalidation::ErrorInfo& error_info) {
302 listener_->OnSessionStatusChanged(false); 295 listener_->OnSessionStatusChanged(false);
303 LOG(ERROR) << "Invalidation client encountered an error"; 296 LOG(ERROR) << "Invalidation client encountered an error";
304 // TODO(ghc): handle the error. 297 // TODO(ghc): handle the error.
305 } 298 }
306 299
307 void ChromeInvalidationClient::WriteState(const std::string& state) { 300 void ChromeInvalidationClient::WriteState(const std::string& state) {
308 DCHECK(non_thread_safe_.CalledOnValidThread()); 301 DCHECK(non_thread_safe_.CalledOnValidThread());
309 CHECK(state_writer_); 302 DVLOG(1) << "WriteState";
310 state_writer_->WriteState(state); 303 invalidation_state_tracker_.Call(
304 FROM_HERE, &InvalidationStateTracker::SetInvalidationState, state);
311 } 305 }
312 306
313 } // namespace sync_notifier 307 } // namespace sync_notifier
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698