| 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 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/containers/hash_tables.h" | 7 #include "base/containers/hash_tables.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "chrome/browser/android/history_report/delta_file_commons.h" | 10 #include "chrome/browser/android/history_report/delta_file_commons.h" |
| 11 #include "chrome/browser/android/history_report/delta_file_service.h" | 11 #include "chrome/browser/android/history_report/delta_file_service.h" |
| 12 #include "chrome/browser/android/history_report/get_all_urls_from_history_task.h
" | 12 #include "chrome/browser/android/history_report/get_all_urls_from_history_task.h
" |
| 13 #include "chrome/browser/android/history_report/historic_visits_migration_task.h
" | 13 #include "chrome/browser/android/history_report/historic_visits_migration_task.h
" |
| 14 #include "chrome/browser/android/history_report/usage_reports_buffer_service.h" | 14 #include "chrome/browser/android/history_report/usage_reports_buffer_service.h" |
| 15 #include "chrome/browser/history/history_service_factory.h" | 15 #include "chrome/browser/history/history_service_factory.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "components/bookmarks/browser/bookmark_model.h" | 17 #include "components/bookmarks/browser/bookmark_model.h" |
| 18 #include "components/history/core/browser/history_db_task.h" | 18 #include "components/history/core/browser/history_db_task.h" |
| 19 #include "components/history/core/browser/history_service.h" | 19 #include "components/history/core/browser/history_service.h" |
| 20 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 21 | 21 |
| 22 using bookmarks::BookmarkModel; | 22 using bookmarks::BookmarkModel; |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 static bool g_is_debug = false; |
| 26 |
| 25 typedef base::hash_map<std::string, BookmarkModel::URLAndTitle*> BookmarkMap; | 27 typedef base::hash_map<std::string, BookmarkModel::URLAndTitle*> BookmarkMap; |
| 26 | 28 |
| 27 struct Context { | 29 struct Context { |
| 28 history::HistoryService* history_service; | 30 history::HistoryService* history_service; |
| 29 base::CancelableTaskTracker* history_task_tracker; | 31 base::CancelableTaskTracker* history_task_tracker; |
| 30 base::WaitableEvent finished; | 32 base::WaitableEvent finished; |
| 31 | 33 |
| 32 Context(history::HistoryService* hservice, | 34 Context(history::HistoryService* hservice, |
| 33 base::CancelableTaskTracker* tracker) | 35 base::CancelableTaskTracker* tracker) |
| 34 : history_service(hservice), | 36 : history_service(hservice), |
| 35 history_task_tracker(tracker), | 37 history_task_tracker(tracker), |
| 36 finished(false, false) {} | 38 finished(false, false) {} |
| 37 }; | 39 }; |
| 38 | 40 |
| 39 void UpdateUrl(Context* context, | 41 void UpdateUrl(Context* context, |
| 40 size_t position, | 42 size_t position, |
| 41 std::vector<history_report::DeltaFileEntryWithData>* urls, | 43 std::vector<history_report::DeltaFileEntryWithData>* urls, |
| 42 bool success, | 44 bool success, |
| 43 const history::URLRow& url, | 45 const history::URLRow& url, |
| 44 const history::VisitVector& visits) { | 46 const history::VisitVector& visits) { |
| 45 history_report::DeltaFileEntryWithData* entry = &((*urls)[position]); | 47 history_report::DeltaFileEntryWithData* entry = &((*urls)[position]); |
| 46 if (success) { | 48 if (success) { |
| 47 entry->SetData(url); | 49 entry->SetData(url); |
| 48 } else { | 50 } else if (g_is_debug){ |
| 49 LOG(WARNING) << "No data for url " << entry->Url(); | 51 LOG(WARNING) << "DB not initialized or no data for url " << entry->Url(); |
| 50 } | 52 } |
| 51 if (position + 1 == urls->size()) { | 53 if (position + 1 == urls->size()) { |
| 52 context->finished.Signal(); | 54 context->finished.Signal(); |
| 53 } else { | 55 } else { |
| 54 context->history_service->QueryURL(GURL((*urls)[position + 1].Url()), | 56 context->history_service->QueryURL(GURL((*urls)[position + 1].Url()), |
| 55 false, | 57 false, |
| 56 base::Bind(&UpdateUrl, | 58 base::Bind(&UpdateUrl, |
| 57 base::Unretained(context), | 59 base::Unretained(context), |
| 58 position + 1, | 60 position + 1, |
| 59 base::Unretained(urls)), | 61 base::Unretained(urls)), |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 bookmark_model_->BlockTillLoaded(); | 186 bookmark_model_->BlockTillLoaded(); |
| 185 bookmark_model_->GetBookmarks(&bookmarks); | 187 bookmark_model_->GetBookmarks(&bookmarks); |
| 186 urls.reserve(urls.size() + bookmarks.size()); | 188 urls.reserve(urls.size() + bookmarks.size()); |
| 187 for (size_t i = 0; i < bookmarks.size(); i++) { | 189 for (size_t i = 0; i < bookmarks.size(); i++) { |
| 188 urls.push_back(bookmarks[i].url.spec()); | 190 urls.push_back(bookmarks[i].url.spec()); |
| 189 } | 191 } |
| 190 delta_file_service_->Recreate(urls); | 192 delta_file_service_->Recreate(urls); |
| 191 } | 193 } |
| 192 | 194 |
| 193 } // namespace history_report | 195 } // namespace history_report |
| OLD | NEW |