diff options
author | mark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-21 21:08:50 +0000 |
---|---|---|
committer | mark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-21 21:08:50 +0000 |
commit | 66aa1265b6ff166987ffc294b7796f827abd27bc (patch) | |
tree | 3545777d69c046f64074a00e782aac5d3228838f | |
parent | 15069dbc92e8768284393fe18a23f79106cd552e (diff) | |
download | chromium_src-66aa1265b6ff166987ffc294b7796f827abd27bc.zip chromium_src-66aa1265b6ff166987ffc294b7796f827abd27bc.tar.gz chromium_src-66aa1265b6ff166987ffc294b7796f827abd27bc.tar.bz2 |
Run MetricsResponseTest on the Mac. This test depended on
url_fetcher_protect.h, which contained a ProtectEntry class, but this name
conflicts with the ProtectEntry function in QuickDraw, and apparently QuickDraw
headers were being brought in by some other system header we use. Rename our
ProtectEntry to URLFetcherProtectEntry, and change ProtectManager for
consistency.
Review URL: http://codereview.chromium.org/7834
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3684 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/url_fetcher.cc | 9 | ||||
-rw-r--r-- | chrome/browser/url_fetcher.h | 2 | ||||
-rw-r--r-- | chrome/browser/url_fetcher_protect.cc | 56 | ||||
-rw-r--r-- | chrome/browser/url_fetcher_protect.h | 36 | ||||
-rw-r--r-- | chrome/browser/url_fetcher_unittest.cc | 15 | ||||
-rw-r--r-- | chrome/chrome.xcodeproj/project.pbxproj | 60 |
6 files changed, 123 insertions, 55 deletions
diff --git a/chrome/browser/url_fetcher.cc b/chrome/browser/url_fetcher.cc index 1a97053..e40d414 100644 --- a/chrome/browser/url_fetcher.cc +++ b/chrome/browser/url_fetcher.cc @@ -36,7 +36,7 @@ URLFetcher::Core::Core(URLFetcher* fetcher, request_(NULL), response_code_(-1), load_flags_(net::LOAD_NORMAL), - protect_entry_(ProtectManager::GetInstance()->Register( + protect_entry_(URLFetcherProtectManager::GetInstance()->Register( original_url_.host())), num_retries_(0) { } @@ -47,7 +47,7 @@ void URLFetcher::Core::Start() { DCHECK(request_context_) << "We need an URLRequestContext!"; io_loop_->PostDelayedTask(FROM_HERE, NewRunnableMethod( this, &Core::StartURLRequest), - protect_entry_->UpdateBackoff(ProtectEntry::SEND)); + protect_entry_->UpdateBackoff(URLFetcherProtectEntry::SEND)); } void URLFetcher::Core::Stop() { @@ -161,7 +161,8 @@ void URLFetcher::Core::OnCompletedURLRequest(const URLRequestStatus& status) { if (response_code_ >= 500) { // When encountering a server error, we will send the request again // after backoff time. - const int wait = protect_entry_->UpdateBackoff(ProtectEntry::FAILURE); + const int wait = + protect_entry_->UpdateBackoff(URLFetcherProtectEntry::FAILURE); ++num_retries_; // Restarts the request if we still need to notify the delegate. if (delegate_) { @@ -174,7 +175,7 @@ void URLFetcher::Core::OnCompletedURLRequest(const URLRequestStatus& status) { } } } else { - protect_entry_->UpdateBackoff(ProtectEntry::SUCCESS); + protect_entry_->UpdateBackoff(URLFetcherProtectEntry::SUCCESS); if (delegate_) delegate_->OnURLFetchComplete(fetcher_, url_, status, response_code_, cookies_, data_); diff --git a/chrome/browser/url_fetcher.h b/chrome/browser/url_fetcher.h index 2651480..b68b53c 100644 --- a/chrome/browser/url_fetcher.h +++ b/chrome/browser/url_fetcher.h @@ -200,7 +200,7 @@ class URLFetcher { // URL, to avoid placing too much demand on the remote resource. We update // this with the status of all requests as they return, and in turn use it // to determine how long to wait before making another request. - ProtectEntry* protect_entry_; + URLFetcherProtectEntry* protect_entry_; // |num_retries_| indicates how many times we've failed to successfully // fetch this URL. Once this value exceeds the maximum number of retries // specified by the protection manager, we'll give up. diff --git a/chrome/browser/url_fetcher_protect.cc b/chrome/browser/url_fetcher_protect.cc index def6b07..297a9bb 100644 --- a/chrome/browser/url_fetcher_protect.cc +++ b/chrome/browser/url_fetcher_protect.cc @@ -4,23 +4,23 @@ #include "chrome/browser/url_fetcher_protect.h" -// ProtectEntry -------------------------------------------------------------- +// URLFetcherProtectEntry ---------------------------------------------------- // Default parameters. Time is in milliseconds. // static -const int ProtectEntry::kDefaultSlidingWindowPeriod = 2000; +const int URLFetcherProtectEntry::kDefaultSlidingWindowPeriod = 2000; -const int ProtectEntry::kDefaultMaxSendThreshold = 20; -const int ProtectEntry::kDefaultMaxRetries = 0; +const int URLFetcherProtectEntry::kDefaultMaxSendThreshold = 20; +const int URLFetcherProtectEntry::kDefaultMaxRetries = 0; -const int ProtectEntry::kDefaultInitialTimeout = 100; -const double ProtectEntry::kDefaultMultiplier = 2.0; -const int ProtectEntry::kDefaultConstantFactor = 100; -const int ProtectEntry::kDefaultMaximumTimeout = 60000; +const int URLFetcherProtectEntry::kDefaultInitialTimeout = 100; +const double URLFetcherProtectEntry::kDefaultMultiplier = 2.0; +const int URLFetcherProtectEntry::kDefaultConstantFactor = 100; +const int URLFetcherProtectEntry::kDefaultMaximumTimeout = 60000; -ProtectEntry::ProtectEntry() +URLFetcherProtectEntry::URLFetcherProtectEntry() : sliding_window_period_(kDefaultSlidingWindowPeriod), max_send_threshold_(kDefaultMaxSendThreshold), max_retries_(kDefaultMaxRetries), @@ -31,10 +31,13 @@ ProtectEntry::ProtectEntry() ResetBackoff(); } -ProtectEntry::ProtectEntry(int sliding_window_period, int max_send_threshold, - int max_retries, int initial_timeout, - double multiplier, int constant_factor, - int maximum_timeout) +URLFetcherProtectEntry::URLFetcherProtectEntry(int sliding_window_period, + int max_send_threshold, + int max_retries, + int initial_timeout, + double multiplier, + int constant_factor, + int maximum_timeout) : sliding_window_period_(sliding_window_period), max_send_threshold_(max_send_threshold), max_retries_(max_retries), @@ -45,7 +48,7 @@ ProtectEntry::ProtectEntry(int sliding_window_period, int max_send_threshold, ResetBackoff(); } -int ProtectEntry::UpdateBackoff(EventType event_type) { +int URLFetcherProtectEntry::UpdateBackoff(EventType event_type) { // request may be sent in different threads AutoLock lock(lock_); @@ -69,7 +72,7 @@ int ProtectEntry::UpdateBackoff(EventType event_type) { return wait; } -TimeDelta ProtectEntry::AntiOverload() { +TimeDelta URLFetcherProtectEntry::AntiOverload() { TimeDelta sw = TimeDelta::FromMilliseconds(sliding_window_period_); TimeTicks now = TimeTicks::Now(); // Estimate when the next request will be sent. @@ -91,13 +94,13 @@ TimeDelta ProtectEntry::AntiOverload() { return release_time_ - now; } -TimeDelta ProtectEntry::ResetBackoff() { +TimeDelta URLFetcherProtectEntry::ResetBackoff() { timeout_period_ = initial_timeout_; release_time_ = TimeTicks::Now(); return TimeDelta::FromMilliseconds(0); } -TimeDelta ProtectEntry::IncreaseBackoff() { +TimeDelta URLFetcherProtectEntry::IncreaseBackoff() { TimeTicks now = TimeTicks::Now(); release_time_ = std::max(release_time_, now) + @@ -112,13 +115,13 @@ TimeDelta ProtectEntry::IncreaseBackoff() { return release_time_ - now; } -// ProtectManager ------------------------------------------------------------ +// URLFetcherProtectManager -------------------------------------------------- // static -scoped_ptr<ProtectManager> ProtectManager::protect_manager_; -Lock ProtectManager::lock_; +scoped_ptr<URLFetcherProtectManager> URLFetcherProtectManager::protect_manager_; +Lock URLFetcherProtectManager::lock_; -ProtectManager::~ProtectManager() { +URLFetcherProtectManager::~URLFetcherProtectManager() { // Deletes all entries ProtectService::iterator i; for (i = services_.begin(); i != services_.end(); ++i) { @@ -128,16 +131,16 @@ ProtectManager::~ProtectManager() { } // static -ProtectManager* ProtectManager::GetInstance() { +URLFetcherProtectManager* URLFetcherProtectManager::GetInstance() { AutoLock lock(lock_); if (protect_manager_.get() == NULL) { - protect_manager_.reset(new ProtectManager()); + protect_manager_.reset(new URLFetcherProtectManager()); } return protect_manager_.get(); } -ProtectEntry* ProtectManager::Register(std::string id) { +URLFetcherProtectEntry* URLFetcherProtectManager::Register(std::string id) { AutoLock lock(lock_); ProtectService::iterator i = services_.find(id); @@ -148,12 +151,13 @@ ProtectEntry* ProtectManager::Register(std::string id) { } // Creates a new entry. - ProtectEntry* entry = new ProtectEntry(); + URLFetcherProtectEntry* entry = new URLFetcherProtectEntry(); services_[id] = entry; return entry; } -ProtectEntry* ProtectManager::Register(std::string id, ProtectEntry* entry) { +URLFetcherProtectEntry* URLFetcherProtectManager::Register( + std::string id, URLFetcherProtectEntry* entry) { AutoLock lock(lock_); ProtectService::iterator i = services_.find(id); diff --git a/chrome/browser/url_fetcher_protect.h b/chrome/browser/url_fetcher_protect.h index 238d307..6e4080d 100644 --- a/chrome/browser/url_fetcher_protect.h +++ b/chrome/browser/url_fetcher_protect.h @@ -33,7 +33,7 @@ // maximum backoff time (when backoff > maximum backoff time) // // where |k| is the multiplier, and |c| is the constant factor. -class ProtectEntry { +class URLFetcherProtectEntry { public: enum EventType { SEND, // request will be sent out @@ -41,14 +41,14 @@ class ProtectEntry { FAILURE // no response or error }; - ProtectEntry(); - ProtectEntry(int sliding_window_period, int max_send_threshold, - int max_retries, int initial_timeout, - double multiplier, int constant_factor, - int maximum_timeout); + URLFetcherProtectEntry(); + URLFetcherProtectEntry(int sliding_window_period, int max_send_threshold, + int max_retries, int initial_timeout, + double multiplier, int constant_factor, + int maximum_timeout); - virtual ~ProtectEntry() { } + virtual ~URLFetcherProtectEntry() { } // When a connection event happens, log it to the queue, and recalculate // the timeout period. It returns the backoff time, in milliseconds, that @@ -110,36 +110,36 @@ class ProtectEntry { // there are too many requests sent in sliding window. std::queue<TimeTicks> send_log_; - DISALLOW_EVIL_CONSTRUCTORS(ProtectEntry); + DISALLOW_COPY_AND_ASSIGN(URLFetcherProtectEntry); }; // This singleton class is used to manage all protect entries. // Now we use the host name as service id. -class ProtectManager { +class URLFetcherProtectManager { public: - ~ProtectManager(); + ~URLFetcherProtectManager(); // Returns the global instance of this class. - static ProtectManager* GetInstance(); + static URLFetcherProtectManager* GetInstance(); // Registers a new entry in this service. If the entry already exists, // just returns it. - ProtectEntry* Register(std::string id); + URLFetcherProtectEntry* Register(std::string id); // Always registers the entry even when it exists. - ProtectEntry* Register(std::string id, ProtectEntry* entry); + URLFetcherProtectEntry* Register(std::string id, + URLFetcherProtectEntry* entry); private: - ProtectManager() { } + URLFetcherProtectManager() { } - typedef std::map<const std::string, ProtectEntry*> ProtectService; + typedef std::map<const std::string, URLFetcherProtectEntry*> ProtectService; static Lock lock_; - static scoped_ptr<ProtectManager> protect_manager_; + static scoped_ptr<URLFetcherProtectManager> protect_manager_; ProtectService services_; - DISALLOW_EVIL_CONSTRUCTORS(ProtectManager); + DISALLOW_COPY_AND_ASSIGN(URLFetcherProtectManager); }; #endif // CHROME_BROWSER_URL_FETCHER_PROTECT_H__ - diff --git a/chrome/browser/url_fetcher_unittest.cc b/chrome/browser/url_fetcher_unittest.cc index ee00d42..2ae69aa 100644 --- a/chrome/browser/url_fetcher_unittest.cc +++ b/chrome/browser/url_fetcher_unittest.cc @@ -376,8 +376,9 @@ TEST_F(URLFetcherProtectTest, Overload) { // Registers an entry for test url. It only allows 3 requests to be sent // in 200 milliseconds. - ProtectManager* manager = ProtectManager::GetInstance(); - ProtectEntry* entry = new ProtectEntry(200, 3, 11, 1, 2.0, 0, 256); + URLFetcherProtectManager* manager = URLFetcherProtectManager::GetInstance(); + URLFetcherProtectEntry* entry = + new URLFetcherProtectEntry(200, 3, 11, 1, 2.0, 0, 256); manager->Register(url.host(), entry); CreateFetcher(url); @@ -393,8 +394,9 @@ TEST_F(URLFetcherProtectTest, ServerUnavailable) { // new_backoff = 2.0 * old_backoff + 0 // and maximum backoff time is 256 milliseconds. // Maximum retries allowed is set to 11. - ProtectManager* manager = ProtectManager::GetInstance(); - ProtectEntry* entry = new ProtectEntry(200, 3, 11, 1, 2.0, 0, 256); + URLFetcherProtectManager* manager = URLFetcherProtectManager::GetInstance(); + URLFetcherProtectEntry* entry = + new URLFetcherProtectEntry(200, 3, 11, 1, 2.0, 0, 256); manager->Register(url.host(), entry); CreateFetcher(url); @@ -419,8 +421,9 @@ TEST_F(URLFetcherCancelTest, ReleasesContext) { // new_backoff = 2.0 * old_backoff + 0 // The initial backoff is 2 seconds and maximum backoff is 4 seconds. // Maximum retries allowed is set to 2. - ProtectManager* manager = ProtectManager::GetInstance(); - ProtectEntry* entry = new ProtectEntry(200, 3, 2, 2000, 2.0, 0, 4000); + URLFetcherProtectManager* manager = URLFetcherProtectManager::GetInstance(); + URLFetcherProtectEntry* entry = + new URLFetcherProtectEntry(200, 3, 2, 2000, 2.0, 0, 4000); manager->Register(url.host(), entry); // Create a separate thread that will create the URLFetcher. The current diff --git a/chrome/chrome.xcodeproj/project.pbxproj b/chrome/chrome.xcodeproj/project.pbxproj index 5f8a155..e9408af 100644 --- a/chrome/chrome.xcodeproj/project.pbxproj +++ b/chrome/chrome.xcodeproj/project.pbxproj @@ -131,6 +131,9 @@ 4D7BFF730E9D5425009A6919 /* libgoogleurl.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4D7BFF6E0E9D540F009A6919 /* libgoogleurl.a */; }; 4D7BFF7B0E9D5449009A6919 /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4D7BFF7A0E9D5449009A6919 /* AppKit.framework */; }; 4DC6498F0EA92BF90017C876 /* platform_test_mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4DC6498E0EA92BF90017C876 /* platform_test_mac.mm */; }; + 4DDC63E70EAE344300FB5EBE /* metrics_response_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4D7BF8B60E9D4839009A6919 /* metrics_response_unittest.cc */; }; + 4DDC644B0EAE390800FB5EBE /* libxml.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4D7BFB230E9D4BBF009A6919 /* libxml.a */; }; + 4DDC64580EAE394200FB5EBE /* libzlib.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4DDC64550EAE392400FB5EBE /* libzlib.a */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -456,6 +459,27 @@ remoteGlobalIDString = 7BA018350E5A28DB00044150; remoteInfo = googleurl; }; + 4DDC64490EAE38F500FB5EBE /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 4D7BFB0B0E9D4BBF009A6919 /* libxml.xcodeproj */; + proxyType = 1; + remoteGlobalIDString = 7B12F2AB0D8EE24200CB6E8F /* xml */; + remoteInfo = xml; + }; + 4DDC64540EAE392400FB5EBE /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 4DDC64500EAE392400FB5EBE /* zlib.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = D2AAC046055464E500DB518D /* libzlib.a */; + remoteInfo = zlib; + }; + 4DDC64560EAE393800FB5EBE /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 4DDC64500EAE392400FB5EBE /* zlib.xcodeproj */; + proxyType = 1; + remoteGlobalIDString = D2AAC045055464E500DB518D /* zlib */; + remoteInfo = zlib; + }; /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ @@ -1153,6 +1177,7 @@ 4D7BFF5F0E9D540F009A6919 /* googleurl.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = googleurl.xcodeproj; path = build/googleurl.xcodeproj; sourceTree = "<group>"; }; 4D7BFF7A0E9D5449009A6919 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = "<group>"; }; 4DC6498E0EA92BF90017C876 /* platform_test_mac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = platform_test_mac.mm; sourceTree = "<group>"; }; + 4DDC64500EAE392400FB5EBE /* zlib.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = zlib.xcodeproj; path = third_party/zlib/zlib.xcodeproj; sourceTree = "<group>"; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -1186,6 +1211,8 @@ 4D7B00510E9D5473009A6919 /* libnet.a in Frameworks */, 4D7B00520E9D5473009A6919 /* libskia.a in Frameworks */, 4D7B01420E9D56C4009A6919 /* libsqlite.a in Frameworks */, + 4DDC644B0EAE390800FB5EBE /* libxml.a in Frameworks */, + 4DDC64580EAE394200FB5EBE /* libzlib.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1843,6 +1870,7 @@ 4D7B00340E9D5464009A6919 /* net.xcodeproj */, 4D7B002E0E9D5459009A6919 /* skia.xcodeproj */, 4D7B01390E9D56BC009A6919 /* sqlite.xcodeproj */, + 4DDC64500EAE392400FB5EBE /* zlib.xcodeproj */, ); name = Projects; path = ..; @@ -2154,6 +2182,14 @@ path = ../base; sourceTree = "<group>"; }; + 4DDC64510EAE392400FB5EBE /* Products */ = { + isa = PBXGroup; + children = ( + 4DDC64550EAE392400FB5EBE /* libzlib.a */, + ); + name = Products; + sourceTree = "<group>"; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -2196,10 +2232,12 @@ 4D7BFE780E9D52EB009A6919 /* PBXTargetDependency */, 4D7BFF580E9D53D2009A6919 /* PBXTargetDependency */, 4D7BFF390E9D536D009A6919 /* PBXTargetDependency */, + 4DDC644A0EAE38F500FB5EBE /* PBXTargetDependency */, 4D7B00600E9D54BF009A6919 /* PBXTargetDependency */, 4D7B00560E9D5487009A6919 /* PBXTargetDependency */, 4D7B00540E9D5487009A6919 /* PBXTargetDependency */, 4D7B01440E9D56CC009A6919 /* PBXTargetDependency */, + 4DDC64570EAE393800FB5EBE /* PBXTargetDependency */, ); name = unit_tests; productName = unit_tests; @@ -2283,6 +2321,10 @@ ProductGroup = 4D7B013A0E9D56BC009A6919 /* Products */; ProjectRef = 4D7B01390E9D56BC009A6919 /* sqlite.xcodeproj */; }, + { + ProductGroup = 4DDC64510EAE392400FB5EBE /* Products */; + ProjectRef = 4DDC64500EAE392400FB5EBE /* zlib.xcodeproj */; + }, ); projectRoot = ""; targets = ( @@ -2464,6 +2506,13 @@ remoteRef = 4D7BFF6F0E9D540F009A6919 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; + 4DDC64550EAE392400FB5EBE /* libzlib.a */ = { + isa = PBXReferenceProxy; + fileType = archive.ar; + path = libzlib.a; + remoteRef = 4DDC64540EAE392400FB5EBE /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; /* End PBXReferenceProxy section */ /* Begin PBXShellScriptBuildPhase section */ @@ -2541,6 +2590,7 @@ 4D7BFB3C0E9D4C25009A6919 /* history_types_unittest.cc in Sources */, 4D7BFCE30E9D4DCE009A6919 /* jpeg_codec_unittest.cc in Sources */, 4D7BFCE70E9D4DD4009A6919 /* json_value_serializer_unittest.cc in Sources */, + 4DDC63E70EAE344300FB5EBE /* metrics_response_unittest.cc in Sources */, 4D7BFB580E9D4C43009A6919 /* page_range_unittest.cc in Sources */, 4D7BFB5F0E9D4C46009A6919 /* page_setup_unittest.cc in Sources */, 4DC6498F0EA92BF90017C876 /* platform_test_mac.mm in Sources */, @@ -2695,6 +2745,16 @@ name = googleurl; targetProxy = 4D7BFF710E9D5416009A6919 /* PBXContainerItemProxy */; }; + 4DDC644A0EAE38F500FB5EBE /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + name = xml; + targetProxy = 4DDC64490EAE38F500FB5EBE /* PBXContainerItemProxy */; + }; + 4DDC64570EAE393800FB5EBE /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + name = zlib; + targetProxy = 4DDC64560EAE393800FB5EBE /* PBXContainerItemProxy */; + }; /* End PBXTargetDependency section */ /* Begin XCBuildConfiguration section */ |