| Index: components/visitedlink/browser/visitedlink_event_listener.cc
|
| diff --git a/components/visitedlink/browser/visitedlink_event_listener.cc b/components/visitedlink/browser/visitedlink_event_listener.cc
|
| index dd9c9f77fcabeddd8a5ed6020fbbd7cdae68f3c0..37cdcd502a3414a808f5b10650d04f2168f99c92 100644
|
| --- a/components/visitedlink/browser/visitedlink_event_listener.cc
|
| +++ b/components/visitedlink/browser/visitedlink_event_listener.cc
|
| @@ -4,13 +4,14 @@
|
|
|
| #include "components/visitedlink/browser/visitedlink_event_listener.h"
|
|
|
| -#include "base/memory/shared_memory.h"
|
| +#include "base/bind.h"
|
| #include "components/visitedlink/browser/visitedlink_delegate.h"
|
| -#include "components/visitedlink/common/visitedlink_messages.h"
|
| +#include "components/visitedlink/common/visitedlink.mojom.h"
|
| #include "content/public/browser/notification_service.h"
|
| #include "content/public/browser/notification_types.h"
|
| #include "content/public/browser/render_process_host.h"
|
| #include "content/public/browser/render_widget_host.h"
|
| +#include "services/shell/public/cpp/interface_provider.h"
|
|
|
| using base::Time;
|
| using base::TimeDelta;
|
| @@ -19,7 +20,7 @@ using content::RenderWidgetHost;
|
| namespace {
|
|
|
| // The amount of time we wait to accumulate visited link additions.
|
| -const int kCommitIntervalMs = 100;
|
| +constexpr int kCommitIntervalMs = 100;
|
|
|
| // Size of the buffer after which individual link updates deemed not warranted
|
| // and the overall update should be used instead.
|
| @@ -42,20 +43,18 @@ class VisitedLinkUpdater {
|
| explicit VisitedLinkUpdater(int render_process_id)
|
| : reset_needed_(false),
|
| invalidate_hashes_(false),
|
| - render_process_id_(render_process_id) {}
|
| + render_process_id_(render_process_id) {
|
| + content::RenderProcessHost::FromID(render_process_id)
|
| + ->GetRemoteInterfaces()
|
| + ->GetInterface(&sink_);
|
| + }
|
|
|
| // Informs the renderer about a new visited link table.
|
| - void SendVisitedLinkTable(base::SharedMemory* table_memory) {
|
| - content::RenderProcessHost* process =
|
| - content::RenderProcessHost::FromID(render_process_id_);
|
| - if (!process)
|
| - return; // Happens in tests
|
| - base::SharedMemoryHandle handle_for_process;
|
| - table_memory->ShareReadOnlyToProcess(process->GetHandle(),
|
| - &handle_for_process);
|
| - if (base::SharedMemory::IsHandleValid(handle_for_process))
|
| - process->Send(new ChromeViewMsg_VisitedLink_NewTable(
|
| - handle_for_process));
|
| + void SendVisitedLinkTable(mojo::SharedBufferHandle table) {
|
| + mojo::ScopedSharedBufferHandle client_table =
|
| + table.Clone(mojo::SharedBufferHandle::AccessMode::READ_ONLY);
|
| + if (client_table.is_valid())
|
| + sink_->UpdateVisitedLinks(std::move(client_table));
|
| }
|
|
|
| // Buffers |links| to update, but doesn't actually relay them.
|
| @@ -98,7 +97,7 @@ class VisitedLinkUpdater {
|
| return;
|
|
|
| if (reset_needed_) {
|
| - process->Send(new ChromeViewMsg_VisitedLink_Reset(invalidate_hashes_));
|
| + sink_->ResetVisitedLinks(invalidate_hashes_);
|
| reset_needed_ = false;
|
| invalidate_hashes_ = false;
|
| return;
|
| @@ -107,7 +106,7 @@ class VisitedLinkUpdater {
|
| if (pending_.empty())
|
| return;
|
|
|
| - process->Send(new ChromeViewMsg_VisitedLink_Add(pending_));
|
| + sink_->AddVisitedLinks(pending_);
|
|
|
| pending_.clear();
|
| }
|
| @@ -116,13 +115,13 @@ class VisitedLinkUpdater {
|
| bool reset_needed_;
|
| bool invalidate_hashes_;
|
| int render_process_id_;
|
| + mojom::VisitedLinkNotificationSinkPtr sink_;
|
| VisitedLinkCommon::Fingerprints pending_;
|
| };
|
|
|
| VisitedLinkEventListener::VisitedLinkEventListener(
|
| - VisitedLinkMaster* master,
|
| content::BrowserContext* browser_context)
|
| - : master_(master),
|
| + : coalesce_timer_(&default_coalesce_timer_),
|
| browser_context_(browser_context) {
|
| registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED,
|
| content::NotificationService::AllBrowserContextsAndSources());
|
| @@ -137,8 +136,10 @@ VisitedLinkEventListener::~VisitedLinkEventListener() {
|
| pending_visited_links_.clear();
|
| }
|
|
|
| -void VisitedLinkEventListener::NewTable(base::SharedMemory* table_memory) {
|
| - if (!table_memory)
|
| +void VisitedLinkEventListener::NewTable(mojo::SharedBufferHandle table) {
|
| + DCHECK(table.is_valid());
|
| + shared_memory_ = table.Clone(mojo::SharedBufferHandle::AccessMode::READ_ONLY);
|
| + if (!shared_memory_.is_valid())
|
| return;
|
|
|
| // Send to all RenderProcessHosts.
|
| @@ -149,23 +150,24 @@ void VisitedLinkEventListener::NewTable(base::SharedMemory* table_memory) {
|
| if (!process)
|
| continue;
|
|
|
| - i->second->SendVisitedLinkTable(table_memory);
|
| + i->second->SendVisitedLinkTable(shared_memory_.get());
|
| }
|
| }
|
|
|
| void VisitedLinkEventListener::Add(VisitedLinkMaster::Fingerprint fingerprint) {
|
| pending_visited_links_.push_back(fingerprint);
|
|
|
| - if (!coalesce_timer_.IsRunning()) {
|
| - coalesce_timer_.Start(FROM_HERE,
|
| - TimeDelta::FromMilliseconds(kCommitIntervalMs), this,
|
| - &VisitedLinkEventListener::CommitVisitedLinks);
|
| + if (!coalesce_timer_->IsRunning()) {
|
| + coalesce_timer_->Start(
|
| + FROM_HERE, TimeDelta::FromMilliseconds(kCommitIntervalMs),
|
| + base::Bind(&VisitedLinkEventListener::CommitVisitedLinks,
|
| + base::Unretained(this)));
|
| }
|
| }
|
|
|
| void VisitedLinkEventListener::Reset(bool invalidate_hashes) {
|
| pending_visited_links_.clear();
|
| - coalesce_timer_.Stop();
|
| + coalesce_timer_->Stop();
|
|
|
| for (Updaters::iterator i = updaters_.begin(); i != updaters_.end(); ++i) {
|
| i->second->AddReset(invalidate_hashes);
|
| @@ -173,6 +175,11 @@ void VisitedLinkEventListener::Reset(bool invalidate_hashes) {
|
| }
|
| }
|
|
|
| +void VisitedLinkEventListener::SetCoalesceTimerForTest(
|
| + base::Timer* coalesce_timer_override) {
|
| + coalesce_timer_ = coalesce_timer_override;
|
| +}
|
| +
|
| void VisitedLinkEventListener::CommitVisitedLinks() {
|
| // Send to all RenderProcessHosts.
|
| for (Updaters::iterator i = updaters_.begin(); i != updaters_.end(); ++i) {
|
| @@ -195,13 +202,12 @@ void VisitedLinkEventListener::Observe(
|
| return;
|
|
|
| // Happens on browser start up.
|
| - if (!master_->shared_memory())
|
| + if (!shared_memory_.is_valid())
|
| return;
|
|
|
| - updaters_[process->GetID()] =
|
| - make_linked_ptr(new VisitedLinkUpdater(process->GetID()));
|
| - updaters_[process->GetID()]->SendVisitedLinkTable(
|
| - master_->shared_memory());
|
| + updaters_[process->GetID()].reset(
|
| + new VisitedLinkUpdater(process->GetID()));
|
| + updaters_[process->GetID()]->SendVisitedLinkTable(shared_memory_.get());
|
| break;
|
| }
|
| case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: {
|
|
|