Chromium Code Reviews| Index: chrome/browser/ui/gtk/unity_dock_service.cc |
| diff --git a/chrome/browser/ui/gtk/unity_dock_service.cc b/chrome/browser/ui/gtk/unity_dock_service.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ec80f13465d6f71f6ad49e61421923a4198854d4 |
| --- /dev/null |
| +++ b/chrome/browser/ui/gtk/unity_dock_service.cc |
| @@ -0,0 +1,81 @@ |
| +// 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_dock_service.h" |
| + |
| +#include <dlfcn.h> |
| + |
| +#include "base/environment.h" |
| +#include "base/scoped_ptr.h" |
| +#include "chrome/browser/shell_integration.h" |
| + |
| +void UnityDockService::SetDownloadCount(int count) { |
| + if (chrome_entry) { |
| + entry_set_count(chrome_entry, count); |
| + entry_set_count_visible(chrome_entry, count != 0); |
| + } |
| +} |
| + |
| +void UnityDockService::SetProgressPercent(float percentage) { |
| + if (chrome_entry) { |
| + entry_set_progress(chrome_entry, percentage); |
| + entry_set_progress_visible(chrome_entry, |
| + percentage > 0.0 && percentage < 1.0); |
| + } |
| +} |
| + |
| +UnityDockService::UnityDockService() {} |
| + |
| +UnityDockService::~UnityDockService() {} |
| + |
| +// static |
| +DockService* UnityDockService::Build() { |
| + UnityDockService* service = NULL; |
| + void* unity_lib = dlopen("libunity.so.4", RTLD_LAZY); |
| + if (unity_lib) { |
|
Evan Martin
2011/04/26 00:33:52
Why not early return here rather than nesting so m
|
| + 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()); |
| + UnityLauncherEntry* entry = entry_get_for_desktop_id(desktop_id.c_str()); |
| + |
| + unity_launcher_entry_set_count_func entry_set_count = |
| + reinterpret_cast<unity_launcher_entry_set_count_func>( |
| + dlsym(unity_lib, "unity_launcher_entry_set_count")); |
| + |
| + unity_launcher_entry_set_count_visible_func entry_set_count_visible = |
| + reinterpret_cast<unity_launcher_entry_set_count_visible_func>( |
| + dlsym(unity_lib, "unity_launcher_entry_set_count_visible")); |
| + |
| + unity_launcher_entry_set_progress_func entry_set_progress = |
| + reinterpret_cast<unity_launcher_entry_set_progress_func>( |
| + dlsym(unity_lib, "unity_launcher_entry_set_progress")); |
| + |
| + unity_launcher_entry_set_progress_visible_func |
| + entry_set_progress_visible = |
| + reinterpret_cast<unity_launcher_entry_set_progress_visible_func>( |
| + dlsym(unity_lib, "unity_launcher_entry_set_progress_visible")); |
| + |
| + // Check every returned method because the API is unstable. |
| + if (entry && |
| + entry_set_count && |
| + entry_set_count_visible && |
| + entry_set_progress && |
| + entry_set_progress_visible) { |
| + service = new UnityDockService; |
| + service->chrome_entry = entry; |
| + service->entry_set_count = entry_set_count; |
| + service->entry_set_count_visible = entry_set_count_visible; |
| + service->entry_set_progress = entry_set_progress; |
| + service->entry_set_progress_visible = entry_set_progress_visible; |
| + } |
| + } |
| + } |
| + |
| + return service; |
| +} |
| + |