Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: chrome/renderer/visitedlink_slave.cc

Issue 11825011: Componentize visitedlinks to src/components/visitedlink (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Final rebase Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/visitedlink_slave.h ('k') | components/components.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2006-2008 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/renderer/visitedlink_slave.h"
6
7 #include "base/logging.h"
8 #include "base/shared_memory.h"
9 #include "chrome/common/render_messages.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
11
12 using WebKit::WebView;
13
14 VisitedLinkSlave::VisitedLinkSlave() : shared_memory_(NULL) {
15 }
16
17 VisitedLinkSlave::~VisitedLinkSlave() {
18 FreeTable();
19 }
20
21 bool VisitedLinkSlave::OnControlMessageReceived(const IPC::Message& message) {
22 bool handled = true;
23 IPC_BEGIN_MESSAGE_MAP(VisitedLinkSlave, message)
24 IPC_MESSAGE_HANDLER(ChromeViewMsg_VisitedLink_NewTable,
25 OnUpdateVisitedLinks)
26 IPC_MESSAGE_HANDLER(ChromeViewMsg_VisitedLink_Add, OnAddVisitedLinks)
27 IPC_MESSAGE_HANDLER(ChromeViewMsg_VisitedLink_Reset, OnResetVisitedLinks)
28 IPC_MESSAGE_UNHANDLED(handled = false)
29 IPC_END_MESSAGE_MAP()
30 return handled;
31 }
32
33 // This function's job is to initialize the table with the given
34 // shared memory handle. This memory is mapped into the process.
35 void VisitedLinkSlave::OnUpdateVisitedLinks(base::SharedMemoryHandle table) {
36 DCHECK(base::SharedMemory::IsHandleValid(table)) << "Bad table handle";
37 // since this function may be called again to change the table, we may need
38 // to free old objects
39 FreeTable();
40 DCHECK(shared_memory_ == NULL && hash_table_ == NULL);
41
42 // create the shared memory object
43 shared_memory_ = new base::SharedMemory(table, true);
44 if (!shared_memory_)
45 return;
46
47 // map the header into our process so we can see how long the rest is,
48 // and set the salt
49 if (!shared_memory_->Map(sizeof(SharedHeader)))
50 return;
51 SharedHeader* header =
52 static_cast<SharedHeader*>(shared_memory_->memory());
53 DCHECK(header);
54 int32 table_len = header->length;
55 memcpy(salt_, header->salt, sizeof(salt_));
56 shared_memory_->Unmap();
57
58 // now do the whole table because we know the length
59 if (!shared_memory_->Map(sizeof(SharedHeader) +
60 table_len * sizeof(Fingerprint))) {
61 shared_memory_->Close();
62 return;
63 }
64
65 // commit the data
66 DCHECK(shared_memory_->memory());
67 hash_table_ = reinterpret_cast<Fingerprint*>(
68 static_cast<char*>(shared_memory_->memory()) + sizeof(SharedHeader));
69 table_length_ = table_len;
70 }
71
72 void VisitedLinkSlave::OnAddVisitedLinks(
73 const VisitedLinkSlave::Fingerprints& fingerprints) {
74 for (size_t i = 0; i < fingerprints.size(); ++i)
75 WebView::updateVisitedLinkState(fingerprints[i]);
76 }
77
78 void VisitedLinkSlave::OnResetVisitedLinks() {
79 WebView::resetVisitedLinkState();
80 }
81
82 void VisitedLinkSlave::FreeTable() {
83 if (shared_memory_) {
84 delete shared_memory_;
85 shared_memory_ = NULL;
86 }
87 hash_table_ = NULL;
88 table_length_ = 0;
89 }
OLDNEW
« no previous file with comments | « chrome/renderer/visitedlink_slave.h ('k') | components/components.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698