Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "sync/internal_api/public/engine/model_safe_worker.h" | 5 #include "sync/internal_api/public/engine/model_safe_worker.h" |
| 6 | 6 |
| 7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 | 10 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 case GROUP_PASSIVE: | 73 case GROUP_PASSIVE: |
| 74 return "GROUP_PASSIVE"; | 74 return "GROUP_PASSIVE"; |
| 75 case GROUP_PASSWORD: | 75 case GROUP_PASSWORD: |
| 76 return "GROUP_PASSWORD"; | 76 return "GROUP_PASSWORD"; |
| 77 default: | 77 default: |
| 78 NOTREACHED(); | 78 NOTREACHED(); |
| 79 return "INVALID"; | 79 return "INVALID"; |
| 80 } | 80 } |
| 81 } | 81 } |
| 82 | 82 |
| 83 ModelSafeWorker::ModelSafeWorker(WorkerLoopDestructionObserver* observer) | |
| 84 : stopped_(false), | |
| 85 work_done_or_stopped_(false, false), | |
| 86 observer_(observer) {} | |
| 87 | |
| 83 ModelSafeWorker::~ModelSafeWorker() {} | 88 ModelSafeWorker::~ModelSafeWorker() {} |
| 84 | 89 |
| 90 void ModelSafeWorker::RequestStop() { | |
| 91 base::AutoLock al(stopped_lock_); | |
| 92 | |
| 93 // Set stop flag but don't signal work_done_or_stopped_ to unblock sync loop | |
| 94 // because the worker may be working and depending on sync command object | |
| 95 // living on sync thread. | |
| 96 stopped_ = true; | |
| 97 } | |
| 98 | |
| 99 SyncerError ModelSafeWorker::DoWorkAndWaitUntilDone(const WorkCallback& work) { | |
| 100 { | |
| 101 base::AutoLock al(stopped_lock_); | |
| 102 if (stopped_) | |
| 103 return CANNOT_DO_WORK; | |
| 104 | |
| 105 // Clear signal before starting work. | |
| 106 work_done_or_stopped_.Reset(); | |
|
tim (not reviewing)
2013/05/17 20:51:33
Why are we using manual reset for this?
haitaol1
2013/05/17 22:06:57
It should be unnecessary if worker is not reused,
tim (not reviewing)
2013/05/20 17:22:38
My question was phrased a bit incorrectly; I was w
haitaol1
2013/05/23 16:07:29
With manual_reset=true, Reset() becomes necessary
tim (not reviewing)
2013/05/23 18:10:37
Right, but you never passed true for manual_reset
| |
| 107 } | |
| 108 | |
| 109 return DoWorkAndWaitUntilDoneImpl(work, &work_done_or_stopped_); | |
| 110 } | |
| 111 | |
| 112 bool ModelSafeWorker::IsStopped() { | |
| 113 base::AutoLock al(stopped_lock_); | |
| 114 return stopped_; | |
| 115 } | |
| 116 | |
| 117 void ModelSafeWorker::WillDestroyCurrentMessageLoop() { | |
| 118 { | |
| 119 base::AutoLock al(stopped_lock_); | |
| 120 stopped_ = true; | |
| 121 | |
| 122 // Safe to signal because pending work (if any) will not be executed. So | |
| 123 // there should be no harm even the work holds a pointer to the | |
| 124 // ModelChangingSyncerCommand that will be destroyed on sync loop after | |
| 125 // the signal is set. | |
| 126 work_done_or_stopped_.Signal(); | |
| 127 | |
| 128 DLOG(INFO) << ModelSafeGroupToString(GetModelSafeGroup()) | |
| 129 << " worker stops on destruction of its working thread."; | |
| 130 } | |
| 131 | |
| 132 if (observer_) | |
| 133 observer_->OnWorkerLoopDestroyed(GetModelSafeGroup()); | |
| 134 } | |
| 135 | |
| 85 } // namespace syncer | 136 } // namespace syncer |
| OLD | NEW |