| 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 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 ExtensionUpdater::ExtensionUpdater(ExtensionServiceInterface* service, | 475 ExtensionUpdater::ExtensionUpdater(ExtensionServiceInterface* service, |
| 476 ExtensionPrefs* extension_prefs, | 476 ExtensionPrefs* extension_prefs, |
| 477 PrefService* prefs, | 477 PrefService* prefs, |
| 478 Profile* profile, | 478 Profile* profile, |
| 479 int frequency_seconds) | 479 int frequency_seconds) |
| 480 : alive_(false), | 480 : alive_(false), |
| 481 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 481 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 482 service_(service), frequency_seconds_(frequency_seconds), | 482 service_(service), frequency_seconds_(frequency_seconds), |
| 483 will_check_soon_(false), extension_prefs_(extension_prefs), | 483 will_check_soon_(false), extension_prefs_(extension_prefs), |
| 484 prefs_(prefs), profile_(profile), blacklist_checks_enabled_(true), | 484 prefs_(prefs), profile_(profile), blacklist_checks_enabled_(true), |
| 485 crx_install_is_running_(false) { | 485 crx_install_is_running_(false), |
| 486 use_utility_process_(true) { |
| 486 Init(); | 487 Init(); |
| 487 } | 488 } |
| 488 | 489 |
| 489 void ExtensionUpdater::Init() { | 490 void ExtensionUpdater::Init() { |
| 490 DCHECK_GE(frequency_seconds_, 5); | 491 DCHECK_GE(frequency_seconds_, 5); |
| 491 DCHECK_LE(frequency_seconds_, kMaxUpdateFrequencySeconds); | 492 DCHECK_LE(frequency_seconds_, kMaxUpdateFrequencySeconds); |
| 492 #ifdef NDEBUG | 493 #ifdef NDEBUG |
| 493 // In Release mode we enforce that update checks don't happen too often. | 494 // In Release mode we enforce that update checks don't happen too often. |
| 494 frequency_seconds_ = std::max(frequency_seconds_, kMinUpdateFrequencySeconds); | 495 frequency_seconds_ = std::max(frequency_seconds_, kMinUpdateFrequencySeconds); |
| 495 #endif | 496 #endif |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 NOTREACHED(); | 616 NOTREACHED(); |
| 616 } | 617 } |
| 617 NotifyIfFinished(); | 618 NotifyIfFinished(); |
| 618 } | 619 } |
| 619 | 620 |
| 620 // Utility class to handle doing xml parsing in a sandboxed utility process. | 621 // Utility class to handle doing xml parsing in a sandboxed utility process. |
| 621 class SafeManifestParser : public UtilityProcessHost::Client { | 622 class SafeManifestParser : public UtilityProcessHost::Client { |
| 622 public: | 623 public: |
| 623 // Takes ownership of |fetch_data|. | 624 // Takes ownership of |fetch_data|. |
| 624 SafeManifestParser(const std::string& xml, ManifestFetchData* fetch_data, | 625 SafeManifestParser(const std::string& xml, ManifestFetchData* fetch_data, |
| 625 base::WeakPtr<ExtensionUpdater> updater) | 626 base::WeakPtr<ExtensionUpdater> updater, |
| 626 : xml_(xml), updater_(updater) { | 627 bool use_utility_process) |
| 628 : xml_(xml), |
| 629 updater_(updater), |
| 630 use_utility_process_(use_utility_process) { |
| 627 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 631 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 628 fetch_data_.reset(fetch_data); | 632 fetch_data_.reset(fetch_data); |
| 629 } | 633 } |
| 630 | 634 |
| 631 // 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 |
| 632 // utility process. | 636 // utility process. |
| 633 void Start() { | 637 void Start() { |
| 634 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 638 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 635 if (!BrowserThread::PostTask( | 639 if (!BrowserThread::PostTask( |
| 636 BrowserThread::IO, FROM_HERE, | 640 BrowserThread::IO, FROM_HERE, |
| 637 base::Bind( | 641 base::Bind( |
| 638 &SafeManifestParser::ParseInSandbox, this, | 642 &SafeManifestParser::ParseInSandbox, this))) { |
| 639 g_browser_process->resource_dispatcher_host()))) { | |
| 640 NOTREACHED(); | 643 NOTREACHED(); |
| 641 } | 644 } |
| 642 } | 645 } |
| 643 | 646 |
| 644 // Creates the sandboxed utility process and tells it to start parsing. | 647 // Creates the sandboxed utility process and tells it to start parsing. |
| 645 void ParseInSandbox(ResourceDispatcherHost* rdh) { | 648 void ParseInSandbox() { |
| 646 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 649 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 647 | 650 |
| 648 // TODO(asargent) we shouldn't need to do this branch here - instead | 651 // TODO(asargent) we shouldn't need to do this branch here - instead |
| 649 // UtilityProcessHost should handle it for us. (http://crbug.com/19192) | 652 // UtilityProcessHost should handle it for us. (http://crbug.com/19192) |
| 650 bool use_utility_process = rdh && | 653 bool use_utility_process = use_utility_process_ && |
| 651 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess); | 654 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess); |
| 652 if (use_utility_process) { | 655 if (use_utility_process) { |
| 653 UtilityProcessHost* host = new UtilityProcessHost( | 656 UtilityProcessHost* host = new UtilityProcessHost( |
| 654 this, BrowserThread::UI); | 657 this, BrowserThread::UI); |
| 655 host->set_use_linux_zygote(true); | 658 host->set_use_linux_zygote(true); |
| 656 host->Send(new ChromeUtilityMsg_ParseUpdateManifest(xml_)); | 659 host->Send(new ChromeUtilityMsg_ParseUpdateManifest(xml_)); |
| 657 } else { | 660 } else { |
| 658 UpdateManifest manifest; | 661 UpdateManifest manifest; |
| 659 if (manifest.Parse(xml_)) { | 662 if (manifest.Parse(xml_)) { |
| 660 if (!BrowserThread::PostTask( | 663 if (!BrowserThread::PostTask( |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 ~SafeManifestParser() { | 717 ~SafeManifestParser() { |
| 715 // If we're using UtilityProcessHost, we may not be destroyed on | 718 // If we're using UtilityProcessHost, we may not be destroyed on |
| 716 // the UI or IO thread. | 719 // the UI or IO thread. |
| 717 } | 720 } |
| 718 | 721 |
| 719 const std::string xml_; | 722 const std::string xml_; |
| 720 | 723 |
| 721 // Should be accessed only on UI thread. | 724 // Should be accessed only on UI thread. |
| 722 scoped_ptr<ManifestFetchData> fetch_data_; | 725 scoped_ptr<ManifestFetchData> fetch_data_; |
| 723 base::WeakPtr<ExtensionUpdater> updater_; | 726 base::WeakPtr<ExtensionUpdater> updater_; |
| 727 bool use_utility_process_; |
| 724 }; | 728 }; |
| 725 | 729 |
| 726 | 730 |
| 727 void ExtensionUpdater::OnManifestFetchComplete( | 731 void ExtensionUpdater::OnManifestFetchComplete( |
| 728 const GURL& url, | 732 const GURL& url, |
| 729 const net::URLRequestStatus& status, | 733 const net::URLRequestStatus& status, |
| 730 int response_code, | 734 int response_code, |
| 731 const std::string& data) { | 735 const std::string& data) { |
| 732 // We want to try parsing the manifest, and if it indicates updates are | 736 // We want to try parsing the manifest, and if it indicates updates are |
| 733 // available, we want to fire off requests to fetch those updates. | 737 // available, we want to fire off requests to fetch those updates. |
| 734 if (status.status() == net::URLRequestStatus::SUCCESS && | 738 if (status.status() == net::URLRequestStatus::SUCCESS && |
| 735 (response_code == 200 || (url.SchemeIsFile() && data.length() > 0))) { | 739 (response_code == 200 || (url.SchemeIsFile() && data.length() > 0))) { |
| 736 VLOG(2) << "beginning manifest parse for " << url; | 740 VLOG(2) << "beginning manifest parse for " << url; |
| 737 scoped_refptr<SafeManifestParser> safe_parser( | 741 scoped_refptr<SafeManifestParser> safe_parser( |
| 738 new SafeManifestParser(data, current_manifest_fetch_.release(), | 742 new SafeManifestParser(data, current_manifest_fetch_.release(), |
| 739 weak_ptr_factory_.GetWeakPtr())); | 743 weak_ptr_factory_.GetWeakPtr(), |
| 744 use_utility_process_)); |
| 740 safe_parser->Start(); | 745 safe_parser->Start(); |
| 741 } else { | 746 } else { |
| 742 // TODO(asargent) Do exponential backoff here. (http://crbug.com/12546). | 747 // TODO(asargent) Do exponential backoff here. (http://crbug.com/12546). |
| 743 VLOG(1) << "Failed to fetch manifest '" << url.possibly_invalid_spec() | 748 VLOG(1) << "Failed to fetch manifest '" << url.possibly_invalid_spec() |
| 744 << "' response code:" << response_code; | 749 << "' response code:" << response_code; |
| 745 RemoveFromInProgress(current_manifest_fetch_->extension_ids()); | 750 RemoveFromInProgress(current_manifest_fetch_->extension_ids()); |
| 746 } | 751 } |
| 747 manifest_fetcher_.reset(); | 752 manifest_fetcher_.reset(); |
| 748 current_manifest_fetch_.reset(); | 753 current_manifest_fetch_.reset(); |
| 749 | 754 |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1287 std::set<std::string>::const_iterator i; | 1292 std::set<std::string>::const_iterator i; |
| 1288 for (i = ids.begin(); i != ids.end(); ++i) | 1293 for (i = ids.begin(); i != ids.end(); ++i) |
| 1289 in_progress_ids_.insert(*i); | 1294 in_progress_ids_.insert(*i); |
| 1290 } | 1295 } |
| 1291 | 1296 |
| 1292 void ExtensionUpdater::RemoveFromInProgress(const std::set<std::string>& ids) { | 1297 void ExtensionUpdater::RemoveFromInProgress(const std::set<std::string>& ids) { |
| 1293 std::set<std::string>::const_iterator i; | 1298 std::set<std::string>::const_iterator i; |
| 1294 for (i = ids.begin(); i != ids.end(); ++i) | 1299 for (i = ids.begin(); i != ids.end(); ++i) |
| 1295 in_progress_ids_.erase(*i); | 1300 in_progress_ids_.erase(*i); |
| 1296 } | 1301 } |
| OLD | NEW |