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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 | 64 |
65 // Post the work task on |history_service|'s DB thread from the UI | 65 // Post the work task on |history_service|'s DB thread from the UI |
66 // thread. | 66 // thread. |
67 void PostWorkerTask(const base::WeakPtr<HistoryService>& history_service, | 67 void PostWorkerTask(const base::WeakPtr<HistoryService>& history_service, |
68 const syncer::WorkCallback& work, | 68 const syncer::WorkCallback& work, |
69 base::CancelableTaskTracker* cancelable_tracker, | 69 base::CancelableTaskTracker* cancelable_tracker, |
70 WaitableEvent* done, | 70 WaitableEvent* done, |
71 syncer::SyncerError* error) { | 71 syncer::SyncerError* error) { |
72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
73 if (history_service.get()) { | 73 if (history_service.get()) { |
74 scoped_ptr<history::HistoryDBTask> task(new WorkerTask(work, done, error)); | 74 scoped_refptr<WorkerTask> task(new WorkerTask(work, done, error)); |
75 history_service->ScheduleDBTask(task.Pass(), cancelable_tracker); | 75 history_service->ScheduleDBTask(task.get(), cancelable_tracker); |
76 } else { | 76 } else { |
77 *error = syncer::CANNOT_DO_WORK; | 77 *error = syncer::CANNOT_DO_WORK; |
78 done->Signal(); | 78 done->Signal(); |
79 } | 79 } |
80 } | 80 } |
81 | 81 |
82 } // namespace | 82 } // namespace |
83 | 83 |
84 HistoryModelWorker::HistoryModelWorker( | 84 HistoryModelWorker::HistoryModelWorker( |
85 const base::WeakPtr<HistoryService>& history_service, | 85 const base::WeakPtr<HistoryService>& history_service, |
86 syncer::WorkerLoopDestructionObserver* observer) | 86 syncer::WorkerLoopDestructionObserver* observer) |
87 : syncer::ModelSafeWorker(observer), | 87 : syncer::ModelSafeWorker(observer), |
88 history_service_(history_service) { | 88 history_service_(history_service) { |
89 CHECK(history_service.get()); | 89 CHECK(history_service.get()); |
90 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 90 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
91 cancelable_tracker_.reset(new base::CancelableTaskTracker); | 91 cancelable_tracker_.reset(new base::CancelableTaskTracker); |
92 } | 92 } |
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 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 base::MessageLoop::current()->AddDestructionObserver(this); |
104 SetWorkingLoopToCurrent(); | 104 SetWorkingLoopToCurrent(); |
105 } | 105 } |
106 | 106 |
107 syncer::SyncerError HistoryModelWorker::DoWorkAndWaitUntilDoneImpl( | 107 syncer::SyncerError HistoryModelWorker::DoWorkAndWaitUntilDoneImpl( |
108 const syncer::WorkCallback& work) { | 108 const syncer::WorkCallback& work) { |
(...skipping 18 matching lines...) Expand all Loading... |
127 } | 127 } |
128 | 128 |
129 HistoryModelWorker::~HistoryModelWorker() { | 129 HistoryModelWorker::~HistoryModelWorker() { |
130 // 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 |
131 // 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 |
132 // the UI thread, so delete it from the UI thread. | 132 // the UI thread, so delete it from the UI thread. |
133 BrowserThread::DeleteOnUIThread::Destruct(cancelable_tracker_.release()); | 133 BrowserThread::DeleteOnUIThread::Destruct(cancelable_tracker_.release()); |
134 } | 134 } |
135 | 135 |
136 } // namespace browser_sync | 136 } // namespace browser_sync |
OLD | NEW |