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

Side by Side Diff: chrome/browser/extensions/app_shortcut_manager.cc

Issue 10698114: Remove app shortcuts when app is uninstalled on Linux. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Mac fix 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
« no previous file with comments | « no previous file | chrome/browser/shell_integration_linux.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/extensions/app_shortcut_manager.h" 5 #include "chrome/browser/extensions/app_shortcut_manager.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/web_applications/web_app.h" 10 #include "chrome/browser/web_applications/web_app.h"
(...skipping 18 matching lines...) Expand all
29 #else 29 #else
30 const int kDesiredSizes[] = {32}; 30 const int kDesiredSizes[] = {32};
31 #endif 31 #endif
32 } // namespace 32 } // namespace
33 33
34 AppShortcutManager::AppShortcutManager(Profile* profile) 34 AppShortcutManager::AppShortcutManager(Profile* profile)
35 : profile_(profile), 35 : profile_(profile),
36 tracker_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 36 tracker_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
37 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, 37 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED,
38 content::Source<Profile>(profile_)); 38 content::Source<Profile>(profile_));
39 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
40 content::Source<Profile>(profile_));
39 } 41 }
40 42
41 void AppShortcutManager::OnImageLoaded(const gfx::Image& image, 43 void AppShortcutManager::OnImageLoaded(const gfx::Image& image,
42 const std::string& extension_id, 44 const std::string& extension_id,
43 int index) { 45 int index) {
44 // If the image failed to load (e.g. if the resource being loaded was empty) 46 // If the image failed to load (e.g. if the resource being loaded was empty)
45 // use the standard application icon. 47 // use the standard application icon.
46 if (image.IsEmpty()) { 48 if (image.IsEmpty()) {
47 gfx::Image default_icon = 49 gfx::Image default_icon =
48 ResourceBundle::GetSharedInstance().GetImageNamed(IDR_APP_DEFAULT_ICON); 50 ResourceBundle::GetSharedInstance().GetImageNamed(IDR_APP_DEFAULT_ICON);
49 int size = kDesiredSizes[arraysize(kDesiredSizes) - 1]; 51 int size = kDesiredSizes[arraysize(kDesiredSizes) - 1];
50 SkBitmap bmp = skia::ImageOperations::Resize( 52 SkBitmap bmp = skia::ImageOperations::Resize(
51 *default_icon.ToSkBitmap(), skia::ImageOperations::RESIZE_BEST, 53 *default_icon.ToSkBitmap(), skia::ImageOperations::RESIZE_BEST,
52 size, size); 54 size, size);
53 shortcut_info_.favicon = gfx::Image(bmp); 55 shortcut_info_.favicon = gfx::Image(bmp);
54 } else { 56 } else {
55 shortcut_info_.favicon = image; 57 shortcut_info_.favicon = image;
56 } 58 }
57 59
58 web_app::CreateShortcut(profile_->GetPath(), shortcut_info_); 60 web_app::CreateShortcut(profile_->GetPath(), shortcut_info_);
59 } 61 }
60 62
61 void AppShortcutManager::Observe(int type, 63 void AppShortcutManager::Observe(int type,
62 const content::NotificationSource& source, 64 const content::NotificationSource& source,
63 const content::NotificationDetails& details) { 65 const content::NotificationDetails& details) {
64 DCHECK(type == chrome::NOTIFICATION_EXTENSION_INSTALLED); 66 #if !defined(OS_MACOSX)
65 #if !defined(OS_MACOSX) 67 switch (type) {
66 const Extension* extension = content::Details<const Extension>( 68 case chrome::NOTIFICATION_EXTENSION_INSTALLED: {
67 details).ptr(); 69 const Extension* extension = content::Details<const Extension>(
68 if (!disable_shortcut_creation_for_tests && 70 details).ptr();
69 extension->is_platform_app() && 71 if (!disable_shortcut_creation_for_tests &&
70 extension->location() != Extension::LOAD) 72 extension->is_platform_app() &&
71 InstallApplicationShortcuts(extension); 73 extension->location() != Extension::LOAD) {
72 #endif 74 InstallApplicationShortcuts(extension);
75 }
76 break;
77 }
78 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: {
79 std::string extension_id = *content::Details<std::string>(details).ptr();
80 if (!disable_shortcut_creation_for_tests)
81 web_app::DeleteAllShortcuts(profile_->GetPath(), extension_id);
82 break;
83 }
84 default:
85 NOTREACHED();
86 }
87 #endif
73 } 88 }
74 89
75 // static 90 // static
76 void AppShortcutManager::SetShortcutCreationDisabledForTesting(bool disabled) { 91 void AppShortcutManager::SetShortcutCreationDisabledForTesting(bool disabled) {
77 disable_shortcut_creation_for_tests = disabled; 92 disable_shortcut_creation_for_tests = disabled;
78 } 93 }
79 94
80 void AppShortcutManager::InstallApplicationShortcuts( 95 void AppShortcutManager::InstallApplicationShortcuts(
81 const Extension* extension) { 96 const Extension* extension) {
82 shortcut_info_.extension_id = extension->id(); 97 shortcut_info_.extension_id = extension->id();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 } 131 }
117 info_list.push_back( 132 info_list.push_back(
118 ImageLoadingTracker::ImageInfo(resource, gfx::Size(size, size))); 133 ImageLoadingTracker::ImageInfo(resource, gfx::Size(size, size)));
119 } 134 }
120 135
121 // |icon_resources| may still be empty at this point, in which case LoadImage 136 // |icon_resources| may still be empty at this point, in which case LoadImage
122 // will call the OnImageLoaded callback with an empty image and exit 137 // will call the OnImageLoaded callback with an empty image and exit
123 // immediately. 138 // immediately.
124 tracker_.LoadImages(extension, info_list, ImageLoadingTracker::DONT_CACHE); 139 tracker_.LoadImages(extension, info_list, ImageLoadingTracker::DONT_CACHE);
125 } 140 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/shell_integration_linux.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698