1 // Copyright 2014 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.
5 #ifndef CHROME_BROWSER_WEB_APPLICATIONS_UPDATE_SHORTCUT_WORKER_WIN_H_
6 #define CHROME_BROWSER_WEB_APPLICATIONS_UPDATE_SHORTCUT_WORKER_WIN_H_
8 #include "chrome/browser/shell_integration.h"
9 #include "chrome/browser/web_applications/web_app.h"
10 #include "content/public/browser/notification_observer.h"
11 #include "content/public/browser/notification_registrar.h"
14 class NotificationDetails
;
15 class NotificationSource
;
21 // UpdateShortcutWorker holds all context data needed for update shortcut.
22 // It schedules a pre-update check to find all shortcuts that needs to be
23 // updated. If there are such shortcuts, it schedules icon download and
24 // update them when icons are downloaded. It observes TAB_CLOSING notification
25 // and cancels all the work when the underlying tab is closing.
26 class UpdateShortcutWorker
: public content::NotificationObserver
{
28 explicit UpdateShortcutWorker(content::WebContents
* web_contents
);
29 ~UpdateShortcutWorker() override
;
34 // Overridden from content::NotificationObserver:
35 void Observe(int type
,
36 const content::NotificationSource
& source
,
37 const content::NotificationDetails
& details
) override
;
39 // Downloads icon via the FaviconDriver.
42 // Favicon download callback.
43 void DidDownloadFavicon(
47 const GURL
& image_url
,
48 const std::vector
<SkBitmap
>& bitmaps
,
49 const std::vector
<gfx::Size
>& original_bitmap_sizes
);
51 // Checks if shortcuts exists on desktop, start menu and quick launch.
52 void CheckExistingShortcuts();
54 // Update shortcut files and icons.
55 void UpdateShortcuts();
56 void UpdateShortcutsOnFileThread();
58 // Callback after shortcuts are updated.
59 void OnShortcutsUpdated(bool);
61 // Deletes the worker on UI thread where it gets created.
63 void DeleteMeOnUIThread();
65 content::NotificationRegistrar registrar_
;
67 // Underlying WebContents whose shortcuts will be updated.
68 content::WebContents
* web_contents_
;
70 // Icons info from web_contents_'s web app data.
71 web_app::IconInfoList unprocessed_icons_
;
73 // Cached shortcut data from the web_contents_.
74 scoped_ptr
<web_app::ShortcutInfo
> shortcut_info_
;
76 // Our copy of profile path.
77 base::FilePath profile_path_
;
79 // File name of shortcut/ico file based on app title.
80 base::FilePath file_name_
;
82 // Existing shortcuts.
83 std::vector
<base::FilePath
> shortcut_files_
;
85 DISALLOW_COPY_AND_ASSIGN(UpdateShortcutWorker
);
88 } // namespace web_app
90 #endif // CHROME_BROWSER_WEB_APPLICATIONS_UPDATE_SHORTCUT_WORKER_WIN_H_