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

Side by Side Diff: chrome/browser/sync/engine/syncer_thread.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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 #include "chrome/browser/sync/engine/syncer_thread.h" 4 #include "chrome/browser/sync/engine/syncer_thread.h"
5 5
6 #include "build/build_config.h" 6 #include "build/build_config.h"
7 7
8 #if defined(OS_MACOSX) 8 #if defined(OS_MACOSX)
9 #include <CoreFoundation/CFNumber.h> 9 #include <CoreFoundation/CFNumber.h>
10 #include <IOKit/IOTypes.h> 10 #include <IOKit/IOTypes.h>
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 allstatus_(all_status), 67 allstatus_(all_status),
68 syncer_short_poll_interval_seconds_(kDefaultShortPollIntervalSeconds), 68 syncer_short_poll_interval_seconds_(kDefaultShortPollIntervalSeconds),
69 syncer_long_poll_interval_seconds_(kDefaultLongPollIntervalSeconds), 69 syncer_long_poll_interval_seconds_(kDefaultLongPollIntervalSeconds),
70 syncer_polling_interval_(kDefaultShortPollIntervalSeconds), 70 syncer_polling_interval_(kDefaultShortPollIntervalSeconds),
71 syncer_max_interval_(kDefaultMaxPollIntervalMs), 71 syncer_max_interval_(kDefaultMaxPollIntervalMs),
72 directory_manager_hookup_(NULL), 72 directory_manager_hookup_(NULL),
73 syncer_events_(NULL), 73 syncer_events_(NULL),
74 session_context_(context), 74 session_context_(context),
75 disable_idle_detection_(false) { 75 disable_idle_detection_(false) {
76 DCHECK(context); 76 DCHECK(context);
77 syncer_event_relay_channel_.reset(new SyncerEventChannel(SyncerEvent( 77 syncer_event_relay_channel_.reset(new SyncerEventChannel());
78 SyncerEvent::SHUTDOWN_USE_WITH_CARE)));
79 78
80 if (context->directory_manager()) { 79 if (context->directory_manager()) {
81 directory_manager_hookup_.reset(NewEventListenerHookup( 80 directory_manager_hookup_.reset(NewEventListenerHookup(
82 context->directory_manager()->channel(), this, 81 context->directory_manager()->channel(), this,
83 &SyncerThread::HandleDirectoryManagerEvent)); 82 &SyncerThread::HandleDirectoryManagerEvent));
84 } 83 }
85 84
86 if (context->connection_manager()) 85 if (context->connection_manager())
87 WatchConnectionManager(context->connection_manager()); 86 WatchConnectionManager(context->connection_manager());
88 87
89 } 88 }
90 89
91 SyncerThread::~SyncerThread() { 90 SyncerThread::~SyncerThread() {
92 conn_mgr_hookup_.reset(); 91 conn_mgr_hookup_.reset();
92 syncer_event_relay_channel_->Notify(SyncerEvent(
93 SyncerEvent::SHUTDOWN_USE_WITH_CARE));
93 syncer_event_relay_channel_.reset(); 94 syncer_event_relay_channel_.reset();
94 directory_manager_hookup_.reset(); 95 directory_manager_hookup_.reset();
95 syncer_events_.reset(); 96 syncer_events_.reset();
96 delete vault_.syncer_; 97 delete vault_.syncer_;
97 CHECK(!thread_.IsRunning()); 98 CHECK(!thread_.IsRunning());
98 } 99 }
99 100
100 // Creates and starts a syncer thread. 101 // Creates and starts a syncer thread.
101 // Returns true if it creates a thread or if there's currently a thread running 102 // Returns true if it creates a thread or if there's currently a thread running
102 // and false otherwise. 103 // and false otherwise.
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 &user_idle_milliseconds, &continue_sync_cycle, nudged); 299 &user_idle_milliseconds, &continue_sync_cycle, nudged);
299 } 300 }
300 #if defined(OS_LINUX) 301 #if defined(OS_LINUX)
301 idle_query_.reset(); 302 idle_query_.reset();
302 #endif 303 #endif
303 } 304 }
304 305
305 void SyncerThread::PauseUntilResumedOrQuit() { 306 void SyncerThread::PauseUntilResumedOrQuit() {
306 LOG(INFO) << "Syncer thread entering pause."; 307 LOG(INFO) << "Syncer thread entering pause.";
307 SyncerEvent event(SyncerEvent::PAUSED); 308 SyncerEvent event(SyncerEvent::PAUSED);
308 relay_channel()->NotifyListeners(event); 309 relay_channel()->Notify(event);
309 310
310 // Thread will get stuck here until either a resume is requested 311 // Thread will get stuck here until either a resume is requested
311 // or shutdown is started. 312 // or shutdown is started.
312 while (vault_.pause_ && !vault_.stop_syncer_thread_) 313 while (vault_.pause_ && !vault_.stop_syncer_thread_)
313 vault_field_changed_.Wait(); 314 vault_field_changed_.Wait();
314 315
315 // Notify that we have resumed if we are not shutting down. 316 // Notify that we have resumed if we are not shutting down.
316 if (!vault_.stop_syncer_thread_) { 317 if (!vault_.stop_syncer_thread_) {
317 SyncerEvent event(SyncerEvent::RESUMED); 318 SyncerEvent event(SyncerEvent::RESUMED);
318 relay_channel()->NotifyListeners(event); 319 relay_channel()->Notify(event);
319 } 320 }
320 LOG(INFO) << "Syncer thread exiting pause."; 321 LOG(INFO) << "Syncer thread exiting pause.";
321 } 322 }
322 323
323 // We check how long the user's been idle and sync less often if the machine is 324 // We check how long the user's been idle and sync less often if the machine is
324 // not in use. The aim is to reduce server load. 325 // not in use. The aim is to reduce server load.
325 // TODO(timsteele): Should use Time(Delta). 326 // TODO(timsteele): Should use Time(Delta).
326 SyncerThread::WaitInterval SyncerThread::CalculatePollingWaitTime( 327 SyncerThread::WaitInterval SyncerThread::CalculatePollingWaitTime(
327 const AllStatus::Status& status, 328 const AllStatus::Status& status,
328 int last_poll_wait, // Time in seconds. 329 int last_poll_wait, // Time in seconds.
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 break; 473 break;
473 case kUnknown: 474 case kUnknown:
474 default: 475 default:
475 updates_source = sync_pb::GetUpdatesCallerInfo::UNKNOWN; 476 updates_source = sync_pb::GetUpdatesCallerInfo::UNKNOWN;
476 break; 477 break;
477 } 478 }
478 } 479 }
479 vault_.syncer_->set_updates_source(updates_source); 480 vault_.syncer_->set_updates_source(updates_source);
480 } 481 }
481 482
482 void SyncerThread::HandleSyncerEvent(const SyncerEvent& event) { 483 void SyncerThread::HandleChannelEvent(const SyncerEvent& event) {
483 AutoLock lock(lock_); 484 AutoLock lock(lock_);
484 relay_channel()->NotifyListeners(event); 485 relay_channel()->Notify(event);
485 if (SyncerEvent::REQUEST_SYNC_NUDGE != event.what_happened) { 486 if (SyncerEvent::REQUEST_SYNC_NUDGE != event.what_happened) {
486 return; 487 return;
487 } 488 }
488 NudgeSyncImpl(event.nudge_delay_milliseconds, kUnknown); 489 NudgeSyncImpl(event.nudge_delay_milliseconds, kUnknown);
489 } 490 }
490 491
491 void SyncerThread::HandleDirectoryManagerEvent( 492 void SyncerThread::HandleDirectoryManagerEvent(
492 const syncable::DirectoryManagerEvent& event) { 493 const syncable::DirectoryManagerEvent& event) {
493 LOG(INFO) << "Handling a directory manager event"; 494 LOG(INFO) << "Handling a directory manager event";
494 if (syncable::DirectoryManagerEvent::OPENED == event.what_happened) { 495 if (syncable::DirectoryManagerEvent::OPENED == event.what_happened) {
495 AutoLock lock(lock_); 496 AutoLock lock(lock_);
496 LOG(INFO) << "Syncer starting up for: " << event.dirname; 497 LOG(INFO) << "Syncer starting up for: " << event.dirname;
497 // The underlying database structure is ready, and we should create 498 // The underlying database structure is ready, and we should create
498 // the syncer. 499 // the syncer.
499 CHECK(vault_.syncer_ == NULL); 500 CHECK(vault_.syncer_ == NULL);
500 session_context_->set_account_name(event.dirname); 501 session_context_->set_account_name(event.dirname);
501 vault_.syncer_ = new Syncer(session_context_.get()); 502 vault_.syncer_ = new Syncer(session_context_.get());
502 503
503 syncer_events_.reset(NewEventListenerHookup( 504 syncer_events_.reset(
504 session_context_->syncer_event_channel(), this, 505 session_context_->syncer_event_channel()->AddObserver(this));
505 &SyncerThread::HandleSyncerEvent));
506 vault_field_changed_.Broadcast(); 506 vault_field_changed_.Broadcast();
507 } 507 }
508 } 508 }
509 509
510 // Sets |*connected| to false if it is currently true but |code| suggests that 510 // Sets |*connected| to false if it is currently true but |code| suggests that
511 // the current network configuration and/or auth state cannot be used to make 511 // the current network configuration and/or auth state cannot be used to make
512 // forward progress, and user intervention (e.g changing server URL or auth 512 // forward progress, and user intervention (e.g changing server URL or auth
513 // credentials) is likely necessary. If |*connected| is false, set it to true 513 // credentials) is likely necessary. If |*connected| is false, set it to true
514 // if |code| suggests that we just recently made healthy contact with the 514 // if |code| suggests that we just recently made healthy contact with the
515 // server. 515 // server.
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 was_logged = true; 673 was_logged = true;
674 LOG(INFO) << "UserIdleTime unimplemented on this platform, " 674 LOG(INFO) << "UserIdleTime unimplemented on this platform, "
675 "synchronization will not throttle when user idle"; 675 "synchronization will not throttle when user idle";
676 } 676 }
677 #endif 677 #endif
678 678
679 return 0; 679 return 0;
680 } 680 }
681 681
682 } // namespace browser_sync 682 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/syncer_thread.h ('k') | chrome/browser/sync/engine/syncer_thread_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698