OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "components/visitedlink/browser/visitedlink_master.h" | 5 #include "components/visitedlink/browser/visitedlink_master.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #include <io.h> | 9 #include <io.h> |
10 #include <shlobj.h> | 10 #include <shlobj.h> |
11 #endif // defined(OS_WIN) | 11 #endif // defined(OS_WIN) |
12 #include <stdio.h> | 12 #include <stdio.h> |
13 | 13 |
14 #include <algorithm> | 14 #include <algorithm> |
15 | 15 |
16 #include "base/bind.h" | 16 #include "base/bind.h" |
17 #include "base/bind_helpers.h" | 17 #include "base/bind_helpers.h" |
18 #include "base/containers/stack_container.h" | 18 #include "base/containers/stack_container.h" |
19 #include "base/file_util.h" | 19 #include "base/file_util.h" |
| 20 #include "base/files/scoped_file.h" |
20 #include "base/logging.h" | 21 #include "base/logging.h" |
21 #include "base/message_loop/message_loop.h" | 22 #include "base/message_loop/message_loop.h" |
22 #include "base/path_service.h" | 23 #include "base/path_service.h" |
23 #include "base/rand_util.h" | 24 #include "base/rand_util.h" |
24 #include "base/strings/string_util.h" | 25 #include "base/strings/string_util.h" |
25 #include "base/threading/thread_restrictions.h" | 26 #include "base/threading/thread_restrictions.h" |
26 #include "components/visitedlink/browser/visitedlink_delegate.h" | 27 #include "components/visitedlink/browser/visitedlink_delegate.h" |
27 #include "components/visitedlink/browser/visitedlink_event_listener.h" | 28 #include "components/visitedlink/browser/visitedlink_event_listener.h" |
28 #include "content/public/browser/browser_context.h" | 29 #include "content/public/browser/browser_context.h" |
29 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
30 #include "url/gurl.h" | 31 #include "url/gurl.h" |
31 | 32 |
32 using content::BrowserThread; | 33 using content::BrowserThread; |
33 using file_util::ScopedFILE; | |
34 | 34 |
35 namespace visitedlink { | 35 namespace visitedlink { |
36 | 36 |
37 const int32 VisitedLinkMaster::kFileHeaderSignatureOffset = 0; | 37 const int32 VisitedLinkMaster::kFileHeaderSignatureOffset = 0; |
38 const int32 VisitedLinkMaster::kFileHeaderVersionOffset = 4; | 38 const int32 VisitedLinkMaster::kFileHeaderVersionOffset = 4; |
39 const int32 VisitedLinkMaster::kFileHeaderLengthOffset = 8; | 39 const int32 VisitedLinkMaster::kFileHeaderLengthOffset = 8; |
40 const int32 VisitedLinkMaster::kFileHeaderUsedOffset = 12; | 40 const int32 VisitedLinkMaster::kFileHeaderUsedOffset = 12; |
41 const int32 VisitedLinkMaster::kFileHeaderSaltOffset = 16; | 41 const int32 VisitedLinkMaster::kFileHeaderSaltOffset = 16; |
42 | 42 |
43 const int32 VisitedLinkMaster::kFileCurrentVersion = 3; | 43 const int32 VisitedLinkMaster::kFileCurrentVersion = 3; |
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 // The hash table may have shrunk, so make sure this is the end. | 533 // The hash table may have shrunk, so make sure this is the end. |
534 PostIOTask(FROM_HERE, base::Bind(&AsyncTruncate, file_)); | 534 PostIOTask(FROM_HERE, base::Bind(&AsyncTruncate, file_)); |
535 } | 535 } |
536 | 536 |
537 bool VisitedLinkMaster::InitFromFile() { | 537 bool VisitedLinkMaster::InitFromFile() { |
538 DCHECK(file_ == NULL); | 538 DCHECK(file_ == NULL); |
539 DCHECK(persist_to_disk_); | 539 DCHECK(persist_to_disk_); |
540 | 540 |
541 base::FilePath filename; | 541 base::FilePath filename; |
542 GetDatabaseFileName(&filename); | 542 GetDatabaseFileName(&filename); |
543 ScopedFILE file_closer(base::OpenFile(filename, "rb+")); | 543 base::ScopedFILE file_closer(base::OpenFile(filename, "rb+")); |
544 if (!file_closer.get()) | 544 if (!file_closer.get()) |
545 return false; | 545 return false; |
546 | 546 |
547 int32 num_entries, used_count; | 547 int32 num_entries, used_count; |
548 if (!ReadFileHeader(file_closer.get(), &num_entries, &used_count, salt_)) | 548 if (!ReadFileHeader(file_closer.get(), &num_entries, &used_count, salt_)) |
549 return false; // Header isn't valid. | 549 return false; // Header isn't valid. |
550 | 550 |
551 // Allocate and read the table. | 551 // Allocate and read the table. |
552 if (!CreateURLTable(num_entries, false)) | 552 if (!CreateURLTable(num_entries, false)) |
553 return false; | 553 return false; |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
978 BrowserThread::UI, FROM_HERE, | 978 BrowserThread::UI, FROM_HERE, |
979 base::Bind(&TableBuilder::OnCompleteMainThread, this)); | 979 base::Bind(&TableBuilder::OnCompleteMainThread, this)); |
980 } | 980 } |
981 | 981 |
982 void VisitedLinkMaster::TableBuilder::OnCompleteMainThread() { | 982 void VisitedLinkMaster::TableBuilder::OnCompleteMainThread() { |
983 if (master_) | 983 if (master_) |
984 master_->OnTableRebuildComplete(success_, fingerprints_); | 984 master_->OnTableRebuildComplete(success_, fingerprints_); |
985 } | 985 } |
986 | 986 |
987 } // namespace visitedlink | 987 } // namespace visitedlink |
OLD | NEW |