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

Unified 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: Actually commit before sending out 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/gtk/unity_service.cc
diff --git a/chrome/browser/ui/gtk/unity_service.cc b/chrome/browser/ui/gtk/unity_service.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6745426caa397ed3bfacf9563292ca603f06d0fe
--- /dev/null
+++ b/chrome/browser/ui/gtk/unity_service.cc
@@ -0,0 +1,125 @@
+// Copyright (c) 2011 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/ui/gtk/unity_service.h"
+
+#include <dlfcn.h>
+
+#include "base/environment.h"
+#include "base/scoped_ptr.h"
+#include "chrome/browser/shell_integration.h"
+
+// Unity data typedefs.
+typedef struct _UnityInspector UnityInspector;
+typedef UnityInspector* (*unity_inspector_get_default_func)(void);
+typedef gboolean (*unity_inspector_get_unity_running_func)
+ (UnityInspector* self);
+
+typedef struct _UnityLauncherEntry UnityLauncherEntry;
+typedef UnityLauncherEntry* (*unity_launcher_entry_get_for_desktop_id_func)
+ (const gchar* desktop_id);
+typedef void (*unity_launcher_entry_set_count_func)(UnityLauncherEntry* self,
+ gint64 value);
+typedef void (*unity_launcher_entry_set_count_visible_func)
+ (UnityLauncherEntry* self, gboolean value);
+typedef void (*unity_launcher_entry_set_progress_func)(UnityLauncherEntry* self,
+ gdouble value);
+typedef void (*unity_launcher_entry_set_progress_visible_func)
+ (UnityLauncherEntry* self, gboolean value);
+
+
+namespace {
+
+bool attempted_load = false;
+
+// Unity has a singleton object that we can ask whether the unity is running.
+UnityInspector* inspector = NULL;
+
+// A link to the desktop entry in the panel.
+UnityLauncherEntry* chrome_entry = NULL;
+
+// Retrieved functions from libunity.
+unity_inspector_get_unity_running_func get_unity_running = NULL;
+unity_launcher_entry_set_count_func entry_set_count = NULL;
+unity_launcher_entry_set_count_visible_func entry_set_count_visible = NULL;
+unity_launcher_entry_set_progress_func entry_set_progress = NULL;
+unity_launcher_entry_set_progress_visible_func entry_set_progress_visible =
+ NULL;
+
+void EnsureMethodsLoaded() {
+ if (!attempted_load) {
Evan Martin 2011/04/26 21:33:04 Can early-exit this function rather than doing the
+ void* unity_lib = dlopen("libunity.so.4", RTLD_LAZY);
+ if (unity_lib) {
Evan Martin 2011/04/26 21:33:04 Here too (if you set attempted_load=true) earlier.
+ unity_inspector_get_default_func inspector_get_default =
+ reinterpret_cast<unity_inspector_get_default_func>(
+ dlsym(unity_lib, "unity_inspector_get_default"));
+ if (inspector_get_default) {
+ inspector = inspector_get_default();
+
+ get_unity_running =
+ reinterpret_cast<unity_inspector_get_unity_running_func>(
+ dlsym(unity_lib, "unity_inspector_get_unity_running"));
+ }
+
+ unity_launcher_entry_get_for_desktop_id_func entry_get_for_desktop_id =
+ reinterpret_cast<unity_launcher_entry_get_for_desktop_id_func>(
+ dlsym(unity_lib, "unity_launcher_entry_get_for_desktop_id"));
+
+ if (entry_get_for_desktop_id) {
+ scoped_ptr<base::Environment> env(base::Environment::Create());
+ std::string desktop_id = ShellIntegration::GetDesktopName(env.get());
+ chrome_entry = entry_get_for_desktop_id(desktop_id.c_str());
+
+ entry_set_count =
+ reinterpret_cast<unity_launcher_entry_set_count_func>(
+ dlsym(unity_lib, "unity_launcher_entry_set_count"));
+
+ entry_set_count_visible =
+ reinterpret_cast<unity_launcher_entry_set_count_visible_func>(
+ dlsym(unity_lib, "unity_launcher_entry_set_count_visible"));
+
+ entry_set_progress =
+ reinterpret_cast<unity_launcher_entry_set_progress_func>(
+ dlsym(unity_lib, "unity_launcher_entry_set_progress"));
+
+ entry_set_progress_visible =
+ reinterpret_cast<unity_launcher_entry_set_progress_visible_func>(
+ dlsym(unity_lib, "unity_launcher_entry_set_progress_visible"));
+ }
+ }
+ attempted_load = true;
+ }
+}
+
+} // namespace
+
+
+namespace unity {
+
+bool IsRunning() {
+ EnsureMethodsLoaded();
+ if (inspector && get_unity_running)
+ return get_unity_running(inspector);
Evan Martin 2011/04/26 21:33:04 I'm concerned this is going to take a while, like
Elliot Glaysher 2011/04/26 21:44:40 libunity reads a boolean. It modifies the boolean
+
+ return false;
+}
+
+void SetDownloadCount(int count) {
+ EnsureMethodsLoaded();
+ if (chrome_entry && entry_set_count && entry_set_count_visible) {
+ entry_set_count(chrome_entry, count);
+ entry_set_count_visible(chrome_entry, count != 0);
+ }
+}
+
+void SetProgressPercent(float percentage) {
+ EnsureMethodsLoaded();
+ if (chrome_entry && entry_set_progress && entry_set_progress_visible) {
+ entry_set_progress(chrome_entry, percentage);
+ entry_set_progress_visible(chrome_entry,
+ percentage > 0.0 && percentage < 1.0);
+ }
+}
+
+} // namespace unity

Powered by Google App Engine
This is Rietveld 408576698