Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(392)

Unified Diff: chrome/browser/task_manager/resource_util.cc

Issue 15196003: Create task_manager namespace and wrap classes related to TaskManager with it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: RendererResource Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/task_manager/resource_util.cc
diff --git a/chrome/browser/task_manager/resource_util.cc b/chrome/browser/task_manager/resource_util.cc
new file mode 100644
index 0000000000000000000000000000000000000000..785d2429fb7848e7c697da78c8ce28a53ec0f2df
--- /dev/null
+++ b/chrome/browser/task_manager/resource_util.cc
@@ -0,0 +1,85 @@
+// 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/task_manager/resource_util.h"
+
+#include "base/basictypes.h"
+#include "base/i18n/rtl.h"
+#include "base/string16.h"
+#include "base/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 {
+
+int ResourceUtil::GetMessagePrefixID(bool is_app,
+ bool is_extension,
+ bool is_incognito,
+ bool is_prerender,
+ bool is_instant_overlay,
+ 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_instant_overlay)
+ return IDS_TASK_MANAGER_INSTANT_OVERLAY_PREFIX;
+
+ return IDS_TASK_MANAGER_TAB_PREFIX;
+}
+
+string16 ResourceUtil::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 string16();
+ else
+ return cache.GetNameOfProfileAtIndex(index);
+}
+
+string16 ResourceUtil::GetTitleFromWebContents(
+ content::WebContents* web_contents) {
+ DCHECK(web_contents);
+
+ string16 title = web_contents->GetTitle();
+ if (title.empty()) {
+ GURL url = web_contents->GetURL();
+ title = UTF8ToUTF16(url.spec());
+ // Force URL to be LTR.
+ title = base::i18n::GetDisplayStringInLTRDirectionality(title);
+ } else {
+ // Since the tab_title will be concatenated with
+ // IDS_TASK_MANAGER_TAB_PREFIX, we need to explicitly set the tab_title to
+ // be LTR format if there is no strong RTL charater in it. Otherwise, if
+ // IDS_TASK_MANAGER_TAB_PREFIX is an RTL word, the concatenated result
+ // might be wrong. For example, http://mail.yahoo.com, whose title is
+ // "Yahoo! Mail: The best web-based Email!", without setting it explicitly
+ // as LTR format, the concatenated result will be "!Yahoo! Mail: The best
+ // web-based Email :BAT", in which the capital letters "BAT" stands for
+ // the Hebrew word for "tab".
+ base::i18n::AdjustStringForLocaleDirection(&title);
+ }
+ return title;
+}
+
+} // namespace task_manager

Powered by Google App Engine
This is Rietveld 408576698