Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / components / visitedlink / browser / visitedlink_event_listener.h
1 // Copyright (c) 2011 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 #ifndef COMPONENTS_VISITEDLINK_BROWSER_VISITEDLINK_EVENT_LISTENER_H_
6 #define COMPONENTS_VISITEDLINK_BROWSER_VISITEDLINK_EVENT_LISTENER_H_
7
8 #include <map>
9
10 #include "base/memory/linked_ptr.h"
11 #include "base/timer/timer.h"
12 #include "components/visitedlink/browser/visitedlink_master.h"
13 #include "content/public/browser/notification_observer.h"
14 #include "content/public/browser/notification_registrar.h"
15
16 namespace base {
17 class SharedMemory;
18 }
19
20 namespace content {
21 class BrowserContext;
22 }
23
24 namespace visitedlink {
25
26 class VisitedLinkUpdater;
27
28 // VisitedLinkEventListener broadcasts link coloring database updates to all
29 // processes. It also coalesces the updates to avoid excessive broadcasting of
30 // messages to the renderers.
31 class VisitedLinkEventListener : public VisitedLinkMaster::Listener,
32                                  public content::NotificationObserver {
33  public:
34   VisitedLinkEventListener(VisitedLinkMaster* master,
35                            content::BrowserContext* browser_context);
36   ~VisitedLinkEventListener() override;
37
38   void NewTable(base::SharedMemory* table_memory) override;
39   void Add(VisitedLinkMaster::Fingerprint fingerprint) override;
40   void Reset() override;
41
42  private:
43   void CommitVisitedLinks();
44
45   // content::NotificationObserver implementation.
46   void Observe(int type,
47                const content::NotificationSource& source,
48                const content::NotificationDetails& details) override;
49
50   base::OneShotTimer<VisitedLinkEventListener> coalesce_timer_;
51   VisitedLinkCommon::Fingerprints pending_visited_links_;
52
53   content::NotificationRegistrar registrar_;
54
55   // Map between renderer child ids and their VisitedLinkUpdater.
56   typedef std::map<int, linked_ptr<VisitedLinkUpdater> > Updaters;
57   Updaters updaters_;
58
59   VisitedLinkMaster* master_;
60
61   // Used to filter RENDERER_PROCESS_CREATED notifications to renderers that
62   // belong to this BrowserContext.
63   content::BrowserContext* browser_context_;
64
65   DISALLOW_COPY_AND_ASSIGN(VisitedLinkEventListener);
66 };
67
68 }  // namespace visitedlink
69
70 #endif  // COMPONENTS_VISITEDLINK_BROWSER_VISITEDLINK_EVENT_LISTENER_H_