Chromium Code Reviews| 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 "chrome/utility/importer/ie_importer_win.h" | 5 #include "chrome/utility/importer/ie_importer_win.h" |
| 6 | 6 |
| 7 #include <ole2.h> | 7 #include <ole2.h> |
| 8 #include <intshcut.h> | 8 #include <intshcut.h> |
| 9 #include <shlobj.h> | 9 #include <shlobj.h> |
| 10 #include <urlhist.h> | 10 #include <urlhist.h> |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 470 } | 470 } |
| 471 | 471 |
| 472 void IEImporter::ImportHistory() { | 472 void IEImporter::ImportHistory() { |
| 473 const std::string kSchemes[] = {url::kHttpScheme, | 473 const std::string kSchemes[] = {url::kHttpScheme, |
| 474 url::kHttpsScheme, | 474 url::kHttpsScheme, |
| 475 url::kFtpScheme, | 475 url::kFtpScheme, |
| 476 url::kFileScheme}; | 476 url::kFileScheme}; |
| 477 int total_schemes = arraysize(kSchemes); | 477 int total_schemes = arraysize(kSchemes); |
| 478 | 478 |
| 479 base::win::ScopedComPtr<IUrlHistoryStg2> url_history_stg2; | 479 base::win::ScopedComPtr<IUrlHistoryStg2> url_history_stg2; |
| 480 HRESULT result; | 480 if (FAILED(url_history_stg2.CreateInstance(CLSID_CUrlHistory, NULL, |
| 481 result = url_history_stg2.CreateInstance(CLSID_CUrlHistory, NULL, | 481 CLSCTX_INPROC_SERVER))) { |
| 482 CLSCTX_INPROC_SERVER); | |
| 483 if (FAILED(result)) | |
| 484 return; | 482 return; |
| 483 } | |
| 485 base::win::ScopedComPtr<IEnumSTATURL> enum_url; | 484 base::win::ScopedComPtr<IEnumSTATURL> enum_url; |
| 486 if (SUCCEEDED(result = url_history_stg2->EnumUrls(enum_url.Receive()))) { | 485 if (SUCCEEDED(url_history_stg2->EnumUrls(enum_url.Receive()))) { |
| 487 std::vector<ImporterURLRow> rows; | 486 std::vector<ImporterURLRow> rows; |
| 488 STATURL stat_url; | 487 STATURL stat_url; |
| 489 ULONG fetched; | 488 |
| 489 // IEnumSTATURL::Next() doesn't fill STATURL::dwFlags by default. Need to | |
| 490 // call IEnumSTATURL::SetFilter() with STATURL_QUERYFLAG_TOPLEVEL | | |
| 491 // STATURL_QUERYFLAG_ISCACHED flags to specify how STATURL will be filled. | |
| 492 // First argument of IEnumSTATURL::SetFilter() specifies the URL prefix | |
| 493 // that is used by IEnumSTATURL::Next() for filtering items by URL. | |
| 494 // So need to pass an empty string here to get all history items. | |
| 495 enum_url->SetFilter(L"", STATURL_QUERYFLAG_TOPLEVEL | | |
| 496 STATURL_QUERYFLAG_ISCACHED); | |
|
gab
2014/12/17 18:55:30
One last question, IIUC STATURL_QUERYFLAG_ISCACHED
Alexey Seren
2014/12/18 12:08:15
Yes, we can miss STATURL_QUERYFLAG_ISCACHED during
gab
2014/12/18 15:48:01
Right, but given we have STATURL_QUERYFLAG_ISCACHE
Alexey Seren
2014/12/22 13:01:40
You are right. It seems like STATURL_QUERYFLAG_ISC
| |
| 490 while (!cancelled() && | 497 while (!cancelled() && |
| 491 (result = enum_url->Next(1, &stat_url, &fetched)) == S_OK) { | 498 enum_url->Next(1, &stat_url, NULL) == S_OK) { |
| 492 base::string16 url_string; | 499 base::string16 url_string; |
| 493 if (stat_url.pwcsUrl) { | 500 if (stat_url.pwcsUrl) { |
| 494 url_string = stat_url.pwcsUrl; | 501 url_string = stat_url.pwcsUrl; |
| 495 CoTaskMemFree(stat_url.pwcsUrl); | 502 CoTaskMemFree(stat_url.pwcsUrl); |
| 496 } | 503 } |
| 497 base::string16 title_string; | 504 base::string16 title_string; |
| 498 if (stat_url.pwcsTitle) { | 505 if (stat_url.pwcsTitle) { |
| 499 title_string = stat_url.pwcsTitle; | 506 title_string = stat_url.pwcsTitle; |
| 500 CoTaskMemFree(stat_url.pwcsTitle); | 507 CoTaskMemFree(stat_url.pwcsTitle); |
| 501 } | 508 } |
| 502 | 509 |
| 503 GURL url(url_string); | 510 GURL url(url_string); |
| 504 // Skips the URLs that are invalid or have other schemes. | 511 // Skips the URLs that are invalid or have other schemes. |
| 505 if (!url.is_valid() || | 512 if (!url.is_valid() || |
| 506 (std::find(kSchemes, kSchemes + total_schemes, url.scheme()) == | 513 (std::find(kSchemes, kSchemes + total_schemes, url.scheme()) == |
| 507 kSchemes + total_schemes)) | 514 kSchemes + total_schemes)) |
| 508 continue; | 515 continue; |
| 509 | 516 |
| 510 ImporterURLRow row(url); | 517 ImporterURLRow row(url); |
| 511 row.title = title_string; | 518 row.title = title_string; |
| 512 row.last_visit = base::Time::FromFileTime(stat_url.ftLastVisited); | 519 row.last_visit = base::Time::FromFileTime(stat_url.ftLastVisited); |
| 513 if (stat_url.dwFlags == STATURL_QUERYFLAG_TOPLEVEL) { | 520 if (stat_url.dwFlags & STATURLFLAG_ISTOPLEVEL) { |
| 514 row.visit_count = 1; | 521 row.visit_count = 1; |
| 515 row.hidden = false; | 522 row.hidden = false; |
| 516 } else { | 523 } else { |
| 524 DCHECK(stat_url.dwFlags == STATURLFLAG_ISCACHED); | |
|
gab
2014/12/17 18:55:30
DCHECK_EQ(stat_url.dwFlags, STATURLFLAG_ISCACHED);
Alexey Seren
2014/12/18 12:08:15
Ok, I will change it if it will not be removed (du
| |
| 517 row.hidden = true; | 525 row.hidden = true; |
| 518 } | 526 } |
| 519 | 527 |
| 520 rows.push_back(row); | 528 rows.push_back(row); |
| 521 } | 529 } |
| 522 | 530 |
| 523 if (!rows.empty() && !cancelled()) { | 531 if (!rows.empty() && !cancelled()) { |
| 524 bridge_->SetHistoryItems(rows, importer::VISIT_SOURCE_IE_IMPORTED); | 532 bridge_->SetHistoryItems(rows, importer::VISIT_SOURCE_IE_IMPORTED); |
| 525 } | 533 } |
| 526 } | 534 } |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 874 static int version = -1; | 882 static int version = -1; |
| 875 if (version < 0) { | 883 if (version < 0) { |
| 876 wchar_t buffer[128]; | 884 wchar_t buffer[128]; |
| 877 DWORD buffer_length = sizeof(buffer); | 885 DWORD buffer_length = sizeof(buffer); |
| 878 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, kIEVersionKey, KEY_READ); | 886 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, kIEVersionKey, KEY_READ); |
| 879 LONG result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL); | 887 LONG result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL); |
| 880 version = ((result == ERROR_SUCCESS)? _wtoi(buffer) : 0); | 888 version = ((result == ERROR_SUCCESS)? _wtoi(buffer) : 0); |
| 881 } | 889 } |
| 882 return version; | 890 return version; |
| 883 } | 891 } |
| OLD | NEW |