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

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

Issue 6903017: GTK: Add download notifications to the unity dock. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: evnam comments Created 9 years, 8 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
« no previous file with comments | « chrome/browser/ui/gtk/unity_service.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/gtk/unity_service.h"
6
7 #include <dlfcn.h>
8
9 #include "base/environment.h"
10 #include "base/scoped_ptr.h"
11 #include "chrome/browser/shell_integration.h"
12
13 // Unity data typedefs.
14 typedef struct _UnityInspector UnityInspector;
15 typedef UnityInspector* (*unity_inspector_get_default_func)(void);
16 typedef gboolean (*unity_inspector_get_unity_running_func)
17 (UnityInspector* self);
18
19 typedef struct _UnityLauncherEntry UnityLauncherEntry;
20 typedef UnityLauncherEntry* (*unity_launcher_entry_get_for_desktop_id_func)
21 (const gchar* desktop_id);
22 typedef void (*unity_launcher_entry_set_count_func)(UnityLauncherEntry* self,
23 gint64 value);
24 typedef void (*unity_launcher_entry_set_count_visible_func)
25 (UnityLauncherEntry* self, gboolean value);
26 typedef void (*unity_launcher_entry_set_progress_func)(UnityLauncherEntry* self,
27 gdouble value);
28 typedef void (*unity_launcher_entry_set_progress_visible_func)
29 (UnityLauncherEntry* self, gboolean value);
30
31
32 namespace {
33
34 bool attempted_load = false;
35
36 // Unity has a singleton object that we can ask whether the unity is running.
37 UnityInspector* inspector = NULL;
38
39 // A link to the desktop entry in the panel.
40 UnityLauncherEntry* chrome_entry = NULL;
41
42 // Retrieved functions from libunity.
43 unity_inspector_get_unity_running_func get_unity_running = NULL;
44 unity_launcher_entry_set_count_func entry_set_count = NULL;
45 unity_launcher_entry_set_count_visible_func entry_set_count_visible = NULL;
46 unity_launcher_entry_set_progress_func entry_set_progress = NULL;
47 unity_launcher_entry_set_progress_visible_func entry_set_progress_visible =
48 NULL;
49
50 void EnsureMethodsLoaded() {
51 if (attempted_load)
52 return;
53 attempted_load = true;
54
55 void* unity_lib = dlopen("libunity.so.4", RTLD_LAZY);
56 if (!unity_lib)
57 return;
58
59 unity_inspector_get_default_func inspector_get_default =
60 reinterpret_cast<unity_inspector_get_default_func>(
61 dlsym(unity_lib, "unity_inspector_get_default"));
62 if (inspector_get_default) {
63 inspector = inspector_get_default();
64
65 get_unity_running =
66 reinterpret_cast<unity_inspector_get_unity_running_func>(
67 dlsym(unity_lib, "unity_inspector_get_unity_running"));
68 }
69
70 unity_launcher_entry_get_for_desktop_id_func entry_get_for_desktop_id =
71 reinterpret_cast<unity_launcher_entry_get_for_desktop_id_func>(
72 dlsym(unity_lib, "unity_launcher_entry_get_for_desktop_id"));
73 if (entry_get_for_desktop_id) {
74 scoped_ptr<base::Environment> env(base::Environment::Create());
75 std::string desktop_id = ShellIntegration::GetDesktopName(env.get());
76 chrome_entry = entry_get_for_desktop_id(desktop_id.c_str());
77
78 entry_set_count =
79 reinterpret_cast<unity_launcher_entry_set_count_func>(
80 dlsym(unity_lib, "unity_launcher_entry_set_count"));
81
82 entry_set_count_visible =
83 reinterpret_cast<unity_launcher_entry_set_count_visible_func>(
84 dlsym(unity_lib, "unity_launcher_entry_set_count_visible"));
85
86 entry_set_progress =
87 reinterpret_cast<unity_launcher_entry_set_progress_func>(
88 dlsym(unity_lib, "unity_launcher_entry_set_progress"));
89
90 entry_set_progress_visible =
91 reinterpret_cast<unity_launcher_entry_set_progress_visible_func>(
92 dlsym(unity_lib, "unity_launcher_entry_set_progress_visible"));
93 }
94 }
95
96 } // namespace
97
98
99 namespace unity {
100
101 bool IsRunning() {
102 EnsureMethodsLoaded();
103 if (inspector && get_unity_running)
104 return get_unity_running(inspector);
105
106 return false;
107 }
108
109 void SetDownloadCount(int count) {
110 EnsureMethodsLoaded();
111 if (chrome_entry && entry_set_count && entry_set_count_visible) {
112 entry_set_count(chrome_entry, count);
113 entry_set_count_visible(chrome_entry, count != 0);
114 }
115 }
116
117 void SetProgressFraction(float percentage) {
118 EnsureMethodsLoaded();
119 if (chrome_entry && entry_set_progress && entry_set_progress_visible) {
120 entry_set_progress(chrome_entry, percentage);
121 entry_set_progress_visible(chrome_entry,
122 percentage > 0.0 && percentage < 1.0);
123 }
124 }
125
126 } // namespace unity
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/unity_service.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698