| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/android/history_report/data_provider.h" | 5 #include "chrome/browser/android/history_report/data_provider.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 struct Context { | 32 struct Context { |
| 33 history::HistoryService* history_service; | 33 history::HistoryService* history_service; |
| 34 base::CancelableTaskTracker* history_task_tracker; | 34 base::CancelableTaskTracker* history_task_tracker; |
| 35 base::WaitableEvent finished; | 35 base::WaitableEvent finished; |
| 36 | 36 |
| 37 Context(history::HistoryService* hservice, | 37 Context(history::HistoryService* hservice, |
| 38 base::CancelableTaskTracker* tracker) | 38 base::CancelableTaskTracker* tracker) |
| 39 : history_service(hservice), | 39 : history_service(hservice), |
| 40 history_task_tracker(tracker), | 40 history_task_tracker(tracker), |
| 41 finished(false, false) {} | 41 finished(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 42 base::WaitableEvent::InitialState::NOT_SIGNALED) {} |
| 42 }; | 43 }; |
| 43 | 44 |
| 44 void UpdateUrl(Context* context, | 45 void UpdateUrl(Context* context, |
| 45 size_t position, | 46 size_t position, |
| 46 std::vector<history_report::DeltaFileEntryWithData>* urls, | 47 std::vector<history_report::DeltaFileEntryWithData>* urls, |
| 47 bool success, | 48 bool success, |
| 48 const history::URLRow& url, | 49 const history::URLRow& url, |
| 49 const history::VisitVector& visits) { | 50 const history::VisitVector& visits) { |
| 50 history_report::DeltaFileEntryWithData* entry = &((*urls)[position]); | 51 history_report::DeltaFileEntryWithData* entry = &((*urls)[position]); |
| 51 if (success) { | 52 if (success) { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 const DeltaFileEntryWithData& entry = (*entries)[i]; | 150 const DeltaFileEntryWithData& entry = (*entries)[i]; |
| 150 if (entry.Valid()) valid_entries->push_back(entry); | 151 if (entry.Valid()) valid_entries->push_back(entry); |
| 151 if (entry.SeqNo() > last_seq_no) last_seq_no = entry.SeqNo(); | 152 if (entry.SeqNo() > last_seq_no) last_seq_no = entry.SeqNo(); |
| 152 } | 153 } |
| 153 } while (!entries->empty() && valid_entries->empty()); | 154 } while (!entries->empty() && valid_entries->empty()); |
| 154 return valid_entries; | 155 return valid_entries; |
| 155 } | 156 } |
| 156 | 157 |
| 157 void DataProvider::StartVisitMigrationToUsageBuffer( | 158 void DataProvider::StartVisitMigrationToUsageBuffer( |
| 158 UsageReportsBufferService* buffer_service) { | 159 UsageReportsBufferService* buffer_service) { |
| 159 base::WaitableEvent finished(false, false); | 160 base::WaitableEvent finished(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 161 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 160 buffer_service->Clear(); | 162 buffer_service->Clear(); |
| 161 content::BrowserThread::PostTask( | 163 content::BrowserThread::PostTask( |
| 162 content::BrowserThread::UI, | 164 content::BrowserThread::UI, |
| 163 FROM_HERE, | 165 FROM_HERE, |
| 164 base::Bind(&StartVisitMigrationToUsageBufferUiThread, | 166 base::Bind(&StartVisitMigrationToUsageBufferUiThread, |
| 165 base::Unretained(history_service_), | 167 base::Unretained(history_service_), |
| 166 buffer_service, | 168 buffer_service, |
| 167 base::Unretained(&finished), | 169 base::Unretained(&finished), |
| 168 base::Unretained(&history_task_tracker_))); | 170 base::Unretained(&history_task_tracker_))); |
| 169 finished.Wait(); | 171 finished.Wait(); |
| 170 } | 172 } |
| 171 | 173 |
| 172 void DataProvider::RecreateLog() { | 174 void DataProvider::RecreateLog() { |
| 173 std::vector<std::string> urls; | 175 std::vector<std::string> urls; |
| 174 { | 176 { |
| 175 base::WaitableEvent finished(false, false); | 177 base::WaitableEvent finished( |
| 178 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 179 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 176 | 180 |
| 177 std::unique_ptr<history::HistoryDBTask> task = | 181 std::unique_ptr<history::HistoryDBTask> task = |
| 178 std::unique_ptr<history::HistoryDBTask>( | 182 std::unique_ptr<history::HistoryDBTask>( |
| 179 new GetAllUrlsFromHistoryTask(&finished, &urls)); | 183 new GetAllUrlsFromHistoryTask(&finished, &urls)); |
| 180 content::BrowserThread::PostTask( | 184 content::BrowserThread::PostTask( |
| 181 content::BrowserThread::UI, FROM_HERE, | 185 content::BrowserThread::UI, FROM_HERE, |
| 182 base::Bind(base::IgnoreResult(&history::HistoryService::ScheduleDBTask), | 186 base::Bind(base::IgnoreResult(&history::HistoryService::ScheduleDBTask), |
| 183 base::Unretained(history_service_), base::Passed(&task), | 187 base::Unretained(history_service_), base::Passed(&task), |
| 184 base::Unretained(&history_task_tracker_))); | 188 base::Unretained(&history_task_tracker_))); |
| 185 finished.Wait(); | 189 finished.Wait(); |
| 186 } | 190 } |
| 187 | 191 |
| 188 std::vector<BookmarkModel::URLAndTitle> bookmarks; | 192 std::vector<BookmarkModel::URLAndTitle> bookmarks; |
| 189 bookmark_model_->BlockTillLoaded(); | 193 bookmark_model_->BlockTillLoaded(); |
| 190 bookmark_model_->GetBookmarks(&bookmarks); | 194 bookmark_model_->GetBookmarks(&bookmarks); |
| 191 urls.reserve(urls.size() + bookmarks.size()); | 195 urls.reserve(urls.size() + bookmarks.size()); |
| 192 for (size_t i = 0; i < bookmarks.size(); i++) { | 196 for (size_t i = 0; i < bookmarks.size(); i++) { |
| 193 urls.push_back(bookmarks[i].url.spec()); | 197 urls.push_back(bookmarks[i].url.spec()); |
| 194 } | 198 } |
| 195 delta_file_service_->Recreate(urls); | 199 delta_file_service_->Recreate(urls); |
| 196 } | 200 } |
| 197 | 201 |
| 198 } // namespace history_report | 202 } // namespace history_report |
| OLD | NEW |