OLD | NEW |
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/ui/libgtkui/app_indicator_icon.h" | 5 #include "chrome/browser/ui/libgtkui/app_indicator_icon.h" |
6 | 6 |
7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 | 187 |
188 EnsureMethodsLoaded(); | 188 EnsureMethodsLoaded(); |
189 tool_tip_ = base::UTF16ToUTF8(tool_tip); | 189 tool_tip_ = base::UTF16ToUTF8(tool_tip); |
190 SetImage(image); | 190 SetImage(image); |
191 } | 191 } |
192 AppIndicatorIcon::~AppIndicatorIcon() { | 192 AppIndicatorIcon::~AppIndicatorIcon() { |
193 if (icon_) { | 193 if (icon_) { |
194 app_indicator_set_status(icon_, APP_INDICATOR_STATUS_PASSIVE); | 194 app_indicator_set_status(icon_, APP_INDICATOR_STATUS_PASSIVE); |
195 g_object_unref(icon_); | 195 g_object_unref(icon_); |
196 base::PostTaskWithTraits(FROM_HERE, | 196 base::PostTaskWithTraits(FROM_HERE, |
197 base::TaskTraits().MayBlock().WithPriority( | 197 {base::MayBlock(), base::TaskPriority::BACKGROUND}, |
198 base::TaskPriority::BACKGROUND), | |
199 base::BindOnce(&DeleteTempDirectory, temp_dir_)); | 198 base::BindOnce(&DeleteTempDirectory, temp_dir_)); |
200 } | 199 } |
201 } | 200 } |
202 | 201 |
203 // static | 202 // static |
204 bool AppIndicatorIcon::CouldOpen() { | 203 bool AppIndicatorIcon::CouldOpen() { |
205 EnsureMethodsLoaded(); | 204 EnsureMethodsLoaded(); |
206 return g_opened; | 205 return g_opened; |
207 } | 206 } |
208 | 207 |
209 void AppIndicatorIcon::SetImage(const gfx::ImageSkia& image) { | 208 void AppIndicatorIcon::SetImage(const gfx::ImageSkia& image) { |
210 if (!g_opened) | 209 if (!g_opened) |
211 return; | 210 return; |
212 | 211 |
213 ++icon_change_count_; | 212 ++icon_change_count_; |
214 | 213 |
215 // Copy the bitmap because it may be freed by the time it's accessed in | 214 // Copy the bitmap because it may be freed by the time it's accessed in |
216 // another thread. | 215 // another thread. |
217 SkBitmap safe_bitmap = *image.bitmap(); | 216 SkBitmap safe_bitmap = *image.bitmap(); |
218 | 217 |
219 const base::TaskTraits kTraits = | 218 const base::TaskTraits kTraits = { |
220 base::TaskTraits() | 219 base::MayBlock(), base::TaskPriority::USER_VISIBLE, |
221 .MayBlock() | 220 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN}; |
222 .WithPriority(base::TaskPriority::USER_VISIBLE) | |
223 .WithShutdownBehavior(base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN); | |
224 | 221 |
225 if (desktop_env_ == base::nix::DESKTOP_ENVIRONMENT_KDE4 || | 222 if (desktop_env_ == base::nix::DESKTOP_ENVIRONMENT_KDE4 || |
226 desktop_env_ == base::nix::DESKTOP_ENVIRONMENT_KDE5) { | 223 desktop_env_ == base::nix::DESKTOP_ENVIRONMENT_KDE5) { |
227 base::PostTaskWithTraitsAndReplyWithResult( | 224 base::PostTaskWithTraitsAndReplyWithResult( |
228 FROM_HERE, kTraits, | 225 FROM_HERE, kTraits, |
229 base::Bind(AppIndicatorIcon::WriteKDE4TempImageOnWorkerThread, | 226 base::Bind(AppIndicatorIcon::WriteKDE4TempImageOnWorkerThread, |
230 safe_bitmap, temp_dir_), | 227 safe_bitmap, temp_dir_), |
231 base::Bind(&AppIndicatorIcon::SetImageFromFile, | 228 base::Bind(&AppIndicatorIcon::SetImageFromFile, |
232 weak_factory_.GetWeakPtr())); | 229 weak_factory_.GetWeakPtr())); |
233 } else { | 230 } else { |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 params.icon_theme_path.c_str()); | 356 params.icon_theme_path.c_str()); |
360 app_indicator_set_status(icon_, APP_INDICATOR_STATUS_ACTIVE); | 357 app_indicator_set_status(icon_, APP_INDICATOR_STATUS_ACTIVE); |
361 SetMenu(); | 358 SetMenu(); |
362 } else { | 359 } else { |
363 app_indicator_set_icon_theme_path(icon_, params.icon_theme_path.c_str()); | 360 app_indicator_set_icon_theme_path(icon_, params.icon_theme_path.c_str()); |
364 app_indicator_set_icon_full(icon_, params.icon_name.c_str(), "icon"); | 361 app_indicator_set_icon_full(icon_, params.icon_name.c_str(), "icon"); |
365 } | 362 } |
366 | 363 |
367 if (temp_dir_ != params.parent_temp_dir) { | 364 if (temp_dir_ != params.parent_temp_dir) { |
368 base::PostTaskWithTraits(FROM_HERE, | 365 base::PostTaskWithTraits(FROM_HERE, |
369 base::TaskTraits().MayBlock().WithPriority( | 366 {base::MayBlock(), base::TaskPriority::BACKGROUND}, |
370 base::TaskPriority::BACKGROUND), | |
371 base::BindOnce(&DeleteTempDirectory, temp_dir_)); | 367 base::BindOnce(&DeleteTempDirectory, temp_dir_)); |
372 temp_dir_ = params.parent_temp_dir; | 368 temp_dir_ = params.parent_temp_dir; |
373 } | 369 } |
374 } | 370 } |
375 | 371 |
376 void AppIndicatorIcon::SetMenu() { | 372 void AppIndicatorIcon::SetMenu() { |
377 menu_.reset(new AppIndicatorIconMenu(menu_model_)); | 373 menu_.reset(new AppIndicatorIconMenu(menu_model_)); |
378 UpdateClickActionReplacementMenuItem(); | 374 UpdateClickActionReplacementMenuItem(); |
379 app_indicator_set_menu(icon_, menu_->GetGtkMenu()); | 375 app_indicator_set_menu(icon_, menu_->GetGtkMenu()); |
380 } | 376 } |
(...skipping 12 matching lines...) Expand all Loading... |
393 base::Bind(&AppIndicatorIcon::OnClickActionReplacementMenuItemActivated, | 389 base::Bind(&AppIndicatorIcon::OnClickActionReplacementMenuItemActivated, |
394 base::Unretained(this))); | 390 base::Unretained(this))); |
395 } | 391 } |
396 | 392 |
397 void AppIndicatorIcon::OnClickActionReplacementMenuItemActivated() { | 393 void AppIndicatorIcon::OnClickActionReplacementMenuItemActivated() { |
398 if (delegate()) | 394 if (delegate()) |
399 delegate()->OnClick(); | 395 delegate()->OnClick(); |
400 } | 396 } |
401 | 397 |
402 } // namespace libgtkui | 398 } // namespace libgtkui |
OLD | NEW |