diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-02 20:40:47 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-02 20:40:47 +0000 |
commit | c60d3a08ee8d9608602808339e4b17d4c23fad8d (patch) | |
tree | da7681ae62c6f3fc53707294973bc69a381efdf9 /chrome/browser | |
parent | 019191a62f17852c6e8a5085bbd62e804d559718 (diff) | |
download | chromium_src-c60d3a08ee8d9608602808339e4b17d4c23fad8d.zip chromium_src-c60d3a08ee8d9608602808339e4b17d4c23fad8d.tar.gz chromium_src-c60d3a08ee8d9608602808339e4b17d4c23fad8d.tar.bz2 |
Make usage of iterator types more consistent, which also saves some code.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/243072
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27891 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/profile_manager.cc | 71 | ||||
-rw-r--r-- | chrome/browser/profile_manager.h | 6 |
2 files changed, 33 insertions, 44 deletions
diff --git a/chrome/browser/profile_manager.cc b/chrome/browser/profile_manager.cc index b24b7b2..3d15524 100644 --- a/chrome/browser/profile_manager.cc +++ b/chrome/browser/profile_manager.cc @@ -50,18 +50,14 @@ ProfileManager::~ProfileManager() { system_monitor->RemoveObserver(this); // Destroy all profiles that we're keeping track of. - for (ProfileVector::const_iterator iter = profiles_.begin(); - iter != profiles_.end(); ++iter) { - delete *iter; - } + for (const_iterator i(begin()); i != end(); ++i) + delete *i; profiles_.clear(); // Get rid of available profile list - for (AvailableProfileVector::const_iterator iter = - available_profiles_.begin(); - iter != available_profiles_.end(); ++iter) { - delete *iter; - } + for (AvailableProfileVector::const_iterator i(available_profiles_.begin()); + i != available_profiles_.end(); ++i) + delete *i; available_profiles_.clear(); } @@ -151,11 +147,10 @@ Profile* ProfileManager::AddProfileByID(const std::wstring& id) { AvailableProfile* ProfileManager::GetAvailableProfileByID( const std::wstring& id) { - AvailableProfileVector::const_iterator iter = available_profiles_.begin(); - for (; iter != available_profiles_.end(); ++iter) { - if ((*iter)->id() == id) { - return *iter; - } + for (AvailableProfileVector::const_iterator i(available_profiles_.begin()); + i != available_profiles_.end(); ++i) { + if ((*i)->id() == id) + return *i; } return NULL; @@ -183,21 +178,19 @@ bool ProfileManager::AddProfile(Profile* profile) { } void ProfileManager::RemoveProfile(Profile* profile) { - for (ProfileVector::iterator iter = profiles_.begin(); - iter != profiles_.end(); ++iter) { - if ((*iter) == profile) { - profiles_.erase(iter); + for (iterator i(begin()); i != end(); ++i) { + if ((*i) == profile) { + profiles_.erase(i); return; } } } void ProfileManager::RemoveProfileByPath(const FilePath& path) { - for (ProfileVector::iterator iter = profiles_.begin(); - iter != profiles_.end(); ++iter) { - if ((*iter)->GetPath() == path) { - delete *iter; - profiles_.erase(iter); + for (iterator i(begin()); i != end(); ++i) { + if ((*i)->GetPath() == path) { + delete *i; + profiles_.erase(i); return; } } @@ -206,20 +199,18 @@ void ProfileManager::RemoveProfileByPath(const FilePath& path) { } Profile* ProfileManager::GetProfileByPath(const FilePath& path) const { - for (ProfileVector::const_iterator iter = profiles_.begin(); - iter != profiles_.end(); ++iter) { - if ((*iter)->GetPath() == path) - return *iter; + for (const_iterator i(begin()); i != end(); ++i) { + if ((*i)->GetPath() == path) + return *i; } return NULL; } Profile* ProfileManager::GetProfileByID(const std::wstring& id) const { - for (ProfileVector::const_iterator iter = profiles_.begin(); - iter != profiles_.end(); ++iter) { - if ((*iter)->GetID() == id) - return *iter; + for (const_iterator i(begin()); i != end(); ++i) { + if ((*i)->GetID() == id) + return *i; } return NULL; @@ -228,21 +219,17 @@ Profile* ProfileManager::GetProfileByID(const std::wstring& id) const { void ProfileManager::OnSuspend() { DCHECK(CalledOnValidThread()); - ProfileManager::const_iterator it = begin(); - while(it != end()) { + for (const_iterator i(begin()); i != end(); ++i) { g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, - NewRunnableFunction(&ProfileManager::SuspendProfile, *it)); - it++; + NewRunnableFunction(&ProfileManager::SuspendProfile, *i)); } } void ProfileManager::OnResume() { DCHECK(CalledOnValidThread()); - ProfileManager::const_iterator it = begin(); - while (it != end()) { + for (const_iterator i(begin()); i != end(); ++i) { g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, - NewRunnableFunction(&ProfileManager::ResumeProfile, *it)); - it++; + NewRunnableFunction(&ProfileManager::ResumeProfile, *i)); } } @@ -251,9 +238,9 @@ void ProfileManager::SuspendProfile(Profile* profile) { DCHECK(MessageLoop::current() == ChromeThread::GetMessageLoop(ChromeThread::IO)); - URLRequestJobTracker::JobIterator it = g_url_request_job_tracker.begin(); - for (;it != g_url_request_job_tracker.end(); ++it) - (*it)->Kill(); + for (URLRequestJobTracker::JobIterator i = g_url_request_job_tracker.begin(); + i != g_url_request_job_tracker.end(); ++i) + (*i)->Kill(); profile->GetRequestContext()->http_transaction_factory()->Suspend(true); } diff --git a/chrome/browser/profile_manager.h b/chrome/browser/profile_manager.h index 56b9998..ecbbfc8 100644 --- a/chrome/browser/profile_manager.h +++ b/chrome/browser/profile_manager.h @@ -117,8 +117,10 @@ class ProfileManager : public NonThreadSafe, typedef ProfileVector::iterator iterator; typedef ProfileVector::const_iterator const_iterator; - const_iterator begin() { return profiles_.begin(); } - const_iterator end() { return profiles_.end(); } + iterator begin() { return profiles_.begin(); } + const_iterator begin() const { return profiles_.begin(); } + iterator end() { return profiles_.end(); } + const_iterator end() const { return profiles_.end(); } typedef std::vector<AvailableProfile*> AvailableProfileVector; const AvailableProfileVector& available_profiles() const { |