Cleanup in chrome/browser
- make more things const
- remove unreferenced declaration of GetGoButton
- fix indentation in one place
Review URL: http://codereview.chromium.org/53053
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12475 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/base/process_util.h b/base/process_util.h
index 0f074b1..35a051a 100644
--- a/base/process_util.h
+++ b/base/process_util.h
@@ -290,27 +290,27 @@
// Returns the current space allocated for the pagefile, in bytes (these pages
// may or may not be in memory).
- size_t GetPagefileUsage();
+ size_t GetPagefileUsage() const;
// Returns the peak space allocated for the pagefile, in bytes.
- size_t GetPeakPagefileUsage();
+ size_t GetPeakPagefileUsage() const;
// Returns the current working set size, in bytes.
- size_t GetWorkingSetSize();
+ size_t GetWorkingSetSize() const;
// Returns private usage, in bytes. Private bytes is the amount
// of memory currently allocated to a process that cannot be shared.
// Note: returns 0 on unsupported OSes: prior to XP SP2.
- size_t GetPrivateBytes();
+ size_t GetPrivateBytes() const;
// Fills a CommittedKBytes with both resident and paged
// memory usage as per definition of CommittedBytes.
- void GetCommittedKBytes(CommittedKBytes* usage);
+ void GetCommittedKBytes(CommittedKBytes* usage) const;
// Fills a WorkingSetKBytes containing resident private and shared memory
// usage in bytes, as per definition of WorkingSetBytes.
- bool GetWorkingSetKBytes(WorkingSetKBytes* ws_usage);
+ bool GetWorkingSetKBytes(WorkingSetKBytes* ws_usage) const;
// Computes the current process available memory for allocation.
// It does a linear scan of the address space querying each memory region
// for its free (unallocated) status. It is useful for estimating the memory
// load and fragmentation.
- bool CalculateFreeMemory(FreeMBytes* free);
+ bool CalculateFreeMemory(FreeMBytes* free) const;
// Returns the CPU usage in percent since the last time this method was
// called. The first time this method is called it returns 0 and will return
@@ -325,7 +325,7 @@
// If IO information is retrieved successfully, the function returns true
// and fills in the IO_COUNTERS passed in. The function returns false
// otherwise.
- bool GetIOCounters(IoCounters* io_counters);
+ bool GetIOCounters(IoCounters* io_counters) const;
private:
explicit ProcessMetrics(ProcessHandle process);
diff --git a/base/process_util_linux.cc b/base/process_util_linux.cc
index 7e43885..dcac3bd 100644
--- a/base/process_util_linux.cc
+++ b/base/process_util_linux.cc
@@ -202,7 +202,7 @@
// To have /proc/self/io file you must enable CONFIG_TASK_IO_ACCOUNTING
// in your kernel configuration.
-bool ProcessMetrics::GetIOCounters(IoCounters* io_counters) {
+bool ProcessMetrics::GetIOCounters(IoCounters* io_counters) const {
std::string proc_io_contents;
if (!file_util::ReadFileToString(L"/proc/self/io", &proc_io_contents))
return false;
diff --git a/base/process_util_mac.mm b/base/process_util_mac.mm
index ff78c07..98714c8 100644
--- a/base/process_util_mac.mm
+++ b/base/process_util_mac.mm
@@ -226,7 +226,7 @@
return filter_->Includes(entry_.pid, entry_.ppid);
}
-bool ProcessMetrics::GetIOCounters(IoCounters* io_counters) {
+bool ProcessMetrics::GetIOCounters(IoCounters* io_counters) const {
// TODO(pinkerton): can we implement this? On linux it relies on /proc.
NOTIMPLEMENTED();
return false;
diff --git a/base/process_util_win.cc b/base/process_util_win.cc
index 0ced788..beb4ea34 100644
--- a/base/process_util_win.cc
+++ b/base/process_util_win.cc
@@ -388,7 +388,7 @@
ProcessMetrics::~ProcessMetrics() { }
-size_t ProcessMetrics::GetPagefileUsage() {
+size_t ProcessMetrics::GetPagefileUsage() const {
PROCESS_MEMORY_COUNTERS pmc;
if (GetProcessMemoryInfo(process_, &pmc, sizeof(pmc))) {
return pmc.PagefileUsage;
@@ -397,7 +397,7 @@
}
// Returns the peak space allocated for the pagefile, in bytes.
-size_t ProcessMetrics::GetPeakPagefileUsage() {
+size_t ProcessMetrics::GetPeakPagefileUsage() const {
PROCESS_MEMORY_COUNTERS pmc;
if (GetProcessMemoryInfo(process_, &pmc, sizeof(pmc))) {
return pmc.PeakPagefileUsage;
@@ -406,7 +406,7 @@
}
// Returns the current working set size, in bytes.
-size_t ProcessMetrics::GetWorkingSetSize() {
+size_t ProcessMetrics::GetWorkingSetSize() const {
PROCESS_MEMORY_COUNTERS pmc;
if (GetProcessMemoryInfo(process_, &pmc, sizeof(pmc))) {
return pmc.WorkingSetSize;
@@ -414,7 +414,7 @@
return 0;
}
-size_t ProcessMetrics::GetPrivateBytes() {
+size_t ProcessMetrics::GetPrivateBytes() const {
// PROCESS_MEMORY_COUNTERS_EX is not supported until XP SP2.
// GetProcessMemoryInfo() will simply fail on prior OS. So the requested
// information is simply not available. Hence, we will return 0 on unsupported
@@ -428,7 +428,7 @@
return 0;
}
-void ProcessMetrics::GetCommittedKBytes(CommittedKBytes* usage) {
+void ProcessMetrics::GetCommittedKBytes(CommittedKBytes* usage) const {
MEMORY_BASIC_INFORMATION mbi = {0};
size_t committed_private = 0;
size_t committed_mapped = 0;
@@ -455,7 +455,7 @@
usage->priv = committed_private / 1024;
}
-bool ProcessMetrics::GetWorkingSetKBytes(WorkingSetKBytes* ws_usage) {
+bool ProcessMetrics::GetWorkingSetKBytes(WorkingSetKBytes* ws_usage) const {
size_t ws_private = 0;
size_t ws_shareable = 0;
size_t ws_shared = 0;
@@ -574,11 +574,11 @@
return cpu;
}
-bool ProcessMetrics::GetIOCounters(IO_COUNTERS* io_counters) {
+bool ProcessMetrics::GetIOCounters(IO_COUNTERS* io_counters) const {
return GetProcessIoCounters(process_, io_counters) != FALSE;
}
-bool ProcessMetrics::CalculateFreeMemory(FreeMBytes* free) {
+bool ProcessMetrics::CalculateFreeMemory(FreeMBytes* free) const {
const SIZE_T kTopAdress = 0x7F000000;
const SIZE_T kMegabyte = 1024 * 1024;
SIZE_T accumulated = 0;
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index 5e1b4ca..f1b3a5b 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -2400,7 +2400,7 @@
}
}
-bool Browser::HasCompletedUnloadProcessing() {
+bool Browser::HasCompletedUnloadProcessing() const {
return is_attempting_to_close_browser_ &&
tabs_needing_before_unload_fired_.empty() &&
tabs_needing_unload_fired_.empty();
@@ -2465,7 +2465,7 @@
gfx::Rect(), true);
}
-GURL Browser::GetHomePage() {
+GURL Browser::GetHomePage() const {
if (profile_->GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage))
return GURL(chrome::kChromeUINewTabURL);
GURL home_page = GURL(URLFixerUpper::FixupURL(
diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h
index bb91b299..d41b53768 100644
--- a/chrome/browser/browser.h
+++ b/chrome/browser/browser.h
@@ -497,9 +497,6 @@
// the LocationBarView's edit.
friend class AutomationProvider;
- // Getters for the location bar and go button.
- GoButton* GetGoButton();
-
// Returns the StatusBubble from the current toolbar. It is possible for
// this to return NULL if called before the toolbar has initialized.
// TODO(beng): remove this.
@@ -526,7 +523,7 @@
void ProcessPendingTabs();
// Whether we've completed firing all the tabs' beforeunload/unload events.
- bool HasCompletedUnloadProcessing();
+ bool HasCompletedUnloadProcessing() const;
// Clears all the state associated with processing tabs' beforeunload/unload
// events since the user cancelled closing the window.
@@ -558,7 +555,7 @@
// Returns what the user's home page is, or the new tab page if the home page
// has not been set.
- GURL GetHomePage();
+ GURL GetHomePage() const;
// Shows the Find Bar, optionally selecting the next entry that matches the
// existing search string for that Tab. |forward_direction| controls the
diff --git a/chrome/browser/tabs/tab_strip_model.cc b/chrome/browser/tabs/tab_strip_model.cc
index 36b8f52..823b49e 100644
--- a/chrome/browser/tabs/tab_strip_model.cc
+++ b/chrome/browser/tabs/tab_strip_model.cc
@@ -246,7 +246,7 @@
}
int TabStripModel::GetIndexOfNextTabContentsOpenedBy(
- NavigationController* opener, int start_index, bool use_group) {
+ const NavigationController* opener, int start_index, bool use_group) const {
DCHECK(opener);
DCHECK(ContainsIndex(start_index));
@@ -272,7 +272,7 @@
}
int TabStripModel::GetIndexOfLastTabContentsOpenedBy(
- NavigationController* opener, int start_index) {
+ const NavigationController* opener, int start_index) const {
DCHECK(opener);
DCHECK(ContainsIndex(start_index));
@@ -418,7 +418,7 @@
// Context menu functions.
bool TabStripModel::IsContextMenuCommandEnabled(
- int context_index, ContextMenuCommand command_id) {
+ int context_index, ContextMenuCommand command_id) const {
DCHECK(command_id > CommandFirst && command_id < CommandLast);
switch (command_id) {
case CommandNewTab:
@@ -588,8 +588,8 @@
}
// static
-bool TabStripModel::OpenerMatches(TabContentsData* data,
- NavigationController* opener,
+bool TabStripModel::OpenerMatches(const TabContentsData* data,
+ const NavigationController* opener,
bool use_group) {
return data->opener == opener || (use_group && data->group == opener);
}
diff --git a/chrome/browser/tabs/tab_strip_model.h b/chrome/browser/tabs/tab_strip_model.h
index ca90db4..ab229da 100644
--- a/chrome/browser/tabs/tab_strip_model.h
+++ b/chrome/browser/tabs/tab_strip_model.h
@@ -303,14 +303,14 @@
// If |use_group| is true, the group property of the tab is used instead of
// the opener to find the next tab. Under some circumstances the group
// relationship may exist but the opener may not.
- int GetIndexOfNextTabContentsOpenedBy(NavigationController* opener,
+ int GetIndexOfNextTabContentsOpenedBy(const NavigationController* opener,
int start_index,
- bool use_group);
+ bool use_group) const;
// Returns the index of the last TabContents in the model opened by the
// specified opener, starting at |start_index|.
- int GetIndexOfLastTabContentsOpenedBy(NavigationController* opener,
- int start_index);
+ int GetIndexOfLastTabContentsOpenedBy(const NavigationController* opener,
+ int start_index) const;
// Called by the Browser when a navigation is about to occur in the specified
// TabContents. Depending on the tab, and the transition type of the
@@ -384,7 +384,7 @@
// Returns true if the specified command is enabled.
bool IsContextMenuCommandEnabled(int context_index,
- ContextMenuCommand command_id);
+ ContextMenuCommand command_id) const;
// Performs the action associated with the specified command for the given
// TabStripModel index |context_index|.
@@ -445,8 +445,8 @@
// that matches the specified one. If |use_group| is true, then this will
// fall back to check the group relationship as well.
struct TabContentsData;
- static bool OpenerMatches(TabContentsData* data,
- NavigationController* opener,
+ static bool OpenerMatches(const TabContentsData* data,
+ const NavigationController* opener,
bool use_group);
// Our delegate.
diff --git a/chrome/browser/task_manager.cc b/chrome/browser/task_manager.cc
index ab7c562..c0f189b 100644
--- a/chrome/browser/task_manager.cc
+++ b/chrome/browser/task_manager.cc
@@ -165,35 +165,36 @@
}
}
-int64 TaskManagerTableModel::GetNetworkUsage(TaskManager::Resource* resource) {
+int64 TaskManagerTableModel::GetNetworkUsage(TaskManager::Resource* resource)
+ const {
int64 net_usage = GetNetworkUsageForResource(resource);
if (net_usage == 0 && !resource->SupportNetworkUsage())
return -1;
return net_usage;
}
-int TaskManagerTableModel::GetCPUUsage(TaskManager::Resource* resource) {
+int TaskManagerTableModel::GetCPUUsage(TaskManager::Resource* resource) const {
CPUUsageMap::const_iterator iter =
cpu_usage_map_.find(resource->GetProcess());
- if (iter == cpu_usage_map_.end())
- return 0;
- return iter->second;
+ if (iter == cpu_usage_map_.end())
+ return 0;
+ return iter->second;
}
size_t TaskManagerTableModel::GetPrivateMemory(
- base::ProcessMetrics* process_metrics) {
+ const base::ProcessMetrics* process_metrics) const {
return process_metrics->GetPrivateBytes() / 1024;
}
size_t TaskManagerTableModel::GetSharedMemory(
- base::ProcessMetrics* process_metrics) {
+ const base::ProcessMetrics* process_metrics) const {
base::WorkingSetKBytes ws_usage;
process_metrics->GetWorkingSetKBytes(&ws_usage);
return ws_usage.shared;
}
size_t TaskManagerTableModel::GetPhysicalMemory(
- base::ProcessMetrics* process_metrics) {
+ const base::ProcessMetrics* process_metrics) const {
// Memory = working_set.private + working_set.shareable.
// We exclude the shared memory.
size_t total_kbytes = process_metrics->GetWorkingSetSize() / 1024;
@@ -203,8 +204,8 @@
return total_kbytes;
}
-int TaskManagerTableModel::GetStatsValue(TaskManager::Resource* resource,
- int col_id) {
+int TaskManagerTableModel::GetStatsValue(const TaskManager::Resource* resource,
+ int col_id) const {
StatsTable* table = StatsTable::current();
if (table != NULL) {
const char* counter = table->GetRowName(col_id);
@@ -558,8 +559,8 @@
}
int64 TaskManagerTableModel::GetNetworkUsageForResource(
- TaskManager::Resource* resource) {
- ResourceValueMap::iterator iter =
+ TaskManager::Resource* resource) const {
+ ResourceValueMap::const_iterator iter =
displayed_network_usage_map_.find(resource);
if (iter == displayed_network_usage_map_.end())
return 0;
diff --git a/chrome/browser/task_manager.h b/chrome/browser/task_manager.h
index 8f67eb8c..717dcf2 100644
--- a/chrome/browser/task_manager.h
+++ b/chrome/browser/task_manager.h
@@ -238,7 +238,7 @@
// Returns the network usage (in bytes per seconds) for the specified
// resource. That's the value retrieved at the last timer's tick.
- int64 GetNetworkUsageForResource(TaskManager::Resource* resource);
+ int64 GetNetworkUsageForResource(TaskManager::Resource* resource) const;
// Called on the UI thread when some bytes are read.
void BytesRead(BytesReadParam param);
@@ -246,27 +246,27 @@
// Returns the network usage (in byte per second) that should be displayed for
// the passed |resource|. -1 means the information is not available for that
// resource.
- int64 GetNetworkUsage(TaskManager::Resource* resource);
+ int64 GetNetworkUsage(TaskManager::Resource* resource) const;
// Returns the CPU usage (in %) that should be displayed for the passed
// |resource|.
- int GetCPUUsage(TaskManager::Resource* resource);
+ int GetCPUUsage(TaskManager::Resource* resource) const;
// Retrieves the private memory (in KB) that should be displayed from the
// passed |process_metrics|.
- size_t GetPrivateMemory(base::ProcessMetrics* process_metrics);
+ size_t GetPrivateMemory(const base::ProcessMetrics* process_metrics) const;
// Returns the shared memory (in KB) that should be displayed from the passed
// |process_metrics|.
- size_t GetSharedMemory(base::ProcessMetrics* process_metrics);
+ size_t GetSharedMemory(const base::ProcessMetrics* process_metrics) const;
// Returns the pysical memory (in KB) that should be displayed from the passed
// |process_metrics|.
- size_t GetPhysicalMemory(base::ProcessMetrics* process_metrics);
+ size_t GetPhysicalMemory(const base::ProcessMetrics* process_metrics) const;
// Returns the stat value at the column |col_id| that should be displayed from
// the passed |process_metrics|.
- int GetStatsValue(TaskManager::Resource* resource, int col_id);
+ int GetStatsValue(const TaskManager::Resource* resource, int col_id) const;
// Retrieves the ProcessMetrics for the resources at the specified rows.
// Returns true if there was a ProcessMetrics available for both rows.
diff --git a/chrome/browser/webdata/web_data_service.cc b/chrome/browser/webdata/web_data_service.cc
index 4f0dece..e514847 100644
--- a/chrome/browser/webdata/web_data_service.cc
+++ b/chrome/browser/webdata/web_data_service.cc
@@ -79,7 +79,7 @@
}
}
-bool WebDataService::IsRunning() {
+bool WebDataService::IsRunning() const {
return thread_ != NULL;
}
diff --git a/chrome/browser/webdata/web_data_service.h b/chrome/browser/webdata/web_data_service.h
index efeaf054..08c0dbe 100644
--- a/chrome/browser/webdata/web_data_service.h
+++ b/chrome/browser/webdata/web_data_service.h
@@ -153,7 +153,7 @@
void Shutdown();
// Returns false if Shutdown() has been called.
- bool IsRunning();
+ bool IsRunning() const;
//////////////////////////////////////////////////////////////////////////////
//
diff --git a/chrome/browser/webdata/web_database.cc b/chrome/browser/webdata/web_database.cc
index b9b64f3..fe9fb5f 100644
--- a/chrome/browser/webdata/web_database.cc
+++ b/chrome/browser/webdata/web_database.cc
@@ -224,7 +224,7 @@
}
bool WebDatabase::GetWebAppImages(const GURL& url,
- std::vector<SkBitmap>* images) {
+ std::vector<SkBitmap>* images) const {
SQLStatement s;
if (s.prepare(db_, "SELECT image FROM web_app_icons WHERE url=?") !=
SQLITE_OK) {
@@ -259,7 +259,7 @@
return (s.step() == SQLITE_DONE);
}
-bool WebDatabase::GetWebAppHasAllImages(const GURL& url) {
+bool WebDatabase::GetWebAppHasAllImages(const GURL& url) const {
SQLStatement s;
if (s.prepare(db_, "SELECT has_all_images FROM web_apps "
"WHERE url=?") != SQLITE_OK) {
@@ -524,7 +524,7 @@
return s.step() == SQLITE_DONE;
}
-bool WebDatabase::GetKeywords(std::vector<TemplateURL*>* urls) {
+bool WebDatabase::GetKeywords(std::vector<TemplateURL*>* urls) const {
SQLStatement s;
if (s.prepare(db_,
"SELECT id, short_name, keyword, favicon_url, url, "
@@ -784,7 +784,7 @@
}
bool WebDatabase::GetLogins(const PasswordForm& form,
- std::vector<PasswordForm*>* forms) {
+ std::vector<PasswordForm*>* forms) const {
DCHECK(forms);
SQLStatement s;
if (s.prepare(db_,
@@ -812,7 +812,7 @@
}
bool WebDatabase::GetAllLogins(std::vector<PasswordForm*>* forms,
- bool include_blacklisted) {
+ bool include_blacklisted) const {
DCHECK(forms);
SQLStatement s;
std::string stmt = "SELECT origin_url, action_url, "
@@ -876,7 +876,7 @@
}
bool WebDatabase::GetIDAndCountOfFormElement(
- const AutofillForm::Element& element, int64* pair_id, int* count) {
+ const AutofillForm::Element& element, int64* pair_id, int* count) const {
SQLStatement s;
if (s.prepare(db_, "SELECT pair_id, count FROM autofill "
@@ -900,7 +900,7 @@
return true;
}
-bool WebDatabase::GetCountOfFormElement(int64 pair_id, int* count) {
+bool WebDatabase::GetCountOfFormElement(int64 pair_id, int* count) const {
SQLStatement s;
if (s.prepare(db_, "SELECT count FROM autofill "
@@ -1010,7 +1010,7 @@
bool WebDatabase::GetFormValuesForElementName(const std::wstring& name,
const std::wstring& prefix,
std::vector<std::wstring>* values,
- int limit) {
+ int limit) const {
DCHECK(values);
SQLStatement s;
diff --git a/chrome/browser/webdata/web_database.h b/chrome/browser/webdata/web_database.h
index 35847011..04250d9 100644
--- a/chrome/browser/webdata/web_database.h
+++ b/chrome/browser/webdata/web_database.h
@@ -59,7 +59,7 @@
// Loads the keywords into the specified vector. It's up to the caller to
// delete the returned objects.
// Returns true on success.
- bool GetKeywords(std::vector<TemplateURL*>* urls);
+ bool GetKeywords(std::vector<TemplateURL*>* urls) const;
// Updates the database values for the specified url.
// Returns true on success.
@@ -108,14 +108,15 @@
// Loads a list of matching password forms into the specified vector |forms|.
// The list will contain all possibly relevant entries to the observed |form|,
// including blacklisted matches.
- bool GetLogins(const PasswordForm& form, std::vector<PasswordForm*>* forms);
+ bool GetLogins(const PasswordForm& form,
+ std::vector<PasswordForm*>* forms) const;
// Loads the complete list of password forms into the specified vector |forms|
// if include_blacklisted is true, otherwise only loads those which are
// actually autofillable; i.e haven't been blacklisted by the user selecting
// the 'Never for this site' button.
bool GetAllLogins(std::vector<PasswordForm*>* forms,
- bool include_blacklisted);
+ bool include_blacklisted) const;
//////////////////////////////////////////////////////////////////////////////
//
@@ -137,7 +138,7 @@
bool GetFormValuesForElementName(const std::wstring& name,
const std::wstring& prefix,
std::vector<std::wstring>* values,
- int limit);
+ int limit) const;
// Removes rows from autofill_dates if they were created on or after
// |delete_begin| and strictly before |delete_end|. Decrements the count of
@@ -161,11 +162,11 @@
// |element|. Sets *count to 0 if there is no such row in the table.
bool GetIDAndCountOfFormElement(const AutofillForm::Element& element,
int64* pair_id,
- int* count);
+ int* count) const;
// Gets the count only given the pair_id.
bool GetCountOfFormElement(int64 pair_id,
- int* count);
+ int* count) const;
// Updates the count entry in the row corresponding to |pair_id| to |count|.
bool SetCountOfFormElement(int64 pair_id, int count);
@@ -190,10 +191,10 @@
//////////////////////////////////////////////////////////////////////////////
bool SetWebAppImage(const GURL& url, const SkBitmap& image);
- bool GetWebAppImages(const GURL& url, std::vector<SkBitmap>* images);
+ bool GetWebAppImages(const GURL& url, std::vector<SkBitmap>* images) const;
bool SetWebAppHasAllImages(const GURL& url, bool has_all_images);
- bool GetWebAppHasAllImages(const GURL& url);
+ bool GetWebAppHasAllImages(const GURL& url) const;
bool RemoveWebApp(const GURL& url);