Commit 2cddef42 authored by sorin@chromium.org's avatar sorin@chromium.org

Changed the update protocol for component updater from v2 to v3.

BUG=314521

Review URL: https://codereview.chromium.org/74893002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@236727 0039d316-1c4b-4281-b951-d872f2087c98
parent af0ebbb9
......@@ -40,13 +40,10 @@ extern const char kSwitchDisablePings[] = "disable-pings";
// Sets the URL for updates.
const char kSwitchUrlSource[] = "url-source";
// The default url from which an update manifest can be fetched. Can be
// The default url for the v3 protocol service endpoint. Can be
// overridden with --component-updater=url-source=someurl.
const char kDefaultUrlSource[] =
"http://clients2.google.com/service/update2/crx";
// The url to send the pings to.
const char kPingUrl[] = "http://tools.google.com/service/update2";
"http://clients2.google.com/service/update2";
#if defined(OS_WIN)
// Disables differential updates.
......@@ -179,7 +176,7 @@ GURL ChromeConfigurator::UpdateUrl() {
}
GURL ChromeConfigurator::PingUrl() {
return pings_enabled_ ? GURL(kPingUrl) : GURL();
return pings_enabled_ ? UpdateUrl() : GURL();
}
const char* ChromeConfigurator::ExtraRequestParams() {
......
......@@ -5,18 +5,13 @@
#include "chrome/browser/component_updater/component_updater_ping_manager.h"
#include "base/guid.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/sys_info.h"
#include "base/win/windows_version.h"
#include "chrome/browser/component_updater/component_updater_utils.h"
#include "chrome/browser/component_updater/crx_update_item.h"
#include "chrome/common/chrome_version_info.h"
#include "chrome/common/omaha_query_params/omaha_query_params.h"
#include "net/base/load_flags.h"
#include "net/base/net_errors.h"
#include "net/url_request/url_fetcher.h"
#include "net/url_request/url_fetcher_delegate.h"
#include "net/url_request/url_request_status.h"
namespace {
......@@ -69,45 +64,26 @@ void PingSender::SendPing(
if (!ping_url.is_valid())
return;
url_fetcher_.reset(net::URLFetcher::Create(0,
ping_url,
net::URLFetcher::POST,
this));
url_fetcher_->SetUploadData("application/xml", BuildPing(item));
url_fetcher_->SetRequestContext(url_request_context_getter);
url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
net::LOAD_DO_NOT_SAVE_COOKIES |
net::LOAD_DISABLE_CACHE);
url_fetcher_->SetAutomaticallyRetryOn5xx(false);
url_fetcher_->Start();
url_fetcher_.reset(SendProtocolRequest(ping_url,
BuildPing(item),
this,
url_request_context_getter));
}
// Builds a ping message for the specified update item.
std::string PingSender::BuildPing(const CrxUpdateItem* item) {
const std::string prod_id(chrome::OmahaQueryParams::GetProdIdString(
chrome::OmahaQueryParams::CHROME));
const char request_format[] =
"<o:gupdate xmlns:o=\"http://www.google.com/update2/request\" "
"protocol=\"2.0\" version=\"%s-%s\" requestid=\"{%s}\" "
"updaterchannel=\"%s\"> "
"<o:os platform=\"%s\" version=\"%s\"/> "
"<o:app appid=\"%s\" version=\"%s\">"
const char app_element_format[] =
"<app appid=\"%s\" version=\"%s\" nextversion=\"%s\">"
"%s"
"</o:app></o:gupdate>";
const std::string request(
base::StringPrintf(request_format,
prod_id.c_str(),
chrome::VersionInfo().Version().c_str(),
base::GenerateGUID().c_str(),
chrome::OmahaQueryParams::GetChannelString(),
chrome::VersionInfo().OSType().c_str(),
base::SysInfo().OperatingSystemVersion().c_str(),
item->id.c_str(),
item->component.version.GetString().c_str(),
BuildPingEventElement(item).c_str()));
return request;
"</app>";
const std::string app_element(base::StringPrintf(
app_element_format,
item->id.c_str(), // "appid"
item->previous_version.GetString().c_str(), // "version"
item->next_version.GetString().c_str(), // "nextversion"
BuildPingEventElement(item).c_str()));
return BuildProtocolRequest(app_element);
}
// Returns a string representing one ping event xml element for an update item.
......@@ -117,13 +93,9 @@ std::string PingSender::BuildPingEventElement(const CrxUpdateItem* item) {
using base::StringAppendF;
std::string ping_event("<o:event eventtype=\"3\"");
std::string ping_event("<event eventtype=\"3\"");
const int event_result = item->status == CrxUpdateItem::kUpdated;
StringAppendF(&ping_event, " eventresult=\"%d\"", event_result);
StringAppendF(&ping_event, " previousversion=\"%s\"",
item->previous_version.GetString().c_str());
StringAppendF(&ping_event, " nextversion=\"%s\"",
item->next_version.GetString().c_str());
if (item->error_category)
StringAppendF(&ping_event, " errorcat=\"%d\"", item->error_category);
if (item->error_code)
......
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/component_updater/component_updater_utils.h"
#include "base/guid.h"
#include "base/strings/stringprintf.h"
#include "base/sys_info.h"
#include "base/win/windows_version.h"
#include "chrome/common/chrome_version_info.h"
#include "chrome/common/omaha_query_params/omaha_query_params.h"
#include "net/base/load_flags.h"
#include "net/url_request/url_fetcher.h"
#include "net/url_request/url_request_context_getter.h"
namespace component_updater {
std::string BuildProtocolRequest(const std::string& request_body) {
const char request_format[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<request protocol=\"3.0\" version=\"%s-%s\" prodversion=\"%s\" "
"requestid=\"{%s}\" updaterchannel=\"%s\" arch=\"%s\" nacl_arch=\"%s\">"
"<os platform=\"%s\" version=\"%s\" arch=\"%s\"/>"
"%s"
"</request>";
const std::string prod_id(chrome::OmahaQueryParams::GetProdIdString(
chrome::OmahaQueryParams::CHROME));
const std::string chrome_version(chrome::VersionInfo().Version().c_str());
const std::string request(base::StringPrintf(request_format,
// Chrome version and platform information.
prod_id.c_str(), chrome_version.c_str(), // "version"
chrome_version.c_str(), // "prodversion"
base::GenerateGUID().c_str(), // "requestid"
chrome::OmahaQueryParams::GetChannelString(), // "updaterchannel"
chrome::OmahaQueryParams::getArch(), // "arch"
chrome::OmahaQueryParams::getNaclArch(), // "nacl_arch"
// OS version and platform information.
chrome::VersionInfo().OSType().c_str(), // "platform"
base::SysInfo().OperatingSystemVersion().c_str(), // "version"
base::SysInfo().OperatingSystemArchitecture().c_str(), // "arch"
request_body.c_str())); // The actual payload of the request.
return request;
}
net::URLFetcher* SendProtocolRequest(
const GURL& url,
const std::string& protocol_request,
net::URLFetcherDelegate* url_fetcher_delegate,
net::URLRequestContextGetter* url_request_context_getter) {
net::URLFetcher* url_fetcher(
net::URLFetcher::Create(0,
url,
net::URLFetcher::POST,
url_fetcher_delegate));
url_fetcher->SetUploadData("application/xml", protocol_request);
url_fetcher->SetRequestContext(url_request_context_getter);
url_fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
net::LOAD_DO_NOT_SAVE_COOKIES |
net::LOAD_DISABLE_CACHE);
url_fetcher->SetAutomaticallyRetryOn5xx(false);
url_fetcher->Start();
return url_fetcher;
}
} // namespace component_updater
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_UTILS_H_
#define CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_UTILS_H_
#include <string>
class GURL;
namespace net {
class URLFetcher;
class URLFetcherDelegate;
class URLRequestContextGetter;
}
namespace component_updater {
// An update protocol request starts with a common preamble which includes
// version and platform information for Chrome and the operating system,
// followed by a request body, which is the actual payload of the request.
// For example:
//
// <?xml version="1.0" encoding="UTF-8"?>
// <request protocol="3.0" version="chrome-32.0.1.0" prodversion="32.0.1.0"
// requestid="{7383396D-B4DD-46E1-9104-AAC6B918E792}"
// updaterchannel="canary" arch="x86" nacl_arch="x86-64">
// <os platform="win" version="6.1" arch="x86"/>
// ... REQUEST BODY ...
// </request>
// Builds a protocol request string by creating the outer envelope for
// the request and including the request body specified as a parameter.
std::string BuildProtocolRequest(const std::string& request_body);
// Sends a protocol request to the the service endpoint specified by |url|.
// The body of the request is provided by |protocol_request| and it is
// expected to contain XML data. The caller owns the returned object.
net::URLFetcher* SendProtocolRequest(
const GURL& url,
const std::string& protocol_request,
net::URLFetcherDelegate* url_fetcher_delegate,
net::URLRequestContextGetter* url_request_context_getter);
} // namespace component_updater
#endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_UTILS_H_
......@@ -19,6 +19,7 @@
#include "chrome/browser/component_updater/test/component_patcher_mock.h"
#include "chrome/browser/component_updater/test/url_request_post_interceptor.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "content/test/net/url_request_prepackaged_interceptor.h"
#include "net/url_request/url_request_test_util.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -27,7 +28,10 @@ class TestInstaller;
namespace component_updater {
// Intercepts HTTP POST requests sent to |localhost2|.
// Intercepts HTTP GET requests sent to "localhost".
typedef content::URLLocalHostRequestPrepackagedInterceptor GetInterceptor;
// Intercepts HTTP POST requests sent to "localhost2".
class InterceptorFactory : public URLRequestPostInterceptorFactory {
public:
InterceptorFactory();
......@@ -148,7 +152,9 @@ class ComponentUpdaterTest : public testing::Test {
void RunThreadsUntilIdle();
scoped_ptr<component_updater::InterceptorFactory> interceptor_factory_;
URLRequestPostInterceptor* post_interceptor_; // Owned by the factory.
scoped_ptr<GetInterceptor> get_interceptor_;
private:
TestConfigurator* test_config_;
base::FilePath test_data_dir_;
......
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/memory/scoped_vector.h"
#include "chrome/browser/component_updater/update_manifest.h"
#include "libxml/globals.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace component_updater {
const char* kValidXml =
"<?xml version='1.0' encoding='UTF-8'?>"
"<response protocol='3.0'>"
" <app appid='12345'>"
" <updatecheck status='ok'>"
" <urls>"
" <url codebase='http://example.com/'/>"
" <url codebasediff='http://diff.example.com/'/>"
" </urls>"
" <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>"
" <packages>"
" <package name='extension_1_2_3_4.crx'/>"
" </packages>"
" </manifest>"
" </updatecheck>"
" </app>"
"</response>";
const char* valid_xml_with_hash =
"<?xml version='1.0' encoding='UTF-8'?>"
"<response protocol='3.0'>"
" <app appid='12345'>"
" <updatecheck status='ok'>"
" <urls>"
" <url codebase='http://example.com/'/>"
" </urls>"
" <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>"
" <packages>"
" <package name='extension_1_2_3_4.crx' hash_sha256='1234'/>"
" </packages>"
" </manifest>"
" </updatecheck>"
" </app>"
"</response>";
const char* valid_xml_with_invalid_sizes =
"<?xml version='1.0' encoding='UTF-8'?>"
"<response protocol='3.0'>"
" <app appid='12345'>"
" <updatecheck status='ok'>"
" <urls>"
" <url codebase='http://example.com/'/>"
" </urls>"
" <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>"
" <packages>"
" <package name='1' size='1234'/>"
" <package name='2' size='-1234'/>"
" <package name='3' />"
" <package name='4' size='-a'/>"
" <package name='5' size='-123467890123456789'/>"
" <package name='6' size='123467890123456789'/>"
" </packages>"
" </manifest>"
" </updatecheck>"
" </app>"
"</response>";
const char* kMissingAppId =
"<?xml version='1.0'?>"
"<response protocol='3.0'>"
" <app>"
" <updatecheck codebase='http://example.com/extension_1.2.3.4.crx'"
" version='1.2.3.4' />"
" </app>"
"</response>";
const char* kInvalidCodebase =
"<?xml version='1.0'?>"
"<response protocol='3.0'>"
" <app appid='12345' status='ok'>"
" <updatecheck codebase='example.com/extension_1.2.3.4.crx'"
" version='1.2.3.4' />"
" </app>"
"</response>";
const char* kMissingVersion =
"<?xml version='1.0'?>"
"<response protocol='3.0'>"
" <app appid='12345' status='ok'>"
" <updatecheck codebase='http://example.com/extension_1.2.3.4.crx' />"
" </app>"
"</response>";
const char* kInvalidVersion =
"<?xml version='1.0'?>"
"<response protocol='3.0'>"
" <app appid='12345' status='ok'>"
" <updatecheck codebase='http://example.com/extension_1.2.3.4.crx' "
" version='1.2.3.a'/>"
" </app>"
"</response>";
// The v3 version of the protocol is not using namespaces. However, the parser
// must be able to parse responses that include namespaces.
const char* kUsesNamespacePrefix =
"<?xml version='1.0' encoding='UTF-8'?>"
"<g:response xmlns='http://www.google.com/update2/response' protocol='3.0'>"
" <g:app appid='12345'>"
" <g:updatecheck status='ok'>"
" <g:urls>"
" <g:url codebase='http://example.com/'/>"
" </g:urls>"
" <g:manifest version='1.2.3.4' prodversionmin='2.0.143.0'>"
" <g:packages>"
" <g:package name='extension_1_2_3_4.crx'/>"
" </g:packages>"
" </g:manifest>"
" </g:updatecheck>"
" </g:app>"
"</g:response>";
// Includes unrelated <app> tags from other xml namespaces - this should
// not cause problems.
const char* kSimilarTagnames =
"<?xml version='1.0' encoding='UTF-8'?>"
"<response xmlns:a='http://a' protocol='3.0'>"
" <a:app appid='12345'>"
" <updatecheck status='ok'>"
" <urls>"
" <url codebase='http://example.com/'/>"
" </urls>"
" <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>"
" <packages>"
" <package name='extension_1_2_3_4.crx'/>"
" </packages>"
" </manifest>"
" </updatecheck>"
" </a:app>"
" <b:app appid='xyz' xmlns:b='http://b'>"
" <updatecheck status='noupdate'/>"
" </b:app>"
"</response>";
// Includes a <daystart> tag.
const char* kWithDaystart =
"<?xml version='1.0' encoding='UTF-8'?>"
"<response protocol='3.0'>"
" <daystart elapsed_seconds='456' />"
" <app appid='12345'>"
" <updatecheck status='ok'>"
" <urls>"
" <url codebase='http://example.com/'/>"
" </urls>"
" <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>"
" <packages>"
" <package name='extension_1_2_3_4.crx'/>"
" </packages>"
" </manifest>"
" </updatecheck>"
" </app>"
"</response>";
// Indicates no updates available - this should not be a parse error.
const char* kNoUpdate =
"<?xml version='1.0' encoding='UTF-8'?>"
"<response protocol='3.0'>"
" <app appid='12345'>"
" <updatecheck status='noupdate' />"
" </app>"
"</response>";
// Includes two <app> tags, one with an error.
const char* kTwoAppsOneError =
"<?xml version='1.0' encoding='UTF-8'?>"
"<response protocol='3.0'>"
" <app appid='aaaaaaaa' status='error-unknownApplication'>"
" <updatecheck status='error-unknownapplication'/>"
" </app>"
" <app appid='bbbbbbbb'>"
" <updatecheck status='ok'>"
" <urls>"
" <url codebase='http://example.com/'/>"
" </urls>"
" <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>"
" <packages>"
" <package name='extension_1_2_3_4.crx'/>"
" </packages>"
" </manifest>"
" </updatecheck>"
" </app>"
"</response>";
TEST(ComponentUpdaterManifestTest, TestUpdateManifest) {
UpdateManifest parser;
// Test parsing of a number of invalid xml cases
EXPECT_FALSE(parser.Parse(std::string()));
EXPECT_FALSE(parser.errors().empty());
EXPECT_TRUE(parser.Parse(kMissingAppId));
EXPECT_TRUE(parser.results().list.empty());
EXPECT_FALSE(parser.errors().empty());
EXPECT_TRUE(parser.Parse(kInvalidCodebase));
EXPECT_TRUE(parser.results().list.empty());
EXPECT_FALSE(parser.errors().empty());
EXPECT_TRUE(parser.Parse(kMissingVersion));
EXPECT_TRUE(parser.results().list.empty());
EXPECT_FALSE(parser.errors().empty());
EXPECT_TRUE(parser.Parse(kInvalidVersion));
EXPECT_TRUE(parser.results().list.empty());
EXPECT_FALSE(parser.errors().empty());
// Parse some valid XML, and check that all params came out as expected
EXPECT_TRUE(parser.Parse(kValidXml));
EXPECT_TRUE(parser.errors().empty());
EXPECT_EQ(1u, parser.results().list.size());
const UpdateManifest::Result* firstResult = &parser.results().list[0];
EXPECT_EQ(1u, firstResult->crx_urls.size());
EXPECT_EQ(GURL("http://example.com/"), firstResult->crx_urls[0]);
EXPECT_EQ(GURL("http://diff.example.com/"), firstResult->crx_diffurls[0]);
EXPECT_EQ("1.2.3.4", firstResult->manifest.version);
EXPECT_EQ("2.0.143.0", firstResult->manifest.browser_min_version);
EXPECT_EQ(1u, firstResult->manifest.packages.size());
EXPECT_EQ("extension_1_2_3_4.crx", firstResult->manifest.packages[0].name);
// Parse some xml that uses namespace prefixes.
EXPECT_TRUE(parser.Parse(kUsesNamespacePrefix));
EXPECT_TRUE(parser.errors().empty());
EXPECT_TRUE(parser.Parse(kSimilarTagnames));
EXPECT_TRUE(parser.errors().empty());
xmlCleanupGlobals();
// Parse xml with hash value
EXPECT_TRUE(parser.Parse(valid_xml_with_hash));
EXPECT_TRUE(parser.errors().empty());
EXPECT_FALSE(parser.results().list.empty());
firstResult = &parser.results().list[0];
EXPECT_FALSE(firstResult->manifest.packages.empty());
EXPECT_EQ("1234", firstResult->manifest.packages[0].hash_sha256);
// Parse xml with package size value
EXPECT_TRUE(parser.Parse(valid_xml_with_invalid_sizes));
EXPECT_TRUE(parser.errors().empty());
EXPECT_FALSE(parser.results().list.empty());
firstResult = &parser.results().list[0];
EXPECT_FALSE(firstResult->manifest.packages.empty());
EXPECT_EQ(1234, firstResult->manifest.packages[0].size);
EXPECT_EQ(-1234, firstResult->manifest.packages[1].size);
EXPECT_EQ(0, firstResult->manifest.packages[2].size);
EXPECT_EQ(0, firstResult->manifest.packages[3].size);
EXPECT_EQ(0, firstResult->manifest.packages[4].size);
EXPECT_EQ(0, firstResult->manifest.packages[5].size);
// Parse xml with a <daystart> element.
EXPECT_TRUE(parser.Parse(kWithDaystart));
EXPECT_TRUE(parser.errors().empty());
EXPECT_FALSE(parser.results().list.empty());
EXPECT_EQ(parser.results().daystart_elapsed_seconds, 456);
// Parse a no-update response.
EXPECT_TRUE(parser.Parse(kNoUpdate));
EXPECT_TRUE(parser.errors().empty());
EXPECT_FALSE(parser.results().list.empty());
firstResult = &parser.results().list[0];
EXPECT_EQ(firstResult->extension_id, "12345");
EXPECT_EQ(firstResult->manifest.version, "");
// Parse xml with one error and one success <app> tag.
EXPECT_TRUE(parser.Parse(kTwoAppsOneError));
EXPECT_FALSE(parser.errors().empty());
EXPECT_EQ(1u, parser.results().list.size());
firstResult = &parser.results().list[0];
EXPECT_EQ(firstResult->extension_id, "bbbbbbbb");
}
} // namespace component_updater
......@@ -18,6 +18,7 @@ using content::BrowserThread;
namespace component_updater {
// Returns a canned response.
class URLRequestMockJob : public net::URLRequestSimpleJob {
public:
URLRequestMockJob(net::URLRequest* request,
......@@ -27,6 +28,10 @@ class URLRequestMockJob : public net::URLRequestSimpleJob {
response_(response) {}
protected:
virtual int GetResponseCode() const OVERRIDE {
return 200;
}
virtual int GetData(std::string* mime_type,
std::string* charset,
std::string* data,
......@@ -45,9 +50,14 @@ class URLRequestMockJob : public net::URLRequestSimpleJob {
};
URLRequestPostInterceptor::URLRequestPostInterceptor(const GURL& url)
: url_(url), hit_count_(0), miss_count_(0) {}
: url_(url), hit_count_(0) {}
URLRequestPostInterceptor::~URLRequestPostInterceptor() {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
ClearExpectations();
}
void URLRequestPostInterceptor::ClearExpectations() {
while (!expectations_.empty()) {
Expectation expectation(expectations_.front());
delete expectation.first;
......@@ -67,10 +77,9 @@ bool URLRequestPostInterceptor::ExpectRequest(
bool URLRequestPostInterceptor::ExpectRequest(
class RequestMatcher* request_matcher,
const std::string& filepath) {
const base::FilePath& filepath) {
std::string response;
const base::FilePath path(base::FilePath().AppendASCII(filepath));
if (filepath.empty() || !base::ReadFileToString(path, &response))
if (filepath.empty() || !base::ReadFileToString(filepath, &response))
return false;
expectations_.push(std::make_pair(request_matcher, response));
return true;
......@@ -81,9 +90,9 @@ int URLRequestPostInterceptor::GetHitCount() const {
return hit_count_;
}
int URLRequestPostInterceptor::GetMissCount() const {
int URLRequestPostInterceptor::GetCount() const {
base::AutoLock auto_lock(interceptor_lock_);
return requests_.size() - hit_count_;
return static_cast<int>(requests_.size());
}
std::vector<std::string>
......@@ -106,6 +115,13 @@ std::string URLRequestPostInterceptor::GetRequestsAsString() const {
return s;
}
void URLRequestPostInterceptor::Reset() {
base::AutoLock auto_lock(interceptor_lock_);
hit_count_ = 0;
requests_.clear();
ClearExpectations();
}
class URLRequestPostInterceptor::Delegate
: public net::URLRequestJobFactory::ProtocolHandler {
......@@ -180,13 +196,12 @@ class URLRequestPostInterceptor::Delegate
const URLRequestPostInterceptor::Expectation& expectation(
interceptor->expectations_.front());
if (expectation.first->Match(request_body)) {
const std::string response(expectation.second);
delete expectation.first;
interceptor->expectations_.pop();
++interceptor->hit_count_;
return new URLRequestMockJob(request,
network_delegate,
expectation.second);
return new URLRequestMockJob(request, network_delegate, response);
}
}
......@@ -222,11 +237,11 @@ URLRequestPostInterceptorFactory::~URLRequestPostInterceptorFactory() {
}
URLRequestPostInterceptor* URLRequestPostInterceptorFactory::CreateInterceptor(
const std::string& file_path) {
const base::FilePath& filepath) {
const GURL base_url(base::StringPrintf("%s://%s",
scheme_.c_str(),
hostname_.c_str()));
GURL absolute_url(base_url.Resolve(file_path));
GURL absolute_url(base_url.Resolve(filepath.MaybeAsASCII()));
URLRequestPostInterceptor* interceptor(
new URLRequestPostInterceptor(absolute_url));
bool res = BrowserThread::PostTask(
......
......@@ -11,10 +11,13 @@
#include <utility>
#include <vector>
#include "base/basictypes.h"
#include "base/path_service.h"
#include "base/synchronization/lock.h"
#include "url/gurl.h"
namespace base {
class FilePath;
}
namespace net {
class URLRequest;
}
......@@ -45,15 +48,14 @@ class URLRequestPostInterceptor {
// |request_matcher| object. Returns |true| if the expectation was set.
bool ExpectRequest(class RequestMatcher* request_matcher);
bool ExpectRequest(class RequestMatcher* request_matcher,
const std::string& filepath);
const base::FilePath& filepath);
// Returns how many requests have been intercepted and matched by
// an expectation. One expectation can only be matched by one request.
int GetHitCount() const;
// Returns how many requests have been intercepted but not matched by
// any expectation.
int GetMissCount() const;
// Returns how many requests in total have been captured by the interceptor.
int GetCount() const;
// Returns all requests that have been intercepted, matched or not.
std::vector<std::string> GetRequests() const;
......@@ -61,6 +63,9 @@ class URLRequestPostInterceptor {
// Returns all requests as a string for debugging purposes.
std::string GetRequestsAsString() const;
// Resets the state of the interceptor so that new expectations can be set.
void Reset();
class Delegate;
private:
......@@ -70,11 +75,11 @@ class URLRequestPostInterceptor {
explicit URLRequestPostInterceptor(const GURL& url);
~URLRequestPostInterceptor();
void ClearExpectations();
const GURL url_;
mutable base::Lock interceptor_lock_;
mutable int hit_count_;
mutable int miss_count_;
mutable std::vector<std::string> requests_;
mutable std::queue<Expectation> expectations_;
......@@ -90,7 +95,7 @@ class URLRequestPostInterceptorFactory {
// Creates an interceptor object for the specified url path. Returns NULL
// in case of errors or a valid interceptor object otherwise. The caller
// does not own the returned object.
URLRequestPostInterceptor* CreateInterceptor(const std::string& file_path);
URLRequestPostInterceptor* CreateInterceptor(const base::FilePath& filepath);
private:
const std::string scheme_;
......
This diff is collapsed.
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_COMPONENT_UPDATER_UPDATE_MANIFEST_H_
#define CHROME_BROWSER_COMPONENT_UPDATER_UPDATE_MANIFEST_H_
#include <string>
#include <vector>
#include "base/basictypes.h"
#include "url/gurl.h"
namespace component_updater {
// Parses responses for the update protocol version 3.
// (http://code.google.com/p/omaha/wiki/ServerProtocol)
//
// An update manifest looks like this:
//
// <?xml version="1.0" encoding="UTF-8"?>
// <response protocol="3.0" server="prod">
// <daystart elapsed_seconds="56508"/>
// <app appid="{430FD4D0-B729-4F61-AA34-91526481799D}" status="ok">
// <updatecheck status="noupdate"/>
// <ping status="ok"/>
// </app>
// <app appid="{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}" status="ok">
// <updatecheck status="ok">
// <urls>
// <url codebase="http://host/edgedl/chrome/install/782.112/"
// <url codebasediff="http://fallback/chrome/diff/782.112/"/>
// </urls>
// <manifest version="13.0.782.112" prodversionmin="2.0.143.0">
// <packages>
// <package name="component.crx"
// namediff="diff_1.2.3.4.crx"
// fp="1.123"
// hash_sha256="9830b4245c4..." size="23963192"
// hashdiff_sha256="cfb6caf3d0..." sizediff="101"/>
// </packages>
// </manifest>
// </updatecheck>
// <ping status="ok"/>
// </app>
// </response>
//
// The <daystart> tag contains a "elapsed_seconds" attribute which refers to
// the server's notion of how many seconds it has been since midnight.
//
// The "appid" attribute of the <app> tag refers to the unique id of the
// extension. The "codebase" attribute of the <updatecheck> tag is the url to
// fetch the updated crx file, and the "prodversionmin" attribute refers to
// the minimum version of the chrome browser that the update applies to.
//
// The diff data members correspond to the differential update package, if
// a differential update is specified in the response.
class UpdateManifest {
public:
// The result of parsing one <app> tag in an xml update check manifest.
struct Result {
struct Manifest {
struct Package {
Package();
~Package();
std::string fingerprint;
// Attributes for the full update.
std::string name;
std::string hash_sha256;
int size;
// Attributes for the differential update.
std::string namediff;
std::string hashdiff_sha256;
int sizediff;
};
Manifest();
~Manifest();
std::string version;
std::string browser_min_version;
std::vector<Package> packages;
};
Result();
~Result();
std::string extension_id;
// The list of fallback urls, for full and diff updates respectively.
std::vector<GURL> crx_urls;
std::vector<GURL> crx_diffurls;
Manifest manifest;
};
static const int kNoDaystart = -1;
struct Results {
Results();
~Results();
// This will be >= 0, or kNoDaystart if the <daystart> tag was not present.
int daystart_elapsed_seconds;
std::vector<Result> list;
};
UpdateManifest();
~UpdateManifest();
// Parses an update manifest xml string into Result data. Returns a bool
// indicating success or failure. On success, the results are available by
// calling results(). The details for any failures are available by calling
// errors().
bool Parse(const std::string& manifest_xml);
const Results& results() const { return results_; }
const std::string& errors() const { return errors_; }
private:
Results results_;
std::string errors_;
// Adds parse error details to |errors_| string.
void ParseError(const char* details, ...);
DISALLOW_COPY_AND_ASSIGN(UpdateManifest);
};
} // namespace component_updater
#endif // CHROME_BROWSER_COMPONENT_UPDATER_UPDATE_MANIFEST_H_
......@@ -434,6 +434,8 @@
'browser/component_updater/component_updater_ping_manager.h',
'browser/component_updater/component_updater_service.cc',
'browser/component_updater/component_updater_service.h',
'browser/component_updater/component_updater_utils.cc',
'browser/component_updater/component_updater_utils.h',
'browser/component_updater/crx_update_item.h',
'browser/component_updater/default_component_installer.cc',
'browser/component_updater/default_component_installer.h',
......@@ -449,6 +451,8 @@
'browser/component_updater/recovery_component_installer.h',
'browser/component_updater/swiftshader_component_installer.cc',
'browser/component_updater/swiftshader_component_installer.h',
'browser/component_updater/update_manifest.cc',
'browser/component_updater/update_manifest.h',
'browser/component_updater/widevine_cdm_component_installer.cc',
'browser/component_updater/widevine_cdm_component_installer.h',
'browser/content_settings/content_settings_default_provider.cc',
......
......@@ -754,6 +754,7 @@
'browser/component_updater/test/component_patcher_unittest.cc',
'browser/component_updater/test/component_updater_service_unittest.cc',
'browser/component_updater/test/test_installer.cc',
'browser/component_updater/test/update_manifest_unittest.cc',
'browser/component_updater/test/url_request_post_interceptor.cc',
'browser/content_settings/content_settings_default_provider_unittest.cc',
'browser/content_settings/content_settings_mock_observer.cc',
......
<?xml version='1.0' encoding='UTF-8'?>
<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>
<response protocol='3.0'>
<app appid='ihfokbkgjpifnbbojhneepfflplebdkc'>
<updatecheck codebase='http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx' version='1.0' prodversionmin='11.0.1.0' fp='1'/>
<updatecheck status='ok'>
<urls>
<url codebase='http://localhost/download/'/>
</urls>
<manifest version='1.0' prodversionmin='11.0.1.0'>
<packages>
<package name='ihfokbkgjpifnbbojhneepfflplebdkc_1.crx' fp='1'/>
</packages>
</manifest>
</updatecheck>
</app>
</gupdate>
</response>
<?xml version='1.0' encoding='UTF-8'?>
<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>
<response protocol='3.0'>
<app appid='ihfokbkgjpifnbbojhneepfflplebdkc'>
<updatecheck codebase='http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_2.crx' version='2.0' prodversionmin='11.0.1.0' fp='f22' codebasediff='http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx'/>
<updatecheck status='ok'>
<urls>
<url codebase='http://localhost/download/'/>
<url codebasediff='http://localhost/download/'/>
</urls>
<manifest version='2.0' prodversionmin='11.0.1.0'>
<packages>
<package name='ihfokbkgjpifnbbojhneepfflplebdkc_2.crx' namediff='ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx' fp='22'/>
</packages>
</manifest>
</updatecheck>
</app>
</gupdate>
</response>
\ No newline at end of file
<?xml version='1.0' encoding='UTF-8'?>
<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>
<response protocol='3.0'>
<app appid='ihfokbkgjpifnbbojhneepfflplebdkc'>
<updatecheck status='noupdate'/>
</app>
</gupdate>
</response>
<?xml version='1.0' encoding='UTF-8'?>
<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>
<response protocol='3.0'>
<app appid='jebgalgnebhfojomionfpkfelancnnkf'>
<updatecheck codebase='http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx' version='1.0' prodversionmin='11.0.1.0' />
<updatecheck status='ok'>
<urls>
<url codebase='http://localhost/download/'/>
</urls>
<manifest version='1.0' prodversionmin='11.0.1.0'>
<packages>
<package name='jebgalgnebhfojomionfpkfelancnnkf.crx'/>
</packages>
</manifest>
</updatecheck>
</app>
</gupdate>
</response>
<?xml version='1.0' encoding='UTF-8'?>
<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>
<response protocol='3.0'>
<app appid='jebgalgnebhfojomionfpkfelancnnkf'>
<updatecheck codebase='http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx' version='2.0' prodversionmin='55.0.1.0' />
<updatecheck status='ok'>
<urls>
<url codebase='http://localhost/download/'/>
</urls>
<manifest version='2.0' prodversionmin='55.0.1.0'>
<packages>
<package name='jebgalgnebhfojomionfpkfelancnnkf.crx'/>
</packages>
</manifest>
</updatecheck>
</app>
</gupdate>
</response>
\ No newline at end of file
<?xml version='1.0' encoding='UTF-8'?>
<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>
<response protocol='3.0'>
<app appid='abagagagagagagagagagagagagagagag'>
<updatecheck status="noupdate"/>
<updatecheck status='noupdate'/>
</app>
</gupdate>
</response>
<?xml version='1.0' encoding='UTF-8'?>
<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>
<response protocol='3.0'>
<app appid='jebgalgnebhfojomionfpkfelancnnkf'>
<updatecheck status='noupdate' />
<updatecheck status='noupdate'/>j
</app>
</gupdate>
</response>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment