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" |
11 | 11 |
12 using base::WaitableEvent; | 12 using base::WaitableEvent; |
13 using content::BrowserThread; | 13 using content::BrowserThread; |
14 | 14 |
15 namespace browser_sync { | 15 namespace browser_sync { |
16 | 16 |
17 class WorkerTask : public history::HistoryDBTask { | 17 class WorkerTask : public history::HistoryDBTask { |
18 public: | 18 public: |
19 WorkerTask( | 19 WorkerTask( |
20 const syncer::WorkCallback& work, | 20 const syncer::WorkCallback& work, |
21 WaitableEvent* done, | 21 WaitableEvent* done, |
22 syncer::SyncerError* error) | 22 syncer::SyncerError* error) |
23 : work_(work), done_(done), error_(error) {} | 23 : work_(work), done_(done), error_(error) {} |
24 | 24 |
25 virtual bool RunOnDBThread(history::HistoryBackend* backend, | 25 virtual bool RunOnDBThread(history::HistoryBackend* backend, |
26 history::HistoryDatabase* db) OVERRIDE { | 26 history::HistoryDatabase* db) override { |
27 *error_ = work_.Run(); | 27 *error_ = work_.Run(); |
28 done_->Signal(); | 28 done_->Signal(); |
29 return true; | 29 return true; |
30 } | 30 } |
31 | 31 |
32 // Since the DoWorkAndWaitUntilDone() is synchronous, we don't need to run | 32 // Since the DoWorkAndWaitUntilDone() is synchronous, we don't need to run |
33 // any code asynchronously on the main thread after completion. | 33 // any code asynchronously on the main thread after completion. |
34 virtual void DoneRunOnMainThread() OVERRIDE {} | 34 virtual void DoneRunOnMainThread() override {} |
35 | 35 |
36 protected: | 36 protected: |
37 virtual ~WorkerTask() {} | 37 virtual ~WorkerTask() {} |
38 | 38 |
39 syncer::WorkCallback work_; | 39 syncer::WorkCallback work_; |
40 WaitableEvent* done_; | 40 WaitableEvent* done_; |
41 syncer::SyncerError* error_; | 41 syncer::SyncerError* error_; |
42 }; | 42 }; |
43 | 43 |
44 class AddDBThreadObserverTask : public history::HistoryDBTask { | 44 class AddDBThreadObserverTask : public history::HistoryDBTask { |
45 public: | 45 public: |
46 explicit AddDBThreadObserverTask(base::Closure register_callback) | 46 explicit AddDBThreadObserverTask(base::Closure register_callback) |
47 : register_callback_(register_callback) {} | 47 : register_callback_(register_callback) {} |
48 | 48 |
49 virtual bool RunOnDBThread(history::HistoryBackend* backend, | 49 virtual bool RunOnDBThread(history::HistoryBackend* backend, |
50 history::HistoryDatabase* db) OVERRIDE { | 50 history::HistoryDatabase* db) override { |
51 register_callback_.Run(); | 51 register_callback_.Run(); |
52 return true; | 52 return true; |
53 } | 53 } |
54 | 54 |
55 virtual void DoneRunOnMainThread() OVERRIDE {} | 55 virtual void DoneRunOnMainThread() override {} |
56 | 56 |
57 private: | 57 private: |
58 virtual ~AddDBThreadObserverTask() {} | 58 virtual ~AddDBThreadObserverTask() {} |
59 | 59 |
60 base::Closure register_callback_; | 60 base::Closure register_callback_; |
61 }; | 61 }; |
62 | 62 |
63 namespace { | 63 namespace { |
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 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 |