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

Side by Side Diff: chrome/browser/task_manager/task_manager_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: Rebase 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/task_manager/task_manager_resource_util.h" 5 #include "chrome/browser/task_manager/task_manager_util.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/i18n/rtl.h" 8 #include "base/i18n/rtl.h"
9 #include "base/string16.h" 9 #include "base/string16.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/profiles/profile_info_cache.h" 13 #include "chrome/browser/profiles/profile_info_cache.h"
14 #include "chrome/browser/profiles/profile_manager.h" 14 #include "chrome/browser/profiles/profile_manager.h"
15 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
16 #include "grit/generated_resources.h" 16 #include "grit/generated_resources.h"
17 17
18 int TaskManagerResourceUtil::GetMessagePrefixID(bool is_app, 18 namespace task_manager {
19 bool is_extension, 19
20 bool is_incognito, 20 namespace util {
21 bool is_prerender, 21
22 bool is_instant_overlay, 22 int GetMessagePrefixID(bool is_app,
23 bool is_background) { 23 bool is_extension,
24 bool is_incognito,
25 bool is_prerender,
26 bool is_instant_overlay,
27 bool is_background) {
24 if (is_app) { 28 if (is_app) {
25 if (is_background) 29 if (is_background)
26 return IDS_TASK_MANAGER_BACKGROUND_PREFIX; 30 return IDS_TASK_MANAGER_BACKGROUND_PREFIX;
27 if (is_incognito) 31 if (is_incognito)
28 return IDS_TASK_MANAGER_APP_INCOGNITO_PREFIX; 32 return IDS_TASK_MANAGER_APP_INCOGNITO_PREFIX;
29 return IDS_TASK_MANAGER_APP_PREFIX; 33 return IDS_TASK_MANAGER_APP_PREFIX;
30 } 34 }
31 if (is_extension) { 35 if (is_extension) {
32 if (is_incognito) 36 if (is_incognito)
33 return IDS_TASK_MANAGER_EXTENSION_INCOGNITO_PREFIX; 37 return IDS_TASK_MANAGER_EXTENSION_INCOGNITO_PREFIX;
34 return IDS_TASK_MANAGER_EXTENSION_PREFIX; 38 return IDS_TASK_MANAGER_EXTENSION_PREFIX;
35 } 39 }
36 if (is_prerender) 40 if (is_prerender)
37 return IDS_TASK_MANAGER_PRERENDER_PREFIX; 41 return IDS_TASK_MANAGER_PRERENDER_PREFIX;
38 if (is_instant_overlay) 42 if (is_instant_overlay)
39 return IDS_TASK_MANAGER_INSTANT_OVERLAY_PREFIX; 43 return IDS_TASK_MANAGER_INSTANT_OVERLAY_PREFIX;
40 44
41 return IDS_TASK_MANAGER_TAB_PREFIX; 45 return IDS_TASK_MANAGER_TAB_PREFIX;
42 } 46 }
43 47
44 string16 TaskManagerResourceUtil::GetProfileNameFromInfoCache( 48 string16 GetProfileNameFromInfoCache(Profile* profile) {
45 Profile* profile) {
46 DCHECK(profile); 49 DCHECK(profile);
47 50
48 ProfileInfoCache& cache = 51 ProfileInfoCache& cache =
49 g_browser_process->profile_manager()->GetProfileInfoCache(); 52 g_browser_process->profile_manager()->GetProfileInfoCache();
50 size_t index = cache.GetIndexOfProfileWithPath( 53 size_t index = cache.GetIndexOfProfileWithPath(
51 profile->GetOriginalProfile()->GetPath()); 54 profile->GetOriginalProfile()->GetPath());
52 if (index == std::string::npos) 55 if (index == std::string::npos)
53 return string16(); 56 return string16();
54 else 57 else
55 return cache.GetNameOfProfileAtIndex(index); 58 return cache.GetNameOfProfileAtIndex(index);
56 } 59 }
57 60
58 string16 TaskManagerResourceUtil::GetTitleFromWebContents( 61 string16 GetTitleFromWebContents(content::WebContents* web_contents) {
59 content::WebContents* web_contents) {
60 DCHECK(web_contents); 62 DCHECK(web_contents);
61 63
62 string16 title = web_contents->GetTitle(); 64 string16 title = web_contents->GetTitle();
63 if (title.empty()) { 65 if (title.empty()) {
64 GURL url = web_contents->GetURL(); 66 GURL url = web_contents->GetURL();
65 title = UTF8ToUTF16(url.spec()); 67 title = UTF8ToUTF16(url.spec());
66 // Force URL to be LTR. 68 // Force URL to be LTR.
67 title = base::i18n::GetDisplayStringInLTRDirectionality(title); 69 title = base::i18n::GetDisplayStringInLTRDirectionality(title);
68 } else { 70 } else {
69 // Since the tab_title will be concatenated with 71 // Since the tab_title will be concatenated with
70 // IDS_TASK_MANAGER_TAB_PREFIX, we need to explicitly set the tab_title to 72 // IDS_TASK_MANAGER_TAB_PREFIX, we need to explicitly set the tab_title to
71 // be LTR format if there is no strong RTL charater in it. Otherwise, if 73 // be LTR format if there is no strong RTL charater in it. Otherwise, if
72 // IDS_TASK_MANAGER_TAB_PREFIX is an RTL word, the concatenated result 74 // IDS_TASK_MANAGER_TAB_PREFIX is an RTL word, the concatenated result
73 // might be wrong. For example, http://mail.yahoo.com, whose title is 75 // might be wrong. For example, http://mail.yahoo.com, whose title is
74 // "Yahoo! Mail: The best web-based Email!", without setting it explicitly 76 // "Yahoo! Mail: The best web-based Email!", without setting it explicitly
75 // as LTR format, the concatenated result will be "!Yahoo! Mail: The best 77 // as LTR format, the concatenated result will be "!Yahoo! Mail: The best
76 // web-based Email :BAT", in which the capital letters "BAT" stands for 78 // web-based Email :BAT", in which the capital letters "BAT" stands for
77 // the Hebrew word for "tab". 79 // the Hebrew word for "tab".
78 base::i18n::AdjustStringForLocaleDirection(&title); 80 base::i18n::AdjustStringForLocaleDirection(&title);
79 } 81 }
80 return title; 82 return title;
81 } 83 }
84
85 } // namespace util
86
87 } // namespace task_manager
OLDNEW
« no previous file with comments | « chrome/browser/task_manager/task_manager_util.h ('k') | chrome/browser/task_manager/task_manager_worker_resource_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698