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 "chrome/browser/sync/glue/history_model_worker.h" | 5 #include "chrome/browser/sync/glue/history_model_worker.h" |
6 | 6 |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 93 |
94 void HistoryModelWorker::RegisterForLoopDestruction() { | 94 void HistoryModelWorker::RegisterForLoopDestruction() { |
95 CHECK(history_service_.get()); | 95 CHECK(history_service_.get()); |
96 history_service_->ScheduleDBTask( | 96 history_service_->ScheduleDBTask( |
97 scoped_ptr<history::HistoryDBTask>(new AddDBThreadObserverTask( | 97 scoped_ptr<history::HistoryDBTask>(new AddDBThreadObserverTask( |
98 base::Bind(&HistoryModelWorker::RegisterOnDBThread, this))), | 98 base::Bind(&HistoryModelWorker::RegisterOnDBThread, this))), |
99 cancelable_tracker_.get()); | 99 cancelable_tracker_.get()); |
100 } | 100 } |
101 | 101 |
102 void HistoryModelWorker::RegisterOnDBThread() { | 102 void HistoryModelWorker::RegisterOnDBThread() { |
| 103 base::MessageLoop::current()->AddDestructionObserver(this); |
103 SetWorkingLoopToCurrent(); | 104 SetWorkingLoopToCurrent(); |
104 } | 105 } |
105 | 106 |
106 syncer::SyncerError HistoryModelWorker::DoWorkAndWaitUntilDoneImpl( | 107 syncer::SyncerError HistoryModelWorker::DoWorkAndWaitUntilDoneImpl( |
107 const syncer::WorkCallback& work) { | 108 const syncer::WorkCallback& work) { |
108 syncer::SyncerError error = syncer::UNSET; | 109 syncer::SyncerError error = syncer::UNSET; |
109 if (BrowserThread::PostTask(BrowserThread::UI, | 110 if (BrowserThread::PostTask(BrowserThread::UI, |
110 FROM_HERE, | 111 FROM_HERE, |
111 base::Bind(&PostWorkerTask, | 112 base::Bind(&PostWorkerTask, |
112 history_service_, | 113 history_service_, |
(...skipping 13 matching lines...) Expand all Loading... |
126 } | 127 } |
127 | 128 |
128 HistoryModelWorker::~HistoryModelWorker() { | 129 HistoryModelWorker::~HistoryModelWorker() { |
129 // The base::CancelableTaskTracker class is not thread-safe and must only be | 130 // The base::CancelableTaskTracker class is not thread-safe and must only be |
130 // used from a single thread but the current object may not be destroyed from | 131 // used from a single thread but the current object may not be destroyed from |
131 // the UI thread, so delete it from the UI thread. | 132 // the UI thread, so delete it from the UI thread. |
132 BrowserThread::DeleteOnUIThread::Destruct(cancelable_tracker_.release()); | 133 BrowserThread::DeleteOnUIThread::Destruct(cancelable_tracker_.release()); |
133 } | 134 } |
134 | 135 |
135 } // namespace browser_sync | 136 } // namespace browser_sync |
OLD | NEW |