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 #include "chrome/browser/sync/engine/sync_scheduler.h" | 5 #include "chrome/browser/sync/engine/sync_scheduler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstring> | 8 #include <cstring> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
15 #include "base/rand_util.h" | 15 #include "base/rand_util.h" |
16 #include "chrome/browser/sync/engine/syncer.h" | 16 #include "chrome/browser/sync/engine/syncer.h" |
17 #include "chrome/browser/sync/protocol/sync.pb.h" | 17 #include "chrome/browser/sync/protocol/sync.pb.h" |
18 #include "chrome/browser/sync/protocol/proto_enum_conversions.h" | 18 #include "chrome/browser/sync/protocol/proto_enum_conversions.h" |
19 #include "chrome/browser/sync/util/logging.h" | 19 #include "chrome/browser/sync/util/logging.h" |
20 | 20 |
21 using base::TimeDelta; | 21 using base::TimeDelta; |
22 using base::TimeTicks; | 22 using base::TimeTicks; |
23 | 23 |
24 namespace browser_sync { | 24 namespace browser_sync { |
25 | 25 |
26 using sessions::SyncSession; | 26 using sessions::SyncSession; |
27 using sessions::SyncSessionSnapshot; | 27 using sessions::SyncSessionSnapshot; |
28 using sessions::SyncSourceInfo; | 28 using sessions::SyncSourceInfo; |
| 29 using syncable::ModelEnumSet; |
| 30 using syncable::ModelEnumSetToString; |
29 using syncable::ModelTypePayloadMap; | 31 using syncable::ModelTypePayloadMap; |
30 using syncable::ModelTypeBitSet; | |
31 using sync_pb::GetUpdatesCallerInfo; | 32 using sync_pb::GetUpdatesCallerInfo; |
32 | 33 |
33 namespace { | 34 namespace { |
34 bool ShouldRequestEarlyExit( | 35 bool ShouldRequestEarlyExit( |
35 const browser_sync::SyncProtocolError& error) { | 36 const browser_sync::SyncProtocolError& error) { |
36 switch (error.error_type) { | 37 switch (error.error_type) { |
37 case browser_sync::SYNC_SUCCESS: | 38 case browser_sync::SYNC_SUCCESS: |
38 case browser_sync::MIGRATION_DONE: | 39 case browser_sync::MIGRATION_DONE: |
39 case browser_sync::THROTTLED: | 40 case browser_sync::THROTTLED: |
40 case browser_sync::TRANSIENT_ERROR: | 41 case browser_sync::TRANSIENT_ERROR: |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 // functions, too. | 453 // functions, too. |
453 void SyncScheduler::ScheduleCleanupDisabledTypes() { | 454 void SyncScheduler::ScheduleCleanupDisabledTypes() { |
454 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 455 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
455 ScheduleSyncSessionJob( | 456 ScheduleSyncSessionJob( |
456 TimeDelta::FromSeconds(0), SyncSessionJob::CLEANUP_DISABLED_TYPES, | 457 TimeDelta::FromSeconds(0), SyncSessionJob::CLEANUP_DISABLED_TYPES, |
457 CreateSyncSession(SyncSourceInfo()), FROM_HERE); | 458 CreateSyncSession(SyncSourceInfo()), FROM_HERE); |
458 } | 459 } |
459 | 460 |
460 void SyncScheduler::ScheduleNudge( | 461 void SyncScheduler::ScheduleNudge( |
461 const TimeDelta& delay, | 462 const TimeDelta& delay, |
462 NudgeSource source, syncable::ModelEnumSet types, | 463 NudgeSource source, ModelEnumSet types, |
463 const tracked_objects::Location& nudge_location) { | 464 const tracked_objects::Location& nudge_location) { |
464 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 465 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
465 SDVLOG_LOC(nudge_location, 2) | 466 SDVLOG_LOC(nudge_location, 2) |
466 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, " | 467 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, " |
467 << "source " << GetNudgeSourceString(source) << ", " | 468 << "source " << GetNudgeSourceString(source) << ", " |
468 << "types " << syncable::ModelEnumSetToString(types); | 469 << "types " << ModelEnumSetToString(types); |
469 | 470 |
470 ModelTypePayloadMap types_with_payloads = | 471 ModelTypePayloadMap types_with_payloads = |
471 syncable::ModelTypePayloadMapFromEnumSet(types, std::string()); | 472 syncable::ModelTypePayloadMapFromEnumSet(types, std::string()); |
472 PostTask(nudge_location, "ScheduleNudgeImpl", | 473 PostTask(nudge_location, "ScheduleNudgeImpl", |
473 base::Bind(&SyncScheduler::ScheduleNudgeImpl, | 474 base::Bind(&SyncScheduler::ScheduleNudgeImpl, |
474 weak_ptr_factory_.GetWeakPtr(), | 475 weak_ptr_factory_.GetWeakPtr(), |
475 delay, | 476 delay, |
476 GetUpdatesFromNudgeSource(source), | 477 GetUpdatesFromNudgeSource(source), |
477 types_with_payloads, | 478 types_with_payloads, |
478 false, | 479 false, |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 } | 556 } |
556 } | 557 } |
557 | 558 |
558 // TODO(lipalani) - pass the job itself to ScheduleSyncSessionJob. | 559 // TODO(lipalani) - pass the job itself to ScheduleSyncSessionJob. |
559 ScheduleSyncSessionJob(delay, SyncSessionJob::NUDGE, job.session.release(), | 560 ScheduleSyncSessionJob(delay, SyncSessionJob::NUDGE, job.session.release(), |
560 nudge_location); | 561 nudge_location); |
561 } | 562 } |
562 | 563 |
563 // Helper to extract the routing info and workers corresponding to types in | 564 // Helper to extract the routing info and workers corresponding to types in |
564 // |types| from |registrar|. | 565 // |types| from |registrar|. |
565 void GetModelSafeParamsForTypes(syncable::ModelEnumSet types, | 566 void GetModelSafeParamsForTypes(ModelEnumSet types, |
566 ModelSafeWorkerRegistrar* registrar, ModelSafeRoutingInfo* routes, | 567 ModelSafeWorkerRegistrar* registrar, ModelSafeRoutingInfo* routes, |
567 std::vector<ModelSafeWorker*>* workers) { | 568 std::vector<ModelSafeWorker*>* workers) { |
568 ModelSafeRoutingInfo r_tmp; | 569 ModelSafeRoutingInfo r_tmp; |
569 std::vector<ModelSafeWorker*> w_tmp; | 570 std::vector<ModelSafeWorker*> w_tmp; |
570 registrar->GetModelSafeRoutingInfo(&r_tmp); | 571 registrar->GetModelSafeRoutingInfo(&r_tmp); |
571 registrar->GetWorkers(&w_tmp); | 572 registrar->GetWorkers(&w_tmp); |
572 | 573 |
573 bool passive_group_added = false; | 574 bool passive_group_added = false; |
574 | 575 |
575 typedef std::vector<ModelSafeWorker*>::const_iterator iter; | 576 typedef std::vector<ModelSafeWorker*>::const_iterator iter; |
576 for (syncable::ModelEnumSet::Iterator it = types.First(); | 577 for (ModelEnumSet::Iterator it = types.First(); |
577 it.Good(); it.Inc()) { | 578 it.Good(); it.Inc()) { |
578 const syncable::ModelType t = it.Get(); | 579 const syncable::ModelType t = it.Get(); |
579 DCHECK_EQ(1U, r_tmp.count(t)); | 580 DCHECK_EQ(1U, r_tmp.count(t)); |
580 (*routes)[t] = r_tmp[t]; | 581 (*routes)[t] = r_tmp[t]; |
581 iter w_tmp_it = std::find_if(w_tmp.begin(), w_tmp.end(), | 582 iter w_tmp_it = std::find_if(w_tmp.begin(), w_tmp.end(), |
582 ModelSafeWorkerGroupIs(r_tmp[t])); | 583 ModelSafeWorkerGroupIs(r_tmp[t])); |
583 if (w_tmp_it != w_tmp.end()) { | 584 if (w_tmp_it != w_tmp.end()) { |
584 iter workers_it = std::find_if(workers->begin(), workers->end(), | 585 iter workers_it = std::find_if(workers->begin(), workers->end(), |
585 ModelSafeWorkerGroupIs(r_tmp[t])); | 586 ModelSafeWorkerGroupIs(r_tmp[t])); |
586 if (workers_it == workers->end()) | 587 if (workers_it == workers->end()) |
(...skipping 11 matching lines...) Expand all Loading... |
598 iter it = std::find_if(w_tmp.begin(), w_tmp.end(), | 599 iter it = std::find_if(w_tmp.begin(), w_tmp.end(), |
599 ModelSafeWorkerGroupIs(GROUP_PASSIVE)); | 600 ModelSafeWorkerGroupIs(GROUP_PASSIVE)); |
600 if (it != w_tmp.end()) | 601 if (it != w_tmp.end()) |
601 workers->push_back(*it); | 602 workers->push_back(*it); |
602 else | 603 else |
603 NOTREACHED(); | 604 NOTREACHED(); |
604 } | 605 } |
605 } | 606 } |
606 | 607 |
607 void SyncScheduler::ScheduleConfig( | 608 void SyncScheduler::ScheduleConfig( |
608 syncable::ModelEnumSet types, | 609 ModelEnumSet types, |
609 GetUpdatesCallerInfo::GetUpdatesSource source) { | 610 GetUpdatesCallerInfo::GetUpdatesSource source) { |
610 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 611 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
611 DCHECK(IsConfigRelatedUpdateSourceValue(source)); | 612 DCHECK(IsConfigRelatedUpdateSourceValue(source)); |
612 SDVLOG(2) << "Scheduling a config"; | 613 SDVLOG(2) << "Scheduling a config"; |
613 ModelSafeRoutingInfo routes; | 614 ModelSafeRoutingInfo routes; |
614 std::vector<ModelSafeWorker*> workers; | 615 std::vector<ModelSafeWorker*> workers; |
615 GetModelSafeParamsForTypes(types, session_context_->registrar(), | 616 GetModelSafeParamsForTypes(types, session_context_->registrar(), |
616 &routes, &workers); | 617 &routes, &workers); |
617 | 618 |
618 PostTask(FROM_HERE, "ScheduleConfigImpl", | 619 PostTask(FROM_HERE, "ScheduleConfigImpl", |
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1186 | 1187 |
1187 #undef SDVLOG_LOC | 1188 #undef SDVLOG_LOC |
1188 | 1189 |
1189 #undef SDVLOG | 1190 #undef SDVLOG |
1190 | 1191 |
1191 #undef SLOG | 1192 #undef SLOG |
1192 | 1193 |
1193 #undef ENUM_CASE | 1194 #undef ENUM_CASE |
1194 | 1195 |
1195 } // browser_sync | 1196 } // browser_sync |
OLD | NEW |