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

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

Issue 8919021: [Sync] Rename ModelEnumSet to ModelTypeSet (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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"
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; 29 using syncable::ModelTypeSet;
30 using syncable::ModelEnumSetToString; 30 using syncable::ModelTypeSetToString;
31 using syncable::ModelTypePayloadMap; 31 using syncable::ModelTypePayloadMap;
32 using sync_pb::GetUpdatesCallerInfo; 32 using sync_pb::GetUpdatesCallerInfo;
33 33
34 namespace { 34 namespace {
35 bool ShouldRequestEarlyExit( 35 bool ShouldRequestEarlyExit(
36 const browser_sync::SyncProtocolError& error) { 36 const browser_sync::SyncProtocolError& error) {
37 switch (error.error_type) { 37 switch (error.error_type) {
38 case browser_sync::SYNC_SUCCESS: 38 case browser_sync::SYNC_SUCCESS:
39 case browser_sync::MIGRATION_DONE: 39 case browser_sync::MIGRATION_DONE:
40 case browser_sync::THROTTLED: 40 case browser_sync::THROTTLED:
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 // functions, too. 453 // functions, too.
454 void SyncScheduler::ScheduleCleanupDisabledTypes() { 454 void SyncScheduler::ScheduleCleanupDisabledTypes() {
455 DCHECK_EQ(MessageLoop::current(), sync_loop_); 455 DCHECK_EQ(MessageLoop::current(), sync_loop_);
456 ScheduleSyncSessionJob( 456 ScheduleSyncSessionJob(
457 TimeDelta::FromSeconds(0), SyncSessionJob::CLEANUP_DISABLED_TYPES, 457 TimeDelta::FromSeconds(0), SyncSessionJob::CLEANUP_DISABLED_TYPES,
458 CreateSyncSession(SyncSourceInfo()), FROM_HERE); 458 CreateSyncSession(SyncSourceInfo()), FROM_HERE);
459 } 459 }
460 460
461 void SyncScheduler::ScheduleNudge( 461 void SyncScheduler::ScheduleNudge(
462 const TimeDelta& delay, 462 const TimeDelta& delay,
463 NudgeSource source, ModelEnumSet types, 463 NudgeSource source, ModelTypeSet types,
464 const tracked_objects::Location& nudge_location) { 464 const tracked_objects::Location& nudge_location) {
465 DCHECK_EQ(MessageLoop::current(), sync_loop_); 465 DCHECK_EQ(MessageLoop::current(), sync_loop_);
466 SDVLOG_LOC(nudge_location, 2) 466 SDVLOG_LOC(nudge_location, 2)
467 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, " 467 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, "
468 << "source " << GetNudgeSourceString(source) << ", " 468 << "source " << GetNudgeSourceString(source) << ", "
469 << "types " << ModelEnumSetToString(types); 469 << "types " << ModelTypeSetToString(types);
470 470
471 ModelTypePayloadMap types_with_payloads = 471 ModelTypePayloadMap types_with_payloads =
472 syncable::ModelTypePayloadMapFromEnumSet(types, std::string()); 472 syncable::ModelTypePayloadMapFromEnumSet(types, std::string());
473 PostTask(nudge_location, "ScheduleNudgeImpl", 473 PostTask(nudge_location, "ScheduleNudgeImpl",
474 base::Bind(&SyncScheduler::ScheduleNudgeImpl, 474 base::Bind(&SyncScheduler::ScheduleNudgeImpl,
475 weak_ptr_factory_.GetWeakPtr(), 475 weak_ptr_factory_.GetWeakPtr(),
476 delay, 476 delay,
477 GetUpdatesFromNudgeSource(source), 477 GetUpdatesFromNudgeSource(source),
478 types_with_payloads, 478 types_with_payloads,
479 false, 479 false,
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 } 556 }
557 } 557 }
558 558
559 // TODO(lipalani) - pass the job itself to ScheduleSyncSessionJob. 559 // TODO(lipalani) - pass the job itself to ScheduleSyncSessionJob.
560 ScheduleSyncSessionJob(delay, SyncSessionJob::NUDGE, job.session.release(), 560 ScheduleSyncSessionJob(delay, SyncSessionJob::NUDGE, job.session.release(),
561 nudge_location); 561 nudge_location);
562 } 562 }
563 563
564 // 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
565 // |types| from |registrar|. 565 // |types| from |registrar|.
566 void GetModelSafeParamsForTypes(ModelEnumSet types, 566 void GetModelSafeParamsForTypes(ModelTypeSet types,
567 ModelSafeWorkerRegistrar* registrar, ModelSafeRoutingInfo* routes, 567 ModelSafeWorkerRegistrar* registrar, ModelSafeRoutingInfo* routes,
568 std::vector<ModelSafeWorker*>* workers) { 568 std::vector<ModelSafeWorker*>* workers) {
569 ModelSafeRoutingInfo r_tmp; 569 ModelSafeRoutingInfo r_tmp;
570 std::vector<ModelSafeWorker*> w_tmp; 570 std::vector<ModelSafeWorker*> w_tmp;
571 registrar->GetModelSafeRoutingInfo(&r_tmp); 571 registrar->GetModelSafeRoutingInfo(&r_tmp);
572 registrar->GetWorkers(&w_tmp); 572 registrar->GetWorkers(&w_tmp);
573 573
574 bool passive_group_added = false; 574 bool passive_group_added = false;
575 575
576 typedef std::vector<ModelSafeWorker*>::const_iterator iter; 576 typedef std::vector<ModelSafeWorker*>::const_iterator iter;
577 for (ModelEnumSet::Iterator it = types.First(); 577 for (ModelTypeSet::Iterator it = types.First();
578 it.Good(); it.Inc()) { 578 it.Good(); it.Inc()) {
579 const syncable::ModelType t = it.Get(); 579 const syncable::ModelType t = it.Get();
580 DCHECK_EQ(1U, r_tmp.count(t)); 580 DCHECK_EQ(1U, r_tmp.count(t));
581 (*routes)[t] = r_tmp[t]; 581 (*routes)[t] = r_tmp[t];
582 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(),
583 ModelSafeWorkerGroupIs(r_tmp[t])); 583 ModelSafeWorkerGroupIs(r_tmp[t]));
584 if (w_tmp_it != w_tmp.end()) { 584 if (w_tmp_it != w_tmp.end()) {
585 iter workers_it = std::find_if(workers->begin(), workers->end(), 585 iter workers_it = std::find_if(workers->begin(), workers->end(),
586 ModelSafeWorkerGroupIs(r_tmp[t])); 586 ModelSafeWorkerGroupIs(r_tmp[t]));
587 if (workers_it == workers->end()) 587 if (workers_it == workers->end())
(...skipping 11 matching lines...) Expand all
599 iter it = std::find_if(w_tmp.begin(), w_tmp.end(), 599 iter it = std::find_if(w_tmp.begin(), w_tmp.end(),
600 ModelSafeWorkerGroupIs(GROUP_PASSIVE)); 600 ModelSafeWorkerGroupIs(GROUP_PASSIVE));
601 if (it != w_tmp.end()) 601 if (it != w_tmp.end())
602 workers->push_back(*it); 602 workers->push_back(*it);
603 else 603 else
604 NOTREACHED(); 604 NOTREACHED();
605 } 605 }
606 } 606 }
607 607
608 void SyncScheduler::ScheduleConfig( 608 void SyncScheduler::ScheduleConfig(
609 ModelEnumSet types, 609 ModelTypeSet types,
610 GetUpdatesCallerInfo::GetUpdatesSource source) { 610 GetUpdatesCallerInfo::GetUpdatesSource source) {
611 DCHECK_EQ(MessageLoop::current(), sync_loop_); 611 DCHECK_EQ(MessageLoop::current(), sync_loop_);
612 DCHECK(IsConfigRelatedUpdateSourceValue(source)); 612 DCHECK(IsConfigRelatedUpdateSourceValue(source));
613 SDVLOG(2) << "Scheduling a config"; 613 SDVLOG(2) << "Scheduling a config";
614 ModelSafeRoutingInfo routes; 614 ModelSafeRoutingInfo routes;
615 std::vector<ModelSafeWorker*> workers; 615 std::vector<ModelSafeWorker*> workers;
616 GetModelSafeParamsForTypes(types, session_context_->registrar(), 616 GetModelSafeParamsForTypes(types, session_context_->registrar(),
617 &routes, &workers); 617 &routes, &workers);
618 618
619 PostTask(FROM_HERE, "ScheduleConfigImpl", 619 PostTask(FROM_HERE, "ScheduleConfigImpl",
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
1187 1187
1188 #undef SDVLOG_LOC 1188 #undef SDVLOG_LOC
1189 1189
1190 #undef SDVLOG 1190 #undef SDVLOG
1191 1191
1192 #undef SLOG 1192 #undef SLOG
1193 1193
1194 #undef ENUM_CASE 1194 #undef ENUM_CASE
1195 1195
1196 } // browser_sync 1196 } // 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