| 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 <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 case GROUP_NON_BLOCKING: | 67 case GROUP_NON_BLOCKING: |
| 68 return "GROUP_NON_BLOCKING"; | 68 return "GROUP_NON_BLOCKING"; |
| 69 default: | 69 default: |
| 70 NOTREACHED(); | 70 NOTREACHED(); |
| 71 return "INVALID"; | 71 return "INVALID"; |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 | 74 |
| 75 ModelSafeWorker::ModelSafeWorker(WorkerLoopDestructionObserver* observer) | 75 ModelSafeWorker::ModelSafeWorker(WorkerLoopDestructionObserver* observer) |
| 76 : stopped_(false), | 76 : stopped_(false), |
| 77 work_done_or_stopped_(false, false), | 77 work_done_or_stopped_(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 78 base::WaitableEvent::InitialState::NOT_SIGNALED), |
| 78 observer_(observer), | 79 observer_(observer), |
| 79 working_loop_(NULL) { | 80 working_loop_(NULL) {} |
| 80 } | |
| 81 | 81 |
| 82 ModelSafeWorker::~ModelSafeWorker() {} | 82 ModelSafeWorker::~ModelSafeWorker() {} |
| 83 | 83 |
| 84 void ModelSafeWorker::RequestStop() { | 84 void ModelSafeWorker::RequestStop() { |
| 85 base::AutoLock al(stopped_lock_); | 85 base::AutoLock al(stopped_lock_); |
| 86 | 86 |
| 87 // Set stop flag but don't signal work_done_or_stopped_ to unblock sync loop | 87 // Set stop flag but don't signal work_done_or_stopped_ to unblock sync loop |
| 88 // because the worker may be working and depending on sync command object | 88 // because the worker may be working and depending on sync command object |
| 89 // living on sync thread. This prevents any *further* tasks from being posted | 89 // living on sync thread. This prevents any *further* tasks from being posted |
| 90 // to worker threads (see DoWorkAndWaitUntilDone below), but note that one | 90 // to worker threads (see DoWorkAndWaitUntilDone below), but note that one |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 return; | 192 return; |
| 193 DCHECK_EQ(base::MessageLoop::current(), working_loop_); | 193 DCHECK_EQ(base::MessageLoop::current(), working_loop_); |
| 194 } | 194 } |
| 195 | 195 |
| 196 DCHECK(stopped_); | 196 DCHECK(stopped_); |
| 197 base::MessageLoop::current()->RemoveDestructionObserver(this); | 197 base::MessageLoop::current()->RemoveDestructionObserver(this); |
| 198 unregister_done_callback.Run(GetModelSafeGroup()); | 198 unregister_done_callback.Run(GetModelSafeGroup()); |
| 199 } | 199 } |
| 200 | 200 |
| 201 } // namespace syncer | 201 } // namespace syncer |
| OLD | NEW |