| 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/browser/extensions/updater/extension_updater.h" | 5 #include "chrome/browser/extensions/updater/extension_updater.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <list> | 10 #include <list> |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 void AddFakeCrxInstaller(const std::string& id, CrxInstaller* crx_installer) { | 500 void AddFakeCrxInstaller(const std::string& id, CrxInstaller* crx_installer) { |
| 501 fake_crx_installers_[id] = crx_installer; | 501 fake_crx_installers_[id] = crx_installer; |
| 502 } | 502 } |
| 503 | 503 |
| 504 bool UpdateExtension(const CRXFileInfo& file, | 504 bool UpdateExtension(const CRXFileInfo& file, |
| 505 bool file_ownership_passed, | 505 bool file_ownership_passed, |
| 506 CrxInstaller** out_crx_installer) override { | 506 CrxInstaller** out_crx_installer) override { |
| 507 extension_id_ = file.extension_id; | 507 extension_id_ = file.extension_id; |
| 508 install_path_ = file.path; | 508 install_path_ = file.path; |
| 509 | 509 |
| 510 if (ContainsKey(fake_crx_installers_, extension_id_)) { | 510 if (base::ContainsKey(fake_crx_installers_, extension_id_)) { |
| 511 *out_crx_installer = fake_crx_installers_[extension_id_]; | 511 *out_crx_installer = fake_crx_installers_[extension_id_]; |
| 512 return true; | 512 return true; |
| 513 } | 513 } |
| 514 | 514 |
| 515 return false; | 515 return false; |
| 516 } | 516 } |
| 517 | 517 |
| 518 PendingExtensionManager* pending_extension_manager() override { | 518 PendingExtensionManager* pending_extension_manager() override { |
| 519 return &pending_extension_manager_; | 519 return &pending_extension_manager_; |
| 520 } | 520 } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 // We've found "x=<something>", now unescape <something> and look for | 587 // We've found "x=<something>", now unescape <something> and look for |
| 588 // the "id=<id>&ping=<ping_value>" parameters within. | 588 // the "id=<id>&ping=<ping_value>" parameters within. |
| 589 std::string unescaped = net::UnescapeURLComponent( | 589 std::string unescaped = net::UnescapeURLComponent( |
| 590 param.second, | 590 param.second, |
| 591 net::UnescapeRule::PATH_SEPARATORS | | 591 net::UnescapeRule::PATH_SEPARATORS | |
| 592 net::UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS); | 592 net::UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS); |
| 593 base::StringPairs extension_params; | 593 base::StringPairs extension_params; |
| 594 base::SplitStringIntoKeyValuePairs(unescaped, '=', '&', &extension_params); | 594 base::SplitStringIntoKeyValuePairs(unescaped, '=', '&', &extension_params); |
| 595 std::multimap<std::string, std::string> param_map; | 595 std::multimap<std::string, std::string> param_map; |
| 596 param_map.insert(extension_params.begin(), extension_params.end()); | 596 param_map.insert(extension_params.begin(), extension_params.end()); |
| 597 if (ContainsKey(param_map, "id") && ContainsKey(param_map, "ping")) { | 597 if (base::ContainsKey(param_map, "id") && |
| 598 base::ContainsKey(param_map, "ping")) { |
| 598 std::string id = param_map.find("id")->second; | 599 std::string id = param_map.find("id")->second; |
| 599 result[id] = ParamsMap(); | 600 result[id] = ParamsMap(); |
| 600 | 601 |
| 601 // Pull the key=value pairs out of the ping parameter for this id and | 602 // Pull the key=value pairs out of the ping parameter for this id and |
| 602 // put into the result. | 603 // put into the result. |
| 603 std::string ping = net::UnescapeURLComponent( | 604 std::string ping = net::UnescapeURLComponent( |
| 604 param_map.find("ping")->second, | 605 param_map.find("ping")->second, |
| 605 net::UnescapeRule::PATH_SEPARATORS | | 606 net::UnescapeRule::PATH_SEPARATORS | |
| 606 net::UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS); | 607 net::UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS); |
| 607 base::StringPairs ping_params; | 608 base::StringPairs ping_params; |
| 608 base::SplitStringIntoKeyValuePairs(ping, '=', '&', &ping_params); | 609 base::SplitStringIntoKeyValuePairs(ping, '=', '&', &ping_params); |
| 609 for (const auto& ping_param : ping_params) { | 610 for (const auto& ping_param : ping_params) { |
| 610 if (!ContainsKey(result[id], ping_param.first)) | 611 if (!base::ContainsKey(result[id], ping_param.first)) |
| 611 result[id][ping_param.first] = std::set<std::string>(); | 612 result[id][ping_param.first] = std::set<std::string>(); |
| 612 result[id][ping_param.first].insert(ping_param.second); | 613 result[id][ping_param.first].insert(ping_param.second); |
| 613 } | 614 } |
| 614 } | 615 } |
| 615 } | 616 } |
| 616 return result; | 617 return result; |
| 617 } | 618 } |
| 618 | 619 |
| 619 static void VerifyQueryAndExtractParameters( | 620 static void VerifyQueryAndExtractParameters( |
| 620 const std::string& query, | 621 const std::string& query, |
| (...skipping 1080 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1701 url2_fetch_url = fetched_urls[0]; | 1702 url2_fetch_url = fetched_urls[0]; |
| 1702 url1_query = fetched_urls[1].query(); | 1703 url1_query = fetched_urls[1].query(); |
| 1703 url2_query = fetched_urls[0].query(); | 1704 url2_query = fetched_urls[0].query(); |
| 1704 } else { | 1705 } else { |
| 1705 NOTREACHED(); | 1706 NOTREACHED(); |
| 1706 } | 1707 } |
| 1707 | 1708 |
| 1708 std::map<std::string, ParamsMap> url1_ping_data = | 1709 std::map<std::string, ParamsMap> url1_ping_data = |
| 1709 GetPingDataFromURL(url1_fetch_url); | 1710 GetPingDataFromURL(url1_fetch_url); |
| 1710 ParamsMap url1_params = ParamsMap(); | 1711 ParamsMap url1_params = ParamsMap(); |
| 1711 if (!url1_ping_data.empty() && ContainsKey(url1_ping_data, id)) | 1712 if (!url1_ping_data.empty() && base::ContainsKey(url1_ping_data, id)) |
| 1712 url1_params = url1_ping_data[id]; | 1713 url1_params = url1_ping_data[id]; |
| 1713 | 1714 |
| 1714 // First make sure the non-google query had no ping parameter. | 1715 // First make sure the non-google query had no ping parameter. |
| 1715 EXPECT_TRUE(GetPingDataFromURL(url2_fetch_url).empty()); | 1716 EXPECT_TRUE(GetPingDataFromURL(url2_fetch_url).empty()); |
| 1716 | 1717 |
| 1717 // Now make sure the google query had the correct ping parameter. | 1718 // Now make sure the google query had the correct ping parameter. |
| 1718 bool did_rollcall = false; | 1719 bool did_rollcall = false; |
| 1719 if (rollcall_ping_days != 0) { | 1720 if (rollcall_ping_days != 0) { |
| 1720 ASSERT_TRUE(ContainsKey(url1_params, "r")); | 1721 ASSERT_TRUE(base::ContainsKey(url1_params, "r")); |
| 1721 ASSERT_EQ(1u, url1_params["r"].size()); | 1722 ASSERT_EQ(1u, url1_params["r"].size()); |
| 1722 EXPECT_EQ(base::IntToString(rollcall_ping_days), | 1723 EXPECT_EQ(base::IntToString(rollcall_ping_days), |
| 1723 *url1_params["r"].begin()); | 1724 *url1_params["r"].begin()); |
| 1724 did_rollcall = true; | 1725 did_rollcall = true; |
| 1725 } | 1726 } |
| 1726 if (active_bit && active_ping_days != 0 && did_rollcall) { | 1727 if (active_bit && active_ping_days != 0 && did_rollcall) { |
| 1727 ASSERT_TRUE(ContainsKey(url1_params, "a")); | 1728 ASSERT_TRUE(base::ContainsKey(url1_params, "a")); |
| 1728 ASSERT_EQ(1u, url1_params["a"].size()); | 1729 ASSERT_EQ(1u, url1_params["a"].size()); |
| 1729 EXPECT_EQ(base::IntToString(active_ping_days), | 1730 EXPECT_EQ(base::IntToString(active_ping_days), |
| 1730 *url1_params["a"].begin()); | 1731 *url1_params["a"].begin()); |
| 1731 } | 1732 } |
| 1732 | 1733 |
| 1733 // Make sure the non-google query has no brand parameter. | 1734 // Make sure the non-google query has no brand parameter. |
| 1734 const std::string brand_string = "brand%3D"; | 1735 const std::string brand_string = "brand%3D"; |
| 1735 EXPECT_TRUE(url2_query.find(brand_string) == std::string::npos); | 1736 EXPECT_TRUE(url2_query.find(brand_string) == std::string::npos); |
| 1736 | 1737 |
| 1737 #if defined(GOOGLE_CHROME_BUILD) | 1738 #if defined(GOOGLE_CHROME_BUILD) |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1836 const GURL& url = fetcher->GetOriginalURL(); | 1837 const GURL& url = fetcher->GetOriginalURL(); |
| 1837 EXPECT_FALSE(url.is_empty()); | 1838 EXPECT_FALSE(url.is_empty()); |
| 1838 EXPECT_TRUE(url.is_valid()); | 1839 EXPECT_TRUE(url.is_valid()); |
| 1839 EXPECT_TRUE(url.has_query()); | 1840 EXPECT_TRUE(url.has_query()); |
| 1840 | 1841 |
| 1841 std::map<std::string, ParamsMap> all_pings = GetPingDataFromURL(url); | 1842 std::map<std::string, ParamsMap> all_pings = GetPingDataFromURL(url); |
| 1842 | 1843 |
| 1843 // Make sure that all the enabled extensions have "e=1" in their ping | 1844 // Make sure that all the enabled extensions have "e=1" in their ping |
| 1844 // parameter. | 1845 // parameter. |
| 1845 for (const auto& ext : enabled_extensions) { | 1846 for (const auto& ext : enabled_extensions) { |
| 1846 ASSERT_TRUE(ContainsKey(all_pings, ext->id())); | 1847 ASSERT_TRUE(base::ContainsKey(all_pings, ext->id())); |
| 1847 ParamsMap& ping = all_pings[ext->id()]; | 1848 ParamsMap& ping = all_pings[ext->id()]; |
| 1848 EXPECT_FALSE(ContainsKey(ping, "dr")); | 1849 EXPECT_FALSE(base::ContainsKey(ping, "dr")); |
| 1849 ASSERT_TRUE(ContainsKey(ping, "e")) << url; | 1850 ASSERT_TRUE(base::ContainsKey(ping, "e")) << url; |
| 1850 std::set<std::string> e = ping["e"]; | 1851 std::set<std::string> e = ping["e"]; |
| 1851 ASSERT_EQ(1u, e.size()) << url; | 1852 ASSERT_EQ(1u, e.size()) << url; |
| 1852 EXPECT_EQ(std::string("1"), *e.begin()) << url; | 1853 EXPECT_EQ(std::string("1"), *e.begin()) << url; |
| 1853 EXPECT_FALSE(ContainsKey(ping, "dr")); | 1854 EXPECT_FALSE(base::ContainsKey(ping, "dr")); |
| 1854 } | 1855 } |
| 1855 | 1856 |
| 1856 // Make sure that all the disable extensions have the appropriate | 1857 // Make sure that all the disable extensions have the appropriate |
| 1857 // "dr=<num>" values in their ping parameter if metrics are on, or omit | 1858 // "dr=<num>" values in their ping parameter if metrics are on, or omit |
| 1858 // it otherwise. | 1859 // it otherwise. |
| 1859 ASSERT_EQ(disabled_extensions.size(), disabled.size()); | 1860 ASSERT_EQ(disabled_extensions.size(), disabled.size()); |
| 1860 for (size_t i = 0; i < disabled.size(); i++) { | 1861 for (size_t i = 0; i < disabled.size(); i++) { |
| 1861 scoped_refptr<const Extension>& ext = disabled_extensions[i]; | 1862 scoped_refptr<const Extension>& ext = disabled_extensions[i]; |
| 1862 int disable_reasons = disabled[i]; | 1863 int disable_reasons = disabled[i]; |
| 1863 ASSERT_TRUE(ContainsKey(all_pings, ext->id())) << url; | 1864 ASSERT_TRUE(base::ContainsKey(all_pings, ext->id())) << url; |
| 1864 ParamsMap& ping = all_pings[ext->id()]; | 1865 ParamsMap& ping = all_pings[ext->id()]; |
| 1865 | 1866 |
| 1866 ASSERT_TRUE(ContainsKey(ping, "e")) << url; | 1867 ASSERT_TRUE(base::ContainsKey(ping, "e")) << url; |
| 1867 std::set<std::string> e = ping["e"]; | 1868 std::set<std::string> e = ping["e"]; |
| 1868 ASSERT_EQ(1u, e.size()) << url; | 1869 ASSERT_EQ(1u, e.size()) << url; |
| 1869 EXPECT_EQ(std::string("0"), *e.begin()) << url; | 1870 EXPECT_EQ(std::string("0"), *e.begin()) << url; |
| 1870 | 1871 |
| 1871 if (disable_reasons == 0) { | 1872 if (disable_reasons == 0) { |
| 1872 EXPECT_FALSE(ContainsKey(ping, "dr")); | 1873 EXPECT_FALSE(base::ContainsKey(ping, "dr")); |
| 1873 } else { | 1874 } else { |
| 1874 ASSERT_TRUE(ContainsKey(ping, "dr")); | 1875 ASSERT_TRUE(base::ContainsKey(ping, "dr")); |
| 1875 int found_reasons = 0; | 1876 int found_reasons = 0; |
| 1876 for (const auto& reason_string : ping["dr"]) { | 1877 for (const auto& reason_string : ping["dr"]) { |
| 1877 int reason = 0; | 1878 int reason = 0; |
| 1878 ASSERT_TRUE(base::StringToInt(reason_string, &reason)); | 1879 ASSERT_TRUE(base::StringToInt(reason_string, &reason)); |
| 1879 // Make sure it's a power of 2. | 1880 // Make sure it's a power of 2. |
| 1880 ASSERT_TRUE(reason < 2 || !(reason & (reason - 1))) << reason; | 1881 ASSERT_TRUE(reason < 2 || !(reason & (reason - 1))) << reason; |
| 1881 found_reasons |= reason; | 1882 found_reasons |= reason; |
| 1882 } | 1883 } |
| 1883 EXPECT_EQ(disable_reasons, found_reasons); | 1884 EXPECT_EQ(disable_reasons, found_reasons); |
| 1884 } | 1885 } |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2262 // -prodversionmin (shouldn't update if browser version too old) | 2263 // -prodversionmin (shouldn't update if browser version too old) |
| 2263 // -manifests & updates arriving out of order / interleaved | 2264 // -manifests & updates arriving out of order / interleaved |
| 2264 // -malformed update url (empty, file://, has query, has a # fragment, etc.) | 2265 // -malformed update url (empty, file://, has query, has a # fragment, etc.) |
| 2265 // -An extension gets uninstalled while updates are in progress (so it doesn't | 2266 // -An extension gets uninstalled while updates are in progress (so it doesn't |
| 2266 // "come back from the dead") | 2267 // "come back from the dead") |
| 2267 // -An extension gets manually updated to v3 while we're downloading v2 (ie | 2268 // -An extension gets manually updated to v3 while we're downloading v2 (ie |
| 2268 // you don't get downgraded accidentally) | 2269 // you don't get downgraded accidentally) |
| 2269 // -An update manifest mentions multiple updates | 2270 // -An update manifest mentions multiple updates |
| 2270 | 2271 |
| 2271 } // namespace extensions | 2272 } // namespace extensions |
| OLD | NEW |