OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // A class to run the syncer on a thread. | 5 // A class to run the syncer on a thread. |
6 #ifndef CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD_H_ | 6 #ifndef CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD_H_ |
7 #define CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD_H_ | 7 #define CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD_H_ |
8 #pragma once | 8 #pragma once |
9 | 9 |
| 10 #include <string> |
| 11 |
10 #include "base/callback.h" | 12 #include "base/callback.h" |
11 #include "base/memory/linked_ptr.h" | 13 #include "base/memory/linked_ptr.h" |
12 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
13 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
14 #include "base/task.h" | 16 #include "base/task.h" |
15 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
16 #include "base/time.h" | 18 #include "base/time.h" |
17 #include "base/timer.h" | 19 #include "base/timer.h" |
18 #include "chrome/browser/sync/engine/configure_reason.h" | 20 #include "chrome/browser/sync/engine/configure_reason.h" |
19 #include "chrome/browser/sync/engine/nudge_source.h" | 21 #include "chrome/browser/sync/engine/nudge_source.h" |
(...skipping 16 matching lines...) Expand all Loading... |
36 // In this mode, the thread only performs configuration tasks. This is | 38 // In this mode, the thread only performs configuration tasks. This is |
37 // designed to make the case where we want to download updates for a | 39 // designed to make the case where we want to download updates for a |
38 // specific type only, and not continue syncing until we are moved into | 40 // specific type only, and not continue syncing until we are moved into |
39 // normal mode. | 41 // normal mode. |
40 CONFIGURATION_MODE, | 42 CONFIGURATION_MODE, |
41 // Resumes polling and allows nudges, drops configuration tasks. Runs | 43 // Resumes polling and allows nudges, drops configuration tasks. Runs |
42 // through entire sync cycle. | 44 // through entire sync cycle. |
43 NORMAL_MODE, | 45 NORMAL_MODE, |
44 }; | 46 }; |
45 | 47 |
46 // Takes ownership of both |context| and |syncer|. | 48 // |name| is a display string to identify the syncer thread. Takes |
47 SyncerThread(sessions::SyncSessionContext* context, Syncer* syncer); | 49 // |ownership of both |context| and |syncer|. |
| 50 SyncerThread(const std::string& name, |
| 51 sessions::SyncSessionContext* context, Syncer* syncer); |
48 virtual ~SyncerThread(); | 52 virtual ~SyncerThread(); |
49 | 53 |
50 typedef Callback0::Type ModeChangeCallback; | 54 typedef Callback0::Type ModeChangeCallback; |
51 | 55 |
52 // Change the mode of operation. | 56 // Change the mode of operation. |
53 // We don't use a lock when changing modes, so we won't cause currently | 57 // We don't use a lock when changing modes, so we won't cause currently |
54 // scheduled jobs to adhere to the new mode. We could protect it, but it | 58 // scheduled jobs to adhere to the new mode. We could protect it, but it |
55 // doesn't buy very much as a) a session could already be in progress and it | 59 // doesn't buy very much as a) a session could already be in progress and it |
56 // will continue no matter what, b) the scheduled sessions already contain | 60 // will continue no matter what, b) the scheduled sessions already contain |
57 // all their required state and won't be affected by potential change at | 61 // all their required state and won't be affected by potential change at |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 | 295 |
292 // Used to update |server_connection_ok_|, see below. | 296 // Used to update |server_connection_ok_|, see below. |
293 void CheckServerConnectionManagerStatus( | 297 void CheckServerConnectionManagerStatus( |
294 HttpResponse::ServerConnectionCode code); | 298 HttpResponse::ServerConnectionCode code); |
295 | 299 |
296 // Called once the first time thread_ is started to broadcast an initial | 300 // Called once the first time thread_ is started to broadcast an initial |
297 // session snapshot containing data like initial_sync_ended. Important when | 301 // session snapshot containing data like initial_sync_ended. Important when |
298 // the client starts up and does not need to perform an initial sync. | 302 // the client starts up and does not need to perform an initial sync. |
299 void SendInitialSnapshot(); | 303 void SendInitialSnapshot(); |
300 | 304 |
| 305 const std::string name_; |
| 306 |
301 base::Thread thread_; | 307 base::Thread thread_; |
302 | 308 |
303 // Modifiable versions of kDefaultLongPollIntervalSeconds which can be | 309 // Modifiable versions of kDefaultLongPollIntervalSeconds which can be |
304 // updated by the server. | 310 // updated by the server. |
305 base::TimeDelta syncer_short_poll_interval_seconds_; | 311 base::TimeDelta syncer_short_poll_interval_seconds_; |
306 base::TimeDelta syncer_long_poll_interval_seconds_; | 312 base::TimeDelta syncer_long_poll_interval_seconds_; |
307 | 313 |
308 // Periodic timer for polling. See AdjustPolling. | 314 // Periodic timer for polling. See AdjustPolling. |
309 base::RepeatingTimer<SyncerThread> poll_timer_; | 315 base::RepeatingTimer<SyncerThread> poll_timer_; |
310 | 316 |
(...skipping 23 matching lines...) Expand all Loading... |
334 DISALLOW_COPY_AND_ASSIGN(SyncerThread); | 340 DISALLOW_COPY_AND_ASSIGN(SyncerThread); |
335 }; | 341 }; |
336 | 342 |
337 } // namespace browser_sync | 343 } // namespace browser_sync |
338 | 344 |
339 // The SyncerThread manages its own internal thread and thus outlives it. We | 345 // The SyncerThread manages its own internal thread and thus outlives it. We |
340 // don't need refcounting for posting tasks to this internal thread. | 346 // don't need refcounting for posting tasks to this internal thread. |
341 DISABLE_RUNNABLE_METHOD_REFCOUNT(browser_sync::SyncerThread); | 347 DISABLE_RUNNABLE_METHOD_REFCOUNT(browser_sync::SyncerThread); |
342 | 348 |
343 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD_H_ | 349 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD_H_ |
OLD | NEW |