Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/history/content_visit_delegate.h" | |
| 6 | |
| 7 #include "chrome/browser/history/history_backend.h" | |
| 8 #include "chrome/browser/history/history_service.h" | |
| 9 #include "components/history/core/browser/history_database.h" | |
| 10 #include "components/history/core/browser/history_db_task.h" | |
| 11 #include "components/visitedlink/browser/visitedlink_master.h" | |
|
droger
2015/02/02 09:39:20
#include "base/logging.h"
#include "base/memory/re
sdefresne
2015/02/04 18:01:54
Done, thank you.
| |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 // URLIterator from std::vector<GURL> | |
| 16 class URLIteratorFromURLs : public visitedlink::VisitedLinkMaster::URLIterator { | |
| 17 public: | |
| 18 explicit URLIteratorFromURLs(const std::vector<GURL>& urls) | |
| 19 : itr_(urls.begin()), end_(urls.end()) {} | |
| 20 | |
| 21 // visitedlink::VisitedLinkMaster::URLIterator implementation. | |
| 22 const GURL& NextURL() override { return *(itr_++); } | |
| 23 bool HasNextURL() const override { return itr_ != end_; } | |
| 24 | |
| 25 private: | |
| 26 std::vector<GURL>::const_iterator itr_; | |
| 27 std::vector<GURL>::const_iterator end_; | |
| 28 | |
| 29 DISALLOW_COPY_AND_ASSIGN(URLIteratorFromURLs); | |
| 30 }; | |
| 31 | |
| 32 // IterateUrlsDBTask bridge HistoryBackend::URLEnumerator to | |
| 33 // visitedlink::VisitedLinkDelegate::URLEnumerator. | |
| 34 class IterateUrlsDBTask : public history::HistoryDBTask { | |
| 35 public: | |
| 36 explicit IterateUrlsDBTask(const scoped_refptr< | |
| 37 visitedlink::VisitedLinkDelegate::URLEnumerator>& enumerator); | |
| 38 ~IterateUrlsDBTask() override; | |
| 39 | |
| 40 private: | |
| 41 // Implementation of history::HistoryDBTask. | |
| 42 bool RunOnDBThread(history::HistoryBackend* backend, | |
| 43 history::HistoryDatabase* db) override; | |
| 44 void DoneRunOnMainThread() override; | |
| 45 | |
| 46 scoped_refptr<visitedlink::VisitedLinkDelegate::URLEnumerator> enumerator_; | |
| 47 | |
| 48 DISALLOW_COPY_AND_ASSIGN(IterateUrlsDBTask); | |
| 49 }; | |
| 50 | |
| 51 IterateUrlsDBTask::IterateUrlsDBTask(const scoped_refptr< | |
| 52 visitedlink::VisitedLinkDelegate::URLEnumerator>& enumerator) | |
| 53 : enumerator_(enumerator) { | |
| 54 } | |
| 55 | |
| 56 IterateUrlsDBTask::~IterateUrlsDBTask() { | |
| 57 } | |
| 58 | |
| 59 bool IterateUrlsDBTask::RunOnDBThread(history::HistoryBackend* backend, | |
| 60 history::HistoryDatabase* db) { | |
| 61 bool success = false; | |
| 62 if (db) { | |
| 63 history::HistoryDatabase::URLEnumerator iter; | |
| 64 if (db->InitURLEnumeratorForEverything(&iter)) { | |
| 65 history::URLRow row; | |
| 66 while (iter.GetNextURL(&row)) | |
| 67 enumerator_->OnURL(row.url()); | |
| 68 success = true; | |
| 69 } | |
| 70 } | |
| 71 enumerator_->OnComplete(success); | |
| 72 return true; | |
| 73 } | |
| 74 | |
| 75 void IterateUrlsDBTask::DoneRunOnMainThread() { | |
| 76 } | |
| 77 | |
| 78 } // namespace | |
| 79 | |
| 80 ContentVisitDelegate::ContentVisitDelegate( | |
| 81 content::BrowserContext* browser_context) | |
| 82 : history_service_(nullptr), | |
| 83 visitedlink_master_( | |
| 84 new visitedlink::VisitedLinkMaster(browser_context, this, true)) { | |
| 85 } | |
| 86 | |
| 87 ContentVisitDelegate::~ContentVisitDelegate() { | |
| 88 } | |
| 89 | |
| 90 bool ContentVisitDelegate::Init(HistoryService* history_service) { | |
| 91 DCHECK(history_service); | |
| 92 history_service_ = history_service; | |
| 93 return visitedlink_master_->Init(); | |
| 94 } | |
| 95 | |
| 96 void ContentVisitDelegate::AddURL(const GURL& url) { | |
| 97 visitedlink_master_->AddURL(url); | |
| 98 } | |
| 99 | |
| 100 void ContentVisitDelegate::AddURLs(const std::vector<GURL>& urls) { | |
| 101 visitedlink_master_->AddURLs(urls); | |
| 102 } | |
| 103 | |
| 104 void ContentVisitDelegate::DeleteURLs(const std::vector<GURL>& urls) { | |
| 105 URLIteratorFromURLs iterator(urls); | |
| 106 visitedlink_master_->DeleteURLs(&iterator); | |
| 107 } | |
| 108 | |
| 109 void ContentVisitDelegate::DeleteAllURLs() { | |
| 110 visitedlink_master_->DeleteAllURLs(); | |
| 111 } | |
| 112 | |
| 113 void ContentVisitDelegate::RebuildTable( | |
| 114 const scoped_refptr<URLEnumerator>& enumerator) { | |
| 115 DCHECK(history_service_); | |
| 116 scoped_ptr<history::HistoryDBTask> task(new IterateUrlsDBTask(enumerator)); | |
| 117 history_service_->ScheduleDBTask(task.Pass(), &task_tracker_); | |
| 118 } | |
| OLD | NEW |