Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(232)

Side by Side Diff: chrome/browser/extensions/extension_updater.cc

Issue 8375039: Create a content::UrlFetcher interface that lives in content/public/common and convert users to i... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: review comments Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 profile_ = NULL; 584 profile_ = NULL;
585 timer_.Stop(); 585 timer_.Stop();
586 will_check_soon_ = false; 586 will_check_soon_ = false;
587 manifest_fetcher_.reset(); 587 manifest_fetcher_.reset();
588 extension_fetcher_.reset(); 588 extension_fetcher_.reset();
589 STLDeleteElements(&manifests_pending_); 589 STLDeleteElements(&manifests_pending_);
590 manifests_pending_.clear(); 590 manifests_pending_.clear();
591 extensions_pending_.clear(); 591 extensions_pending_.clear();
592 } 592 }
593 593
594 void ExtensionUpdater::OnURLFetchComplete(const URLFetcher* source) { 594 void ExtensionUpdater::OnURLFetchComplete(const content::URLFetcher* source) {
595 // Stop() destroys all our URLFetchers, which means we shouldn't be 595 // Stop() destroys all our URLFetchers, which means we shouldn't be
596 // called after Stop() is called. 596 // called after Stop() is called.
597 DCHECK(alive_); 597 DCHECK(alive_);
598 598
599 if (source == manifest_fetcher_.get()) { 599 if (source == manifest_fetcher_.get()) {
600 std::string data; 600 std::string data;
601 source->GetResponseAsString(&data); 601 source->GetResponseAsString(&data);
602 OnManifestFetchComplete(source->url(), 602 OnManifestFetchComplete(source->GetUrl(),
603 source->status(), 603 source->GetStatus(),
604 source->response_code(), 604 source->GetResponseCode(),
605 data); 605 data);
606 } else if (source == extension_fetcher_.get()) { 606 } else if (source == extension_fetcher_.get()) {
607 OnCRXFetchComplete(source, 607 OnCRXFetchComplete(source,
608 source->url(), 608 source->GetUrl(),
609 source->status(), 609 source->GetStatus(),
610 source->response_code()); 610 source->GetResponseCode());
611 } else { 611 } else {
612 NOTREACHED(); 612 NOTREACHED();
613 } 613 }
614 NotifyIfFinished(); 614 NotifyIfFinished();
615 } 615 }
616 616
617 // Utility class to handle doing xml parsing in a sandboxed utility process. 617 // Utility class to handle doing xml parsing in a sandboxed utility process.
618 class SafeManifestParser : public UtilityProcessHost::Client { 618 class SafeManifestParser : public UtilityProcessHost::Client {
619 public: 619 public:
620 // Takes ownership of |fetch_data|. 620 // Takes ownership of |fetch_data|.
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 // Tell ExtensionService to update prefs. 819 // Tell ExtensionService to update prefs.
820 service_->UpdateExtensionBlacklist(blacklist); 820 service_->UpdateExtensionBlacklist(blacklist);
821 821
822 // Update the pref value for blacklist version 822 // Update the pref value for blacklist version
823 prefs_->SetString(kExtensionBlacklistUpdateVersion, 823 prefs_->SetString(kExtensionBlacklistUpdateVersion,
824 current_extension_fetch_.version); 824 current_extension_fetch_.version);
825 prefs_->ScheduleSavePersistentPrefs(); 825 prefs_->ScheduleSavePersistentPrefs();
826 } 826 }
827 827
828 void ExtensionUpdater::OnCRXFetchComplete( 828 void ExtensionUpdater::OnCRXFetchComplete(
829 const URLFetcher* source, 829 const content::URLFetcher* source,
830 const GURL& url, 830 const GURL& url,
831 const net::URLRequestStatus& status, 831 const net::URLRequestStatus& status,
832 int response_code) { 832 int response_code) {
833 833
834 base::PlatformFileError error_code = base::PLATFORM_FILE_OK; 834 base::PlatformFileError error_code = base::PLATFORM_FILE_OK;
835 if (source->FileErrorOccurred(&error_code)) { 835 if (source->FileErrorOccurred(&error_code)) {
836 LOG(ERROR) << "Failed to write update CRX with id " 836 LOG(ERROR) << "Failed to write update CRX with id "
837 << current_extension_fetch_.id << ". " 837 << current_extension_fetch_.id << ". "
838 << "Error code is "<< error_code; 838 << "Error code is "<< error_code;
839 839
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 1153
1154 std::deque<ManifestFetchData*>::const_iterator i; 1154 std::deque<ManifestFetchData*>::const_iterator i;
1155 for (i = manifests_pending_.begin(); i != manifests_pending_.end(); i++) { 1155 for (i = manifests_pending_.begin(); i != manifests_pending_.end(); i++) {
1156 if (fetch_data->full_url() == (*i)->full_url()) { 1156 if (fetch_data->full_url() == (*i)->full_url()) {
1157 // This url is already scheduled to be fetched. 1157 // This url is already scheduled to be fetched.
1158 return; 1158 return;
1159 } 1159 }
1160 } 1160 }
1161 1161
1162 if (manifest_fetcher_.get() != NULL) { 1162 if (manifest_fetcher_.get() != NULL) {
1163 if (manifest_fetcher_->url() != fetch_data->full_url()) { 1163 if (manifest_fetcher_->GetUrl() != fetch_data->full_url()) {
1164 manifests_pending_.push_back(scoped_fetch_data.release()); 1164 manifests_pending_.push_back(scoped_fetch_data.release());
1165 } 1165 }
1166 } else { 1166 } else {
1167 UMA_HISTOGRAM_COUNTS("Extensions.UpdateCheckUrlLength", 1167 UMA_HISTOGRAM_COUNTS("Extensions.UpdateCheckUrlLength",
1168 fetch_data->full_url().possibly_invalid_spec().length()); 1168 fetch_data->full_url().possibly_invalid_spec().length());
1169 1169
1170 current_manifest_fetch_.swap(scoped_fetch_data); 1170 current_manifest_fetch_.swap(scoped_fetch_data);
1171 manifest_fetcher_.reset( 1171 manifest_fetcher_.reset(
1172 URLFetcher::Create(kManifestFetcherId, fetch_data->full_url(), 1172 URLFetcher::Create(kManifestFetcherId, fetch_data->full_url(),
1173 URLFetcher::GET, this)); 1173 URLFetcher::GET, this));
1174 manifest_fetcher_->set_request_context( 1174 manifest_fetcher_->SetRequestContext(profile_->GetRequestContext());
1175 profile_->GetRequestContext()); 1175 manifest_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
1176 manifest_fetcher_->set_load_flags(net::LOAD_DO_NOT_SEND_COOKIES | 1176 net::LOAD_DO_NOT_SAVE_COOKIES |
1177 net::LOAD_DO_NOT_SAVE_COOKIES | 1177 net::LOAD_DISABLE_CACHE);
1178 net::LOAD_DISABLE_CACHE);
1179 manifest_fetcher_->Start(); 1178 manifest_fetcher_->Start();
1180 } 1179 }
1181 } 1180 }
1182 1181
1183 void ExtensionUpdater::FetchUpdatedExtension(const std::string& id, 1182 void ExtensionUpdater::FetchUpdatedExtension(const std::string& id,
1184 const GURL& url, 1183 const GURL& url,
1185 const std::string& hash, 1184 const std::string& hash,
1186 const std::string& version) { 1185 const std::string& version) {
1187 for (std::deque<ExtensionFetch>::const_iterator iter = 1186 for (std::deque<ExtensionFetch>::const_iterator iter =
1188 extensions_pending_.begin(); 1187 extensions_pending_.begin();
1189 iter != extensions_pending_.end(); ++iter) { 1188 iter != extensions_pending_.end(); ++iter) {
1190 if (iter->id == id || iter->url == url) { 1189 if (iter->id == id || iter->url == url) {
1191 return; // already scheduled 1190 return; // already scheduled
1192 } 1191 }
1193 } 1192 }
1194 1193
1195 if (extension_fetcher_.get() != NULL) { 1194 if (extension_fetcher_.get() != NULL) {
1196 if (extension_fetcher_->url() != url) { 1195 if (extension_fetcher_->GetUrl() != url) {
1197 extensions_pending_.push_back(ExtensionFetch(id, url, hash, version)); 1196 extensions_pending_.push_back(ExtensionFetch(id, url, hash, version));
1198 } 1197 }
1199 } else { 1198 } else {
1200 extension_fetcher_.reset( 1199 extension_fetcher_.reset(
1201 URLFetcher::Create(kExtensionFetcherId, url, URLFetcher::GET, this)); 1200 URLFetcher::Create(kExtensionFetcherId, url, URLFetcher::GET, this));
1202 extension_fetcher_->set_request_context( 1201 extension_fetcher_->SetRequestContext(
1203 profile_->GetRequestContext()); 1202 profile_->GetRequestContext());
1204 extension_fetcher_->set_load_flags(net::LOAD_DO_NOT_SEND_COOKIES | 1203 extension_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
1205 net::LOAD_DO_NOT_SAVE_COOKIES | 1204 net::LOAD_DO_NOT_SAVE_COOKIES |
1206 net::LOAD_DISABLE_CACHE); 1205 net::LOAD_DISABLE_CACHE);
1207 // Download CRX files to a temp file. The blacklist is small and will be 1206 // Download CRX files to a temp file. The blacklist is small and will be
1208 // processed in memory, so it is fetched into a string. 1207 // processed in memory, so it is fetched into a string.
1209 if (id != ExtensionUpdater::kBlacklistAppID) { 1208 if (id != ExtensionUpdater::kBlacklistAppID) {
1210 extension_fetcher_->SaveResponseToTemporaryFile( 1209 extension_fetcher_->SaveResponseToTemporaryFile(
1211 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); 1210 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE));
1212 } 1211 }
1213 1212
1214 extension_fetcher_->Start(); 1213 extension_fetcher_->Start();
1215 current_extension_fetch_ = ExtensionFetch(id, url, hash, version); 1214 current_extension_fetch_ = ExtensionFetch(id, url, hash, version);
1216 } 1215 }
(...skipping 27 matching lines...) Expand all
1244 std::set<std::string>::const_iterator i; 1243 std::set<std::string>::const_iterator i;
1245 for (i = ids.begin(); i != ids.end(); ++i) 1244 for (i = ids.begin(); i != ids.end(); ++i)
1246 in_progress_ids_.insert(*i); 1245 in_progress_ids_.insert(*i);
1247 } 1246 }
1248 1247
1249 void ExtensionUpdater::RemoveFromInProgress(const std::set<std::string>& ids) { 1248 void ExtensionUpdater::RemoveFromInProgress(const std::set<std::string>& ids) {
1250 std::set<std::string>::const_iterator i; 1249 std::set<std::string>::const_iterator i;
1251 for (i = ids.begin(); i != ids.end(); ++i) 1250 for (i = ids.begin(); i != ids.end(); ++i)
1252 in_progress_ids_.erase(*i); 1251 in_progress_ids_.erase(*i);
1253 } 1252 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_updater.h ('k') | chrome/browser/extensions/extension_updater_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698