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

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

Issue 3305003: New authorization framework for sync. ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 3 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) 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>
11 #include <IOKit/IOKitLib.h> 11 #include <IOKit/IOKitLib.h>
12 #endif 12 #endif
13 13
14 #include <algorithm> 14 #include <algorithm>
15 #include <map> 15 #include <map>
16 #include <queue> 16 #include <queue>
17 17
18 #include "base/rand_util.h" 18 #include "base/rand_util.h"
19 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" 19 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
20 #include "chrome/browser/sync/engine/auth_watcher.h"
21 #include "chrome/browser/sync/engine/model_safe_worker.h" 20 #include "chrome/browser/sync/engine/model_safe_worker.h"
22 #include "chrome/browser/sync/engine/net/server_connection_manager.h" 21 #include "chrome/browser/sync/engine/net/server_connection_manager.h"
23 #include "chrome/browser/sync/engine/syncer.h" 22 #include "chrome/browser/sync/engine/syncer.h"
24 #include "chrome/browser/sync/sessions/session_state.h" 23 #include "chrome/browser/sync/sessions/session_state.h"
25 #include "chrome/browser/sync/syncable/directory_manager.h"
26 #include "chrome/common/chrome_switches.h" 24 #include "chrome/common/chrome_switches.h"
27 #include "jingle/notifier/listener/notification_constants.h" 25 #include "jingle/notifier/listener/notification_constants.h"
28 26
29 using std::priority_queue; 27 using std::priority_queue;
30 using std::min; 28 using std::min;
31 using base::Time; 29 using base::Time;
32 using base::TimeDelta; 30 using base::TimeDelta;
33 using base::TimeTicks; 31 using base::TimeTicks;
34 32
35 namespace browser_sync { 33 namespace browser_sync {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 : thread_main_started_(false, false), 66 : thread_main_started_(false, false),
69 thread_("SyncEngine_SyncerThread"), 67 thread_("SyncEngine_SyncerThread"),
70 vault_field_changed_(&lock_), 68 vault_field_changed_(&lock_),
71 p2p_authenticated_(false), 69 p2p_authenticated_(false),
72 p2p_subscribed_(false), 70 p2p_subscribed_(false),
73 conn_mgr_hookup_(NULL), 71 conn_mgr_hookup_(NULL),
74 syncer_short_poll_interval_seconds_(kDefaultShortPollIntervalSeconds), 72 syncer_short_poll_interval_seconds_(kDefaultShortPollIntervalSeconds),
75 syncer_long_poll_interval_seconds_(kDefaultLongPollIntervalSeconds), 73 syncer_long_poll_interval_seconds_(kDefaultLongPollIntervalSeconds),
76 syncer_polling_interval_(kDefaultShortPollIntervalSeconds), 74 syncer_polling_interval_(kDefaultShortPollIntervalSeconds),
77 syncer_max_interval_(kDefaultMaxPollIntervalMs), 75 syncer_max_interval_(kDefaultMaxPollIntervalMs),
78 directory_manager_hookup_(NULL),
79 syncer_events_(NULL), 76 syncer_events_(NULL),
80 session_context_(context), 77 session_context_(context),
81 disable_idle_detection_(false) { 78 disable_idle_detection_(false) {
82 DCHECK(context); 79 DCHECK(context);
83 syncer_event_relay_channel_.reset(new SyncerEventChannel()); 80 syncer_event_relay_channel_.reset(new SyncerEventChannel());
84 81
85 if (context->directory_manager()) {
86 directory_manager_hookup_.reset(NewEventListenerHookup(
87 context->directory_manager()->channel(), this,
88 &SyncerThread::HandleDirectoryManagerEvent));
89 }
90
91 if (context->connection_manager()) 82 if (context->connection_manager())
92 WatchConnectionManager(context->connection_manager()); 83 WatchConnectionManager(context->connection_manager());
93 84
94 } 85 }
95 86
96 SyncerThread::~SyncerThread() { 87 SyncerThread::~SyncerThread() {
97 conn_mgr_hookup_.reset(); 88 conn_mgr_hookup_.reset();
98 syncer_event_relay_channel_->Notify(SyncerEvent( 89 syncer_event_relay_channel_->Notify(SyncerEvent(
99 SyncerEvent::SHUTDOWN_USE_WITH_CARE)); 90 SyncerEvent::SHUTDOWN_USE_WITH_CARE));
100 syncer_event_relay_channel_.reset(); 91 syncer_event_relay_channel_.reset();
101 directory_manager_hookup_.reset();
102 syncer_events_.reset(); 92 syncer_events_.reset();
103 delete vault_.syncer_; 93 delete vault_.syncer_;
104 CHECK(!thread_.IsRunning()); 94 CHECK(!thread_.IsRunning());
105 } 95 }
106 96
107 // Creates and starts a syncer thread. 97 // Creates and starts a syncer thread.
108 // Returns true if it creates a thread or if there's currently a thread running 98 // Returns true if it creates a thread or if there's currently a thread running
109 // and false otherwise. 99 // and false otherwise.
110 bool SyncerThread::Start() { 100 bool SyncerThread::Start() {
111 { 101 {
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 570
581 void SyncerThread::HandleChannelEvent(const SyncerEvent& event) { 571 void SyncerThread::HandleChannelEvent(const SyncerEvent& event) {
582 AutoLock lock(lock_); 572 AutoLock lock(lock_);
583 relay_channel()->Notify(event); 573 relay_channel()->Notify(event);
584 if (SyncerEvent::REQUEST_SYNC_NUDGE != event.what_happened) { 574 if (SyncerEvent::REQUEST_SYNC_NUDGE != event.what_happened) {
585 return; 575 return;
586 } 576 }
587 NudgeSyncImpl(event.nudge_delay_milliseconds, kUnknown); 577 NudgeSyncImpl(event.nudge_delay_milliseconds, kUnknown);
588 } 578 }
589 579
590 void SyncerThread::HandleDirectoryManagerEvent( 580 void SyncerThread::CreateSyncer(const std::string& dirname) {
591 const syncable::DirectoryManagerEvent& event) { 581 AutoLock lock(lock_);
592 LOG(INFO) << "Handling a directory manager event"; 582 LOG(INFO) << "Creating syncer up for: " << dirname;
593 if (syncable::DirectoryManagerEvent::OPENED == event.what_happened) { 583 // The underlying database structure is ready, and we should create
594 AutoLock lock(lock_); 584 // the syncer.
595 LOG(INFO) << "Syncer starting up for: " << event.dirname; 585 CHECK(vault_.syncer_ == NULL);
596 // The underlying database structure is ready, and we should create 586 session_context_->set_account_name(dirname);
597 // the syncer. 587 vault_.syncer_ = new Syncer(session_context_.get());
598 CHECK(vault_.syncer_ == NULL);
599 session_context_->set_account_name(event.dirname);
600 vault_.syncer_ = new Syncer(session_context_.get());
601 588
602 syncer_events_.reset( 589 syncer_events_.reset(
603 session_context_->syncer_event_channel()->AddObserver(this)); 590 session_context_->syncer_event_channel()->AddObserver(this));
604 vault_field_changed_.Broadcast(); 591 vault_field_changed_.Broadcast();
605 }
606 } 592 }
607 593
608 // Sets |*connected| to false if it is currently true but |code| suggests that 594 // Sets |*connected| to false if it is currently true but |code| suggests that
609 // the current network configuration and/or auth state cannot be used to make 595 // the current network configuration and/or auth state cannot be used to make
610 // forward progress, and user intervention (e.g changing server URL or auth 596 // forward progress, and user intervention (e.g changing server URL or auth
611 // credentials) is likely necessary. If |*connected| is false, set it to true 597 // credentials) is likely necessary. If |*connected| is false, set it to true
612 // if |code| suggests that we just recently made healthy contact with the 598 // if |code| suggests that we just recently made healthy contact with the
613 // server. 599 // server.
614 static inline void CheckConnected(bool* connected, 600 static inline void CheckConnected(bool* connected,
615 HttpResponse::ServerConnectionCode code, 601 HttpResponse::ServerConnectionCode code,
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 was_logged = true; 778 was_logged = true;
793 LOG(INFO) << "UserIdleTime unimplemented on this platform, " 779 LOG(INFO) << "UserIdleTime unimplemented on this platform, "
794 "synchronization will not throttle when user idle"; 780 "synchronization will not throttle when user idle";
795 } 781 }
796 #endif 782 #endif
797 783
798 return 0; 784 return 0;
799 } 785 }
800 786
801 } // namespace browser_sync 787 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698