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

Side by Side Diff: chrome/browser/component_updater/component_updater_service.cc

Issue 8122015: Component updater: send extra attributes in the request to (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' 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/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 22 matching lines...) Expand all
33 namespace { 33 namespace {
34 // Extends an omaha compatible update check url |query| string. Does 34 // Extends an omaha compatible update check url |query| string. Does
35 // not mutate the string if it would be longer than |limit| chars. 35 // not mutate the string if it would be longer than |limit| chars.
36 bool AddQueryString(std::string id, std::string version, 36 bool AddQueryString(std::string id, std::string version,
37 size_t limit, std::string* query) { 37 size_t limit, std::string* query) {
38 std::string additional = 38 std::string additional =
39 base::StringPrintf("id=%s&v=%s&uc", id.c_str(), version.c_str()); 39 base::StringPrintf("id=%s&v=%s&uc", id.c_str(), version.c_str());
40 additional = "x=" + net::EscapeQueryParamValue(additional, true); 40 additional = "x=" + net::EscapeQueryParamValue(additional, true);
41 if ((additional.size() + query->size() + 1) > limit) 41 if ((additional.size() + query->size() + 1) > limit)
42 return false; 42 return false;
43 query->append(1, query->empty()? '?' : '&'); 43 if (!query->empty())
44 query->append(1, '&');
44 query->append(additional); 45 query->append(additional);
45 return true; 46 return true;
46 } 47 }
47 48
49 // Create the final omaha compatible query. The |extra| is optional and can
50 // be null. It should contain top level (non-escaped) parameters.
51 std::string MakeFinalQuery(const std::string& host,
52 const std::string& query,
53 const char* extra) {
54 std::string request(host);
55 request.append(1, '?');
56 if (extra) {
57 request.append(extra);
58 request.append(1, '&');
59 }
60 request.append(query);
61 return request;
62 }
63
48 // Produces an extension-like friendly |id|. This might be removed in the 64 // Produces an extension-like friendly |id|. This might be removed in the
49 // future if we roll our on packing tools. 65 // future if we roll our on packing tools.
50 static std::string HexStringToID(const std::string& hexstr) { 66 static std::string HexStringToID(const std::string& hexstr) {
51 std::string id; 67 std::string id;
52 for (size_t i = 0; i < hexstr.size(); ++i) { 68 for (size_t i = 0; i < hexstr.size(); ++i) {
53 int val; 69 int val;
54 if (base::HexStringToInt(hexstr.begin() + i, hexstr.begin() + i + 1, &val)) 70 if (base::HexStringToInt(hexstr.begin() + i, hexstr.begin() + i + 1, &val))
55 id.append(1, val + 'a'); 71 id.append(1, val + 'a');
56 else 72 else
57 id.append(1, 'a'); 73 id.append(1, 'a');
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 break; 539 break;
524 } 540 }
525 541
526 if (query.empty()) { 542 if (query.empty()) {
527 // Next check after the long sleep. 543 // Next check after the long sleep.
528 ScheduleNextRun(false); 544 ScheduleNextRun(false);
529 return; 545 return;
530 } 546 }
531 547
532 // We got components to check. Start the url request. 548 // We got components to check. Start the url request.
533 GURL url(config_->UpdateUrl().spec() + query); 549 const std::string full_query = MakeFinalQuery(config_->UpdateUrl().spec(),
534 url_fetcher_.reset(URLFetcher::Create(0, url, URLFetcher::GET, 550 query,
551 config_->ExtraRequestParams());
552 url_fetcher_.reset(URLFetcher::Create(0, GURL(full_query), URLFetcher::GET,
535 MakeContextDelegate(this, new UpdateContext()))); 553 MakeContextDelegate(this, new UpdateContext())));
536 StartFetch(url_fetcher_.get(), config_->RequestContext(), false); 554 StartFetch(url_fetcher_.get(), config_->RequestContext(), false);
537 } 555 }
538 556
539 // Caled when we got a response from the update server. It consists of an xml 557 // Caled when we got a response from the update server. It consists of an xml
540 // document following the omaha update scheme. 558 // document following the omaha update scheme.
541 void CrxUpdateService::OnURLFetchComplete(const URLFetcher* source, 559 void CrxUpdateService::OnURLFetchComplete(const URLFetcher* source,
542 UpdateContext* context) { 560 UpdateContext* context) {
543 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 561 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
544 if (FetchSuccess(*source)) { 562 if (FetchSuccess(*source)) {
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 ScheduleNextRun(false); 743 ScheduleNextRun(false);
726 } 744 }
727 745
728 // The component update factory. Using the component updater as a singleton 746 // The component update factory. Using the component updater as a singleton
729 // is the job of the browser process. 747 // is the job of the browser process.
730 ComponentUpdateService* ComponentUpdateServiceFactory( 748 ComponentUpdateService* ComponentUpdateServiceFactory(
731 ComponentUpdateService::Configurator* config) { 749 ComponentUpdateService::Configurator* config) {
732 DCHECK(config); 750 DCHECK(config);
733 return new CrxUpdateService(config); 751 return new CrxUpdateService(config);
734 } 752 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698