This source file includes following definitions.
- GetMessagePrefixID
- GetProfileNameFromInfoCache
- GetTitleFromWebContents
#include "chrome/browser/task_manager/task_manager_util.h"
#include "base/basictypes.h"
#include "base/i18n/rtl.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_info_cache.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "content/public/browser/web_contents.h"
#include "grit/generated_resources.h"
namespace task_manager {
namespace util {
int GetMessagePrefixID(bool is_app,
bool is_extension,
bool is_incognito,
bool is_prerender,
bool is_background) {
if (is_app) {
if (is_background)
return IDS_TASK_MANAGER_BACKGROUND_PREFIX;
if (is_incognito)
return IDS_TASK_MANAGER_APP_INCOGNITO_PREFIX;
return IDS_TASK_MANAGER_APP_PREFIX;
}
if (is_extension) {
if (is_incognito)
return IDS_TASK_MANAGER_EXTENSION_INCOGNITO_PREFIX;
return IDS_TASK_MANAGER_EXTENSION_PREFIX;
}
if (is_prerender)
return IDS_TASK_MANAGER_PRERENDER_PREFIX;
if (is_incognito)
return IDS_TASK_MANAGER_TAB_INCOGNITO_PREFIX;
return IDS_TASK_MANAGER_TAB_PREFIX;
}
base::string16 GetProfileNameFromInfoCache(Profile* profile) {
DCHECK(profile);
ProfileInfoCache& cache =
g_browser_process->profile_manager()->GetProfileInfoCache();
size_t index = cache.GetIndexOfProfileWithPath(
profile->GetOriginalProfile()->GetPath());
if (index == std::string::npos)
return base::string16();
else
return cache.GetNameOfProfileAtIndex(index);
}
base::string16 GetTitleFromWebContents(content::WebContents* web_contents) {
DCHECK(web_contents);
base::string16 title = web_contents->GetTitle();
if (title.empty()) {
GURL url = web_contents->GetURL();
title = base::UTF8ToUTF16(url.spec());
title = base::i18n::GetDisplayStringInLTRDirectionality(title);
} else {
base::i18n::AdjustStringForLocaleDirection(&title);
}
return title;
}
}
}