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/component_updater/component_updater_service.h" | 5 #include "chrome/browser/component_updater/component_updater_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "base/timer.h" | 21 #include "base/timer.h" |
22 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
23 #include "chrome/browser/component_updater/component_unpacker.h" | 23 #include "chrome/browser/component_updater/component_unpacker.h" |
24 #include "chrome/common/chrome_notification_types.h" | 24 #include "chrome/common/chrome_notification_types.h" |
25 #include "chrome/common/chrome_utility_messages.h" | 25 #include "chrome/common/chrome_utility_messages.h" |
26 #include "chrome/common/chrome_version_info.h" | 26 #include "chrome/common/chrome_version_info.h" |
27 #include "chrome/common/extensions/extension.h" | 27 #include "chrome/common/extensions/extension.h" |
28 #include "content/public/browser/notification_service.h" | 28 #include "content/public/browser/notification_service.h" |
29 #include "content/public/browser/utility_process_host.h" | 29 #include "content/public/browser/utility_process_host.h" |
30 #include "content/public/browser/utility_process_host_client.h" | 30 #include "content/public/browser/utility_process_host_client.h" |
| 31 #include "content/public/common/url_fetcher.h" |
31 #include "content/public/common/url_fetcher_delegate.h" | 32 #include "content/public/common/url_fetcher_delegate.h" |
32 #include "content/public/common/url_fetcher.h" | |
33 #include "googleurl/src/gurl.h" | 33 #include "googleurl/src/gurl.h" |
34 #include "net/base/escape.h" | 34 #include "net/base/escape.h" |
35 #include "net/base/load_flags.h" | 35 #include "net/base/load_flags.h" |
36 | 36 |
37 using content::BrowserThread; | 37 using content::BrowserThread; |
38 using content::UtilityProcessHost; | 38 using content::UtilityProcessHost; |
39 using content::UtilityProcessHostClient; | 39 using content::UtilityProcessHostClient; |
40 | 40 |
41 // The component updater is designed to live until process shutdown, so | 41 // The component updater is designed to live until process shutdown, so |
42 // base::Bind() calls are not refcounted. | 42 // base::Bind() calls are not refcounted. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 | 110 |
111 // Helper template class that allows our main class to have separate | 111 // Helper template class that allows our main class to have separate |
112 // OnURLFetchComplete() callbacks for different types of url requests | 112 // OnURLFetchComplete() callbacks for different types of url requests |
113 // they are differentiated by the |Ctx| type. | 113 // they are differentiated by the |Ctx| type. |
114 template <typename Del, typename Ctx> | 114 template <typename Del, typename Ctx> |
115 class DelegateWithContext : public content::URLFetcherDelegate { | 115 class DelegateWithContext : public content::URLFetcherDelegate { |
116 public: | 116 public: |
117 DelegateWithContext(Del* delegate, Ctx* context) | 117 DelegateWithContext(Del* delegate, Ctx* context) |
118 : delegate_(delegate), context_(context) {} | 118 : delegate_(delegate), context_(context) {} |
119 | 119 |
120 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE { | 120 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE { |
121 delegate_->OnURLFetchComplete(source, context_); | 121 delegate_->OnURLFetchComplete(source, context_); |
122 delete this; | 122 delete this; |
123 } | 123 } |
124 | 124 |
125 private: | 125 private: |
126 ~DelegateWithContext() {} | 126 ~DelegateWithContext() {} |
127 | 127 |
128 Del* delegate_; | 128 Del* delegate_; |
129 Ctx* context_; | 129 Ctx* context_; |
130 }; | 130 }; |
(...skipping 14 matching lines...) Expand all Loading... |
145 // TODO(cpu): Define our retry and backoff policy. | 145 // TODO(cpu): Define our retry and backoff policy. |
146 fetcher->SetAutomaticallyRetryOn5xx(false); | 146 fetcher->SetAutomaticallyRetryOn5xx(false); |
147 if (save_to_file) { | 147 if (save_to_file) { |
148 fetcher->SaveResponseToTemporaryFile( | 148 fetcher->SaveResponseToTemporaryFile( |
149 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); | 149 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); |
150 } | 150 } |
151 fetcher->Start(); | 151 fetcher->Start(); |
152 } | 152 } |
153 | 153 |
154 // Returs true if the url request of |fetcher| was succesful. | 154 // Returs true if the url request of |fetcher| was succesful. |
155 bool FetchSuccess(const content::URLFetcher& fetcher) { | 155 bool FetchSuccess(const net::URLFetcher& fetcher) { |
156 return (fetcher.GetStatus().status() == net::URLRequestStatus::SUCCESS) && | 156 return (fetcher.GetStatus().status() == net::URLRequestStatus::SUCCESS) && |
157 (fetcher.GetResponseCode() == 200); | 157 (fetcher.GetResponseCode() == 200); |
158 } | 158 } |
159 | 159 |
160 // This is the one and only per-item state structure. Designed to be hosted | 160 // This is the one and only per-item state structure. Designed to be hosted |
161 // in a std::vector or a std::list. The two main members are |component| | 161 // in a std::vector or a std::list. The two main members are |component| |
162 // which is supplied by the the component updater client and |status| which | 162 // which is supplied by the the component updater client and |status| which |
163 // is modified as the item is processed by the update pipeline. The expected | 163 // is modified as the item is processed by the update pipeline. The expected |
164 // transition graph is: | 164 // transition graph is: |
165 // error error error | 165 // error error error |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 }; | 282 }; |
283 | 283 |
284 // Context for a crx download url request. See DelegateWithContext above. | 284 // Context for a crx download url request. See DelegateWithContext above. |
285 struct CRXContext { | 285 struct CRXContext { |
286 ComponentInstaller* installer; | 286 ComponentInstaller* installer; |
287 std::vector<uint8> pk_hash; | 287 std::vector<uint8> pk_hash; |
288 std::string id; | 288 std::string id; |
289 CRXContext() : installer(NULL) {} | 289 CRXContext() : installer(NULL) {} |
290 }; | 290 }; |
291 | 291 |
292 void OnURLFetchComplete(const content::URLFetcher* source, | 292 void OnURLFetchComplete(const net::URLFetcher* source, |
293 UpdateContext* context); | 293 UpdateContext* context); |
294 | 294 |
295 void OnURLFetchComplete(const content::URLFetcher* source, | 295 void OnURLFetchComplete(const net::URLFetcher* source, |
296 CRXContext* context); | 296 CRXContext* context); |
297 | 297 |
298 private: | 298 private: |
299 // See ManifestParserBridge. | 299 // See ManifestParserBridge. |
300 void OnParseUpdateManifestSucceeded( | 300 void OnParseUpdateManifestSucceeded( |
301 const UpdateManifest::Results& results); | 301 const UpdateManifest::Results& results); |
302 | 302 |
303 // See ManifestParserBridge. | 303 // See ManifestParserBridge. |
304 void OnParseUpdateManifestFailed( | 304 void OnParseUpdateManifestFailed( |
305 const std::string& error_message); | 305 const std::string& error_message); |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 query, | 567 query, |
568 config_->ExtraRequestParams()); | 568 config_->ExtraRequestParams()); |
569 url_fetcher_.reset(content::URLFetcher::Create( | 569 url_fetcher_.reset(content::URLFetcher::Create( |
570 0, GURL(full_query), content::URLFetcher::GET, | 570 0, GURL(full_query), content::URLFetcher::GET, |
571 MakeContextDelegate(this, new UpdateContext()))); | 571 MakeContextDelegate(this, new UpdateContext()))); |
572 StartFetch(url_fetcher_.get(), config_->RequestContext(), false); | 572 StartFetch(url_fetcher_.get(), config_->RequestContext(), false); |
573 } | 573 } |
574 | 574 |
575 // Caled when we got a response from the update server. It consists of an xml | 575 // Caled when we got a response from the update server. It consists of an xml |
576 // document following the omaha update scheme. | 576 // document following the omaha update scheme. |
577 void CrxUpdateService::OnURLFetchComplete(const content::URLFetcher* source, | 577 void CrxUpdateService::OnURLFetchComplete(const net::URLFetcher* source, |
578 UpdateContext* context) { | 578 UpdateContext* context) { |
579 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 579 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
580 if (FetchSuccess(*source)) { | 580 if (FetchSuccess(*source)) { |
581 std::string xml; | 581 std::string xml; |
582 source->GetResponseAsString(&xml); | 582 source->GetResponseAsString(&xml); |
583 url_fetcher_.reset(); | 583 url_fetcher_.reset(); |
584 ParseManifest(xml); | 584 ParseManifest(xml); |
585 } else { | 585 } else { |
586 url_fetcher_.reset(); | 586 url_fetcher_.reset(); |
587 CrxUpdateService::OnParseUpdateManifestFailed("network error"); | 587 CrxUpdateService::OnParseUpdateManifestFailed("network error"); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 size_t count = ChangeItemStatus(CrxUpdateItem::kChecking, | 672 size_t count = ChangeItemStatus(CrxUpdateItem::kChecking, |
673 CrxUpdateItem::kNoUpdate); | 673 CrxUpdateItem::kNoUpdate); |
674 config_->OnEvent(Configurator::kManifestError, static_cast<int>(count)); | 674 config_->OnEvent(Configurator::kManifestError, static_cast<int>(count)); |
675 DCHECK_GT(count, 0ul); | 675 DCHECK_GT(count, 0ul); |
676 ScheduleNextRun(false); | 676 ScheduleNextRun(false); |
677 } | 677 } |
678 | 678 |
679 // Called when the CRX package has been downloaded to a temporary location. | 679 // Called when the CRX package has been downloaded to a temporary location. |
680 // Here we fire the notifications and schedule the component-specific installer | 680 // Here we fire the notifications and schedule the component-specific installer |
681 // to be called in the file thread. | 681 // to be called in the file thread. |
682 void CrxUpdateService::OnURLFetchComplete(const content::URLFetcher* source, | 682 void CrxUpdateService::OnURLFetchComplete(const net::URLFetcher* source, |
683 CRXContext* context) { | 683 CRXContext* context) { |
684 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 684 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
685 base::PlatformFileError error_code; | 685 base::PlatformFileError error_code; |
686 | 686 |
687 if (source->FileErrorOccurred(&error_code) || !FetchSuccess(*source)) { | 687 if (source->FileErrorOccurred(&error_code) || !FetchSuccess(*source)) { |
688 size_t count = ChangeItemStatus(CrxUpdateItem::kDownloading, | 688 size_t count = ChangeItemStatus(CrxUpdateItem::kDownloading, |
689 CrxUpdateItem::kNoUpdate); | 689 CrxUpdateItem::kNoUpdate); |
690 DCHECK_EQ(count, 1ul); | 690 DCHECK_EQ(count, 1ul); |
691 config_->OnEvent(Configurator::kNetworkError, CrxIdtoUMAId(context->id)); | 691 config_->OnEvent(Configurator::kNetworkError, CrxIdtoUMAId(context->id)); |
692 url_fetcher_.reset(); | 692 url_fetcher_.reset(); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 ScheduleNextRun(false); | 768 ScheduleNextRun(false); |
769 } | 769 } |
770 | 770 |
771 // The component update factory. Using the component updater as a singleton | 771 // The component update factory. Using the component updater as a singleton |
772 // is the job of the browser process. | 772 // is the job of the browser process. |
773 ComponentUpdateService* ComponentUpdateServiceFactory( | 773 ComponentUpdateService* ComponentUpdateServiceFactory( |
774 ComponentUpdateService::Configurator* config) { | 774 ComponentUpdateService::Configurator* config) { |
775 DCHECK(config); | 775 DCHECK(config); |
776 return new CrxUpdateService(config); | 776 return new CrxUpdateService(config); |
777 } | 777 } |
OLD | NEW |