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

Side by Side Diff: chrome/browser/sync/engine/all_status.cc

Issue 2075012: Replace changes_channel with an observer list. (Closed)
Patch Set: Ready for checkin Created 10 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 | « chrome/browser/sync/engine/all_status.h ('k') | chrome/browser/sync/engine/syncapi.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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 "chrome/browser/sync/engine/all_status.h" 5 #include "chrome/browser/sync/engine/all_status.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/port.h" 10 #include "base/port.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 static const AllStatusEvent shutdown_event = 43 static const AllStatusEvent shutdown_event =
44 { AllStatusEvent::SHUTDOWN, init_status }; 44 { AllStatusEvent::SHUTDOWN, init_status };
45 45
46 AllStatus::AllStatus() : status_(init_status), 46 AllStatus::AllStatus() : status_(init_status),
47 channel_(new Channel(shutdown_event)) { 47 channel_(new Channel(shutdown_event)) {
48 status_.initial_sync_ended = true; 48 status_.initial_sync_ended = true;
49 status_.notifications_enabled = false; 49 status_.notifications_enabled = false;
50 } 50 }
51 51
52 AllStatus::~AllStatus() { 52 AllStatus::~AllStatus() {
53 syncer_thread_hookup_.reset();
53 delete channel_; 54 delete channel_;
54 } 55 }
55 56
56 void AllStatus::WatchConnectionManager(ServerConnectionManager* conn_mgr) { 57 void AllStatus::WatchConnectionManager(ServerConnectionManager* conn_mgr) {
57 conn_mgr_hookup_.reset(NewEventListenerHookup(conn_mgr->channel(), this, 58 conn_mgr_hookup_.reset(NewEventListenerHookup(conn_mgr->channel(), this,
58 &AllStatus::HandleServerConnectionEvent)); 59 &AllStatus::HandleServerConnectionEvent));
59 } 60 }
60 61
61 void AllStatus::WatchSyncerThread(SyncerThread* syncer_thread) { 62 void AllStatus::WatchSyncerThread(SyncerThread* syncer_thread) {
62 syncer_thread_hookup_.reset( 63 syncer_thread_hookup_.reset(
63 NewEventListenerHookup(syncer_thread->relay_channel(), this, 64 syncer_thread->relay_channel()->AddObserver(this));
64 &AllStatus::HandleSyncerEvent));
65 } 65 }
66 66
67 AllStatus::Status AllStatus::CreateBlankStatus() const { 67 AllStatus::Status AllStatus::CreateBlankStatus() const {
68 Status status = status_; 68 Status status = status_;
69 status.syncing = true; 69 status.syncing = true;
70 status.unsynced_count = 0; 70 status.unsynced_count = 0;
71 status.conflicting_count = 0; 71 status.conflicting_count = 0;
72 status.initial_sync_ended = false; 72 status.initial_sync_ended = false;
73 status.syncer_stuck = false; 73 status.syncer_stuck = false;
74 status.max_consecutive_errors = 0; 74 status.max_consecutive_errors = 0;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 } else { 180 } else {
181 lock.set_notify_plan(DONT_NOTIFY); 181 lock.set_notify_plan(DONT_NOTIFY);
182 } 182 }
183 break; 183 break;
184 default: 184 default:
185 lock.set_notify_plan(DONT_NOTIFY); 185 lock.set_notify_plan(DONT_NOTIFY);
186 break; 186 break;
187 } 187 }
188 } 188 }
189 189
190 void AllStatus::HandleSyncerEvent(const SyncerEvent& event) { 190 void AllStatus::HandleChannelEvent(const SyncerEvent& event) {
191 ScopedStatusLockWithNotify lock(this); 191 ScopedStatusLockWithNotify lock(this);
192 switch (event.what_happened) { 192 switch (event.what_happened) {
193 case SyncerEvent::COMMITS_SUCCEEDED: 193 case SyncerEvent::COMMITS_SUCCEEDED:
194 break; 194 break;
195 case SyncerEvent::SYNC_CYCLE_ENDED: 195 case SyncerEvent::SYNC_CYCLE_ENDED:
196 case SyncerEvent::STATUS_CHANGED: 196 case SyncerEvent::STATUS_CHANGED:
197 status_ = CalcSyncing(event); 197 status_ = CalcSyncing(event);
198 break; 198 break;
199 case SyncerEvent::SHUTDOWN_USE_WITH_CARE: 199 case SyncerEvent::SHUTDOWN_USE_WITH_CARE:
200 // We're safe to use this value here because we don't call into the syncer 200 // We're safe to use this value here because we don't call into the syncer
201 // or block on any processes. 201 // or block on any processes.
202 lock.set_notify_plan(DONT_NOTIFY); 202 lock.set_notify_plan(DONT_NOTIFY);
203 syncer_thread_hookup_.reset();
203 break; 204 break;
204 case SyncerEvent::OVER_QUOTA: 205 case SyncerEvent::OVER_QUOTA:
205 LOG(WARNING) << "User has gone over quota."; 206 LOG(WARNING) << "User has gone over quota.";
206 lock.NotifyOverQuota(); 207 lock.NotifyOverQuota();
207 break; 208 break;
208 case SyncerEvent::REQUEST_SYNC_NUDGE: 209 case SyncerEvent::REQUEST_SYNC_NUDGE:
209 lock.set_notify_plan(DONT_NOTIFY); 210 lock.set_notify_plan(DONT_NOTIFY);
210 break; 211 break;
211 case SyncerEvent::PAUSED: 212 case SyncerEvent::PAUSED:
212 lock.set_notify_plan(DONT_NOTIFY); 213 lock.set_notify_plan(DONT_NOTIFY);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 allstatus_->mutex_.Release(); 292 allstatus_->mutex_.Release();
292 if (event_.what_changed) 293 if (event_.what_changed)
293 allstatus_->channel()->NotifyListeners(event_); 294 allstatus_->channel()->NotifyListeners(event_);
294 } 295 }
295 296
296 void ScopedStatusLockWithNotify::NotifyOverQuota() { 297 void ScopedStatusLockWithNotify::NotifyOverQuota() {
297 event_.what_changed |= AllStatusEvent::OVER_QUOTA; 298 event_.what_changed |= AllStatusEvent::OVER_QUOTA;
298 } 299 }
299 300
300 } // namespace browser_sync 301 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/all_status.h ('k') | chrome/browser/sync/engine/syncapi.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698