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

Side by Side Diff: chrome/browser/ui/gtk/unity_service.cc

Issue 10735034: Linux: Detect Unity as a desktop environment. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: rebase Created 8 years, 5 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/gtk/unity_service.h" 5 #include "chrome/browser/ui/gtk/unity_service.h"
6 6
7 #include <dlfcn.h> 7 #include <dlfcn.h>
8 #include <string> 8 #include <string>
9 9
10 #include "base/environment.h" 10 #include "base/environment.h"
11 #include "base/nix/xdg_util.h"
11 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
12 #include "chrome/browser/shell_integration_linux.h" 13 #include "chrome/browser/shell_integration_linux.h"
13 14
14 // Unity data typedefs. 15 // Unity data typedefs.
15 typedef struct _UnityInspector UnityInspector; 16 typedef struct _UnityInspector UnityInspector;
16 typedef UnityInspector* (*unity_inspector_get_default_func)(void); 17 typedef UnityInspector* (*unity_inspector_get_default_func)(void);
17 typedef gboolean (*unity_inspector_get_unity_running_func) 18 typedef gboolean (*unity_inspector_get_unity_running_func)
18 (UnityInspector* self); 19 (UnityInspector* self);
19 20
20 typedef struct _UnityLauncherEntry UnityLauncherEntry; 21 typedef struct _UnityLauncherEntry UnityLauncherEntry;
(...skipping 21 matching lines...) Expand all
42 43
43 // Retrieved functions from libunity. 44 // Retrieved functions from libunity.
44 unity_inspector_get_unity_running_func get_unity_running = NULL; 45 unity_inspector_get_unity_running_func get_unity_running = NULL;
45 unity_launcher_entry_set_count_func entry_set_count = NULL; 46 unity_launcher_entry_set_count_func entry_set_count = NULL;
46 unity_launcher_entry_set_count_visible_func entry_set_count_visible = NULL; 47 unity_launcher_entry_set_count_visible_func entry_set_count_visible = NULL;
47 unity_launcher_entry_set_progress_func entry_set_progress = NULL; 48 unity_launcher_entry_set_progress_func entry_set_progress = NULL;
48 unity_launcher_entry_set_progress_visible_func entry_set_progress_visible = 49 unity_launcher_entry_set_progress_visible_func entry_set_progress_visible =
49 NULL; 50 NULL;
50 51
51 void EnsureMethodsLoaded() { 52 void EnsureMethodsLoaded() {
53 using base::nix::GetDesktopEnvironment;
54
52 if (attempted_load) 55 if (attempted_load)
53 return; 56 return;
54 attempted_load = true; 57 attempted_load = true;
55 58
59 scoped_ptr<base::Environment> env(base::Environment::Create());
60 if (GetDesktopEnvironment(env.get()) != base::nix::DESKTOP_ENVIRONMENT_UNITY)
61 return;
62
56 // TODO(erg): When unity stabilizes its interface, switch all this to looking 63 // TODO(erg): When unity stabilizes its interface, switch all this to looking
57 // up just ".so" instead of specific versions. 64 // up just ".so" instead of specific versions.
58 void* unity_lib = dlopen("libunity.so.4", RTLD_LAZY); 65 void* unity_lib = dlopen("libunity.so.4", RTLD_LAZY);
59 if (!unity_lib) 66 if (!unity_lib)
60 unity_lib = dlopen("libunity.so.6", RTLD_LAZY); 67 unity_lib = dlopen("libunity.so.6", RTLD_LAZY);
61 if (!unity_lib) 68 if (!unity_lib)
62 unity_lib = dlopen("libunity.so.9", RTLD_LAZY); 69 unity_lib = dlopen("libunity.so.9", RTLD_LAZY);
63 if (!unity_lib) 70 if (!unity_lib)
64 return; 71 return;
65 72
66 unity_inspector_get_default_func inspector_get_default = 73 unity_inspector_get_default_func inspector_get_default =
67 reinterpret_cast<unity_inspector_get_default_func>( 74 reinterpret_cast<unity_inspector_get_default_func>(
68 dlsym(unity_lib, "unity_inspector_get_default")); 75 dlsym(unity_lib, "unity_inspector_get_default"));
69 if (inspector_get_default) { 76 if (inspector_get_default) {
70 inspector = inspector_get_default(); 77 inspector = inspector_get_default();
71 78
72 get_unity_running = 79 get_unity_running =
73 reinterpret_cast<unity_inspector_get_unity_running_func>( 80 reinterpret_cast<unity_inspector_get_unity_running_func>(
74 dlsym(unity_lib, "unity_inspector_get_unity_running")); 81 dlsym(unity_lib, "unity_inspector_get_unity_running"));
75 } 82 }
76 83
77 unity_launcher_entry_get_for_desktop_id_func entry_get_for_desktop_id = 84 unity_launcher_entry_get_for_desktop_id_func entry_get_for_desktop_id =
78 reinterpret_cast<unity_launcher_entry_get_for_desktop_id_func>( 85 reinterpret_cast<unity_launcher_entry_get_for_desktop_id_func>(
79 dlsym(unity_lib, "unity_launcher_entry_get_for_desktop_id")); 86 dlsym(unity_lib, "unity_launcher_entry_get_for_desktop_id"));
80 if (entry_get_for_desktop_id) { 87 if (entry_get_for_desktop_id) {
81 scoped_ptr<base::Environment> env(base::Environment::Create());
82 std::string desktop_id = ShellIntegrationLinux::GetDesktopName(env.get()); 88 std::string desktop_id = ShellIntegrationLinux::GetDesktopName(env.get());
83 chrome_entry = entry_get_for_desktop_id(desktop_id.c_str()); 89 chrome_entry = entry_get_for_desktop_id(desktop_id.c_str());
84 90
85 entry_set_count = 91 entry_set_count =
86 reinterpret_cast<unity_launcher_entry_set_count_func>( 92 reinterpret_cast<unity_launcher_entry_set_count_func>(
87 dlsym(unity_lib, "unity_launcher_entry_set_count")); 93 dlsym(unity_lib, "unity_launcher_entry_set_count"));
88 94
89 entry_set_count_visible = 95 entry_set_count_visible =
90 reinterpret_cast<unity_launcher_entry_set_count_visible_func>( 96 reinterpret_cast<unity_launcher_entry_set_count_visible_func>(
91 dlsym(unity_lib, "unity_launcher_entry_set_count_visible")); 97 dlsym(unity_lib, "unity_launcher_entry_set_count_visible"));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 void SetProgressFraction(float percentage) { 130 void SetProgressFraction(float percentage) {
125 EnsureMethodsLoaded(); 131 EnsureMethodsLoaded();
126 if (chrome_entry && entry_set_progress && entry_set_progress_visible) { 132 if (chrome_entry && entry_set_progress && entry_set_progress_visible) {
127 entry_set_progress(chrome_entry, percentage); 133 entry_set_progress(chrome_entry, percentage);
128 entry_set_progress_visible(chrome_entry, 134 entry_set_progress_visible(chrome_entry,
129 percentage > 0.0 && percentage < 1.0); 135 percentage > 0.0 && percentage < 1.0);
130 } 136 }
131 } 137 }
132 138
133 } // namespace unity 139 } // namespace unity
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/gtk_theme_service.cc ('k') | chrome/browser/ui/webui/options2/advanced_options_utils_x11.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698