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

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

Issue 8772074: [Sync] Convert syncable/ directory to ModelEnumSet (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix typo Created 9 years 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) 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"
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 // functions, too. 452 // functions, too.
453 void SyncScheduler::ScheduleCleanupDisabledTypes() { 453 void SyncScheduler::ScheduleCleanupDisabledTypes() {
454 DCHECK_EQ(MessageLoop::current(), sync_loop_); 454 DCHECK_EQ(MessageLoop::current(), sync_loop_);
455 ScheduleSyncSessionJob( 455 ScheduleSyncSessionJob(
456 TimeDelta::FromSeconds(0), SyncSessionJob::CLEANUP_DISABLED_TYPES, 456 TimeDelta::FromSeconds(0), SyncSessionJob::CLEANUP_DISABLED_TYPES,
457 CreateSyncSession(SyncSourceInfo()), FROM_HERE); 457 CreateSyncSession(SyncSourceInfo()), FROM_HERE);
458 } 458 }
459 459
460 void SyncScheduler::ScheduleNudge( 460 void SyncScheduler::ScheduleNudge(
461 const TimeDelta& delay, 461 const TimeDelta& delay,
462 NudgeSource source, const ModelTypeBitSet& types, 462 NudgeSource source, syncable::ModelEnumSet types,
463 const tracked_objects::Location& nudge_location) { 463 const tracked_objects::Location& nudge_location) {
464 DCHECK_EQ(MessageLoop::current(), sync_loop_); 464 DCHECK_EQ(MessageLoop::current(), sync_loop_);
465 SDVLOG_LOC(nudge_location, 2) 465 SDVLOG_LOC(nudge_location, 2)
466 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, " 466 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, "
467 << "source " << GetNudgeSourceString(source) << ", " 467 << "source " << GetNudgeSourceString(source) << ", "
468 << "types " << syncable::ModelTypeBitSetToString(types); 468 << "types " << syncable::ModelEnumSetToString(types);
469 469
470 ModelTypePayloadMap types_with_payloads = 470 ModelTypePayloadMap types_with_payloads =
471 syncable::ModelTypePayloadMapFromBitSet(types, std::string()); 471 syncable::ModelTypePayloadMapFromEnumSet(types, std::string());
472 PostTask(nudge_location, "ScheduleNudgeImpl", 472 PostTask(nudge_location, "ScheduleNudgeImpl",
473 base::Bind(&SyncScheduler::ScheduleNudgeImpl, 473 base::Bind(&SyncScheduler::ScheduleNudgeImpl,
474 weak_ptr_factory_.GetWeakPtr(), 474 weak_ptr_factory_.GetWeakPtr(),
475 delay, 475 delay,
476 GetUpdatesFromNudgeSource(source), 476 GetUpdatesFromNudgeSource(source),
477 types_with_payloads, 477 types_with_payloads,
478 false, 478 false,
479 nudge_location)); 479 nudge_location));
480 } 480 }
481 481
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 } 555 }
556 } 556 }
557 557
558 // TODO(lipalani) - pass the job itself to ScheduleSyncSessionJob. 558 // TODO(lipalani) - pass the job itself to ScheduleSyncSessionJob.
559 ScheduleSyncSessionJob(delay, SyncSessionJob::NUDGE, job.session.release(), 559 ScheduleSyncSessionJob(delay, SyncSessionJob::NUDGE, job.session.release(),
560 nudge_location); 560 nudge_location);
561 } 561 }
562 562
563 // Helper to extract the routing info and workers corresponding to types in 563 // Helper to extract the routing info and workers corresponding to types in
564 // |types| from |registrar|. 564 // |types| from |registrar|.
565 void GetModelSafeParamsForTypes(const ModelTypeBitSet& types, 565 void GetModelSafeParamsForTypes(syncable::ModelEnumSet types,
566 ModelSafeWorkerRegistrar* registrar, ModelSafeRoutingInfo* routes, 566 ModelSafeWorkerRegistrar* registrar, ModelSafeRoutingInfo* routes,
567 std::vector<ModelSafeWorker*>* workers) { 567 std::vector<ModelSafeWorker*>* workers) {
568 ModelSafeRoutingInfo r_tmp; 568 ModelSafeRoutingInfo r_tmp;
569 std::vector<ModelSafeWorker*> w_tmp; 569 std::vector<ModelSafeWorker*> w_tmp;
570 registrar->GetModelSafeRoutingInfo(&r_tmp); 570 registrar->GetModelSafeRoutingInfo(&r_tmp);
571 registrar->GetWorkers(&w_tmp); 571 registrar->GetWorkers(&w_tmp);
572 572
573 bool passive_group_added = false; 573 bool passive_group_added = false;
574 574
575 typedef std::vector<ModelSafeWorker*>::const_iterator iter; 575 typedef std::vector<ModelSafeWorker*>::const_iterator iter;
576 for (size_t i = syncable::FIRST_REAL_MODEL_TYPE; i < types.size(); ++i) { 576 for (syncable::ModelEnumSet::Iterator it = types.First();
577 if (!types.test(i)) 577 it.Good(); it.Inc()) {
578 continue; 578 const syncable::ModelType t = it.Get();
579 syncable::ModelType t = syncable::ModelTypeFromInt(i);
580 DCHECK_EQ(1U, r_tmp.count(t)); 579 DCHECK_EQ(1U, r_tmp.count(t));
581 (*routes)[t] = r_tmp[t]; 580 (*routes)[t] = r_tmp[t];
582 iter it = std::find_if(w_tmp.begin(), w_tmp.end(), 581 iter w_tmp_it = std::find_if(w_tmp.begin(), w_tmp.end(),
583 ModelSafeWorkerGroupIs(r_tmp[t])); 582 ModelSafeWorkerGroupIs(r_tmp[t]));
584 if (it != w_tmp.end()) { 583 if (w_tmp_it != w_tmp.end()) {
585 iter it2 = std::find_if(workers->begin(), workers->end(), 584 iter workers_it = std::find_if(workers->begin(), workers->end(),
586 ModelSafeWorkerGroupIs(r_tmp[t])); 585 ModelSafeWorkerGroupIs(r_tmp[t]));
587 if (it2 == workers->end()) 586 if (workers_it == workers->end())
588 workers->push_back(*it); 587 workers->push_back(*w_tmp_it);
589 588
590 if (r_tmp[t] == GROUP_PASSIVE) 589 if (r_tmp[t] == GROUP_PASSIVE)
591 passive_group_added = true; 590 passive_group_added = true;
592 } else { 591 } else {
593 NOTREACHED(); 592 NOTREACHED();
594 } 593 }
595 } 594 }
596 595
597 // Always add group passive. 596 // Always add group passive.
598 if (passive_group_added == false) { 597 if (passive_group_added == false) {
599 iter it = std::find_if(w_tmp.begin(), w_tmp.end(), 598 iter it = std::find_if(w_tmp.begin(), w_tmp.end(),
600 ModelSafeWorkerGroupIs(GROUP_PASSIVE)); 599 ModelSafeWorkerGroupIs(GROUP_PASSIVE));
601 if (it != w_tmp.end()) 600 if (it != w_tmp.end())
602 workers->push_back(*it); 601 workers->push_back(*it);
603 else 602 else
604 NOTREACHED(); 603 NOTREACHED();
605 } 604 }
606 } 605 }
607 606
608 void SyncScheduler::ScheduleConfig( 607 void SyncScheduler::ScheduleConfig(
609 const ModelTypeBitSet& types, 608 syncable::ModelEnumSet types,
610 GetUpdatesCallerInfo::GetUpdatesSource source) { 609 GetUpdatesCallerInfo::GetUpdatesSource source) {
611 DCHECK_EQ(MessageLoop::current(), sync_loop_); 610 DCHECK_EQ(MessageLoop::current(), sync_loop_);
612 DCHECK(IsConfigRelatedUpdateSourceValue(source)); 611 DCHECK(IsConfigRelatedUpdateSourceValue(source));
613 SDVLOG(2) << "Scheduling a config"; 612 SDVLOG(2) << "Scheduling a config";
614 ModelSafeRoutingInfo routes; 613 ModelSafeRoutingInfo routes;
615 std::vector<ModelSafeWorker*> workers; 614 std::vector<ModelSafeWorker*> workers;
616 GetModelSafeParamsForTypes(types, session_context_->registrar(), 615 GetModelSafeParamsForTypes(types, session_context_->registrar(),
617 &routes, &workers); 616 &routes, &workers);
618 617
619 PostTask(FROM_HERE, "ScheduleConfigImpl", 618 PostTask(FROM_HERE, "ScheduleConfigImpl",
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
1187 1186
1188 #undef SDVLOG_LOC 1187 #undef SDVLOG_LOC
1189 1188
1190 #undef SDVLOG 1189 #undef SDVLOG
1191 1190
1192 #undef SLOG 1191 #undef SLOG
1193 1192
1194 #undef ENUM_CASE 1193 #undef ENUM_CASE
1195 1194
1196 } // browser_sync 1195 } // browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/sync_scheduler.h ('k') | chrome/browser/sync/engine/sync_scheduler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698