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/extension_updater.h" | 5 #include "chrome/browser/extensions/extension_updater.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
31 #include "chrome/common/chrome_notification_types.h" | 31 #include "chrome/common/chrome_notification_types.h" |
32 #include "chrome/common/chrome_switches.h" | 32 #include "chrome/common/chrome_switches.h" |
33 #include "chrome/common/chrome_utility_messages.h" | 33 #include "chrome/common/chrome_utility_messages.h" |
34 #include "chrome/common/chrome_version_info.h" | 34 #include "chrome/common/chrome_version_info.h" |
35 #include "chrome/common/extensions/extension.h" | 35 #include "chrome/common/extensions/extension.h" |
36 #include "chrome/common/extensions/extension_constants.h" | 36 #include "chrome/common/extensions/extension_constants.h" |
37 #include "chrome/common/extensions/extension_file_util.h" | 37 #include "chrome/common/extensions/extension_file_util.h" |
38 #include "chrome/common/pref_names.h" | 38 #include "chrome/common/pref_names.h" |
39 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 39 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
40 #include "content/browser/utility_process_host.h" | |
41 #include "content/public/browser/notification_service.h" | 40 #include "content/public/browser/notification_service.h" |
42 #include "content/public/browser/notification_source.h" | 41 #include "content/public/browser/notification_source.h" |
| 42 #include "content/public/browser/utility_process_host.h" |
43 #include "content/public/common/url_fetcher.h" | 43 #include "content/public/common/url_fetcher.h" |
44 #include "crypto/sha2.h" | 44 #include "crypto/sha2.h" |
45 #include "googleurl/src/gurl.h" | 45 #include "googleurl/src/gurl.h" |
46 #include "net/base/escape.h" | 46 #include "net/base/escape.h" |
47 #include "net/base/load_flags.h" | 47 #include "net/base/load_flags.h" |
48 #include "net/url_request/url_request_status.h" | 48 #include "net/url_request/url_request_status.h" |
49 | 49 |
50 #if defined(OS_MACOSX) | 50 #if defined(OS_MACOSX) |
51 #include "base/sys_string_conversions.h" | 51 #include "base/sys_string_conversions.h" |
52 #endif | 52 #endif |
53 | 53 |
54 #define SEND_ACTIVE_PINGS 1 | 54 #define SEND_ACTIVE_PINGS 1 |
55 | 55 |
56 using base::RandDouble; | 56 using base::RandDouble; |
57 using base::RandInt; | 57 using base::RandInt; |
58 using base::Time; | 58 using base::Time; |
59 using base::TimeDelta; | 59 using base::TimeDelta; |
60 using content::BrowserThread; | 60 using content::BrowserThread; |
| 61 using content::UtilityProcessHost; |
| 62 using content::UtilityProcessHostClient; |
61 using prefs::kExtensionBlacklistUpdateVersion; | 63 using prefs::kExtensionBlacklistUpdateVersion; |
62 using prefs::kLastExtensionsUpdateCheck; | 64 using prefs::kLastExtensionsUpdateCheck; |
63 using prefs::kNextExtensionsUpdateCheck; | 65 using prefs::kNextExtensionsUpdateCheck; |
64 | 66 |
65 // Update AppID for extension blacklist. | 67 // Update AppID for extension blacklist. |
66 const char* ExtensionUpdater::kBlacklistAppID = "com.google.crx.blacklist"; | 68 const char* ExtensionUpdater::kBlacklistAppID = "com.google.crx.blacklist"; |
67 | 69 |
68 namespace { | 70 namespace { |
69 | 71 |
70 // Wait at least 5 minutes after browser startup before we do any checks. If you | 72 // Wait at least 5 minutes after browser startup before we do any checks. If you |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 source->GetURL(), | 615 source->GetURL(), |
614 source->GetStatus(), | 616 source->GetStatus(), |
615 source->GetResponseCode()); | 617 source->GetResponseCode()); |
616 } else { | 618 } else { |
617 NOTREACHED(); | 619 NOTREACHED(); |
618 } | 620 } |
619 NotifyIfFinished(); | 621 NotifyIfFinished(); |
620 } | 622 } |
621 | 623 |
622 // Utility class to handle doing xml parsing in a sandboxed utility process. | 624 // Utility class to handle doing xml parsing in a sandboxed utility process. |
623 class SafeManifestParser : public UtilityProcessHost::Client { | 625 class SafeManifestParser : public UtilityProcessHostClient { |
624 public: | 626 public: |
625 // Takes ownership of |fetch_data|. | 627 // Takes ownership of |fetch_data|. |
626 SafeManifestParser(const std::string& xml, ManifestFetchData* fetch_data, | 628 SafeManifestParser(const std::string& xml, ManifestFetchData* fetch_data, |
627 base::WeakPtr<ExtensionUpdater> updater) | 629 base::WeakPtr<ExtensionUpdater> updater) |
628 : xml_(xml), updater_(updater) { | 630 : xml_(xml), updater_(updater) { |
629 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 631 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
630 fetch_data_.reset(fetch_data); | 632 fetch_data_.reset(fetch_data); |
631 } | 633 } |
632 | 634 |
633 // Posts a task over to the IO loop to start the parsing of xml_ in a | 635 // Posts a task over to the IO loop to start the parsing of xml_ in a |
(...skipping 11 matching lines...) Expand all Loading... |
645 | 647 |
646 // Creates the sandboxed utility process and tells it to start parsing. | 648 // Creates the sandboxed utility process and tells it to start parsing. |
647 void ParseInSandbox(ResourceDispatcherHost* rdh) { | 649 void ParseInSandbox(ResourceDispatcherHost* rdh) { |
648 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 650 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
649 | 651 |
650 // TODO(asargent) we shouldn't need to do this branch here - instead | 652 // TODO(asargent) we shouldn't need to do this branch here - instead |
651 // UtilityProcessHost should handle it for us. (http://crbug.com/19192) | 653 // UtilityProcessHost should handle it for us. (http://crbug.com/19192) |
652 bool use_utility_process = rdh && | 654 bool use_utility_process = rdh && |
653 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess); | 655 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess); |
654 if (use_utility_process) { | 656 if (use_utility_process) { |
655 UtilityProcessHost* host = new UtilityProcessHost( | 657 UtilityProcessHost* host = UtilityProcessHost::Create( |
656 this, BrowserThread::UI); | 658 this, BrowserThread::UI); |
657 host->set_use_linux_zygote(true); | 659 host->EnableZygote(); |
658 host->Send(new ChromeUtilityMsg_ParseUpdateManifest(xml_)); | 660 host->Send(new ChromeUtilityMsg_ParseUpdateManifest(xml_)); |
659 } else { | 661 } else { |
660 UpdateManifest manifest; | 662 UpdateManifest manifest; |
661 if (manifest.Parse(xml_)) { | 663 if (manifest.Parse(xml_)) { |
662 if (!BrowserThread::PostTask( | 664 if (!BrowserThread::PostTask( |
663 BrowserThread::UI, FROM_HERE, | 665 BrowserThread::UI, FROM_HERE, |
664 base::Bind( | 666 base::Bind( |
665 &SafeManifestParser::OnParseUpdateManifestSucceeded, this, | 667 &SafeManifestParser::OnParseUpdateManifestSucceeded, this, |
666 manifest.results()))) { | 668 manifest.results()))) { |
667 NOTREACHED(); | 669 NOTREACHED(); |
668 } | 670 } |
669 } else { | 671 } else { |
670 if (!BrowserThread::PostTask( | 672 if (!BrowserThread::PostTask( |
671 BrowserThread::UI, FROM_HERE, | 673 BrowserThread::UI, FROM_HERE, |
672 base::Bind( | 674 base::Bind( |
673 &SafeManifestParser::OnParseUpdateManifestFailed, this, | 675 &SafeManifestParser::OnParseUpdateManifestFailed, this, |
674 manifest.errors()))) { | 676 manifest.errors()))) { |
675 NOTREACHED(); | 677 NOTREACHED(); |
676 } | 678 } |
677 } | 679 } |
678 } | 680 } |
679 } | 681 } |
680 | 682 |
681 // UtilityProcessHost::Client | 683 // UtilityProcessHostClient |
682 virtual bool OnMessageReceived(const IPC::Message& message) { | 684 virtual bool OnMessageReceived(const IPC::Message& message) { |
683 bool handled = true; | 685 bool handled = true; |
684 IPC_BEGIN_MESSAGE_MAP(SafeManifestParser, message) | 686 IPC_BEGIN_MESSAGE_MAP(SafeManifestParser, message) |
685 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParseUpdateManifest_Succeeded, | 687 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParseUpdateManifest_Succeeded, |
686 OnParseUpdateManifestSucceeded) | 688 OnParseUpdateManifestSucceeded) |
687 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParseUpdateManifest_Failed, | 689 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParseUpdateManifest_Failed, |
688 OnParseUpdateManifestFailed) | 690 OnParseUpdateManifestFailed) |
689 IPC_MESSAGE_UNHANDLED(handled = false) | 691 IPC_MESSAGE_UNHANDLED(handled = false) |
690 IPC_END_MESSAGE_MAP() | 692 IPC_END_MESSAGE_MAP() |
691 return handled; | 693 return handled; |
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1297 std::set<std::string>::const_iterator i; | 1299 std::set<std::string>::const_iterator i; |
1298 for (i = ids.begin(); i != ids.end(); ++i) | 1300 for (i = ids.begin(); i != ids.end(); ++i) |
1299 in_progress_ids_.insert(*i); | 1301 in_progress_ids_.insert(*i); |
1300 } | 1302 } |
1301 | 1303 |
1302 void ExtensionUpdater::RemoveFromInProgress(const std::set<std::string>& ids) { | 1304 void ExtensionUpdater::RemoveFromInProgress(const std::set<std::string>& ids) { |
1303 std::set<std::string>::const_iterator i; | 1305 std::set<std::string>::const_iterator i; |
1304 for (i = ids.begin(); i != ids.end(); ++i) | 1306 for (i = ids.begin(); i != ids.end(); ++i) |
1305 in_progress_ids_.erase(*i); | 1307 in_progress_ids_.erase(*i); |
1306 } | 1308 } |
OLD | NEW |