| OLD | NEW | 
|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/web_applications/web_app_ui.h" | 5 #include "chrome/browser/ui/web_applications/web_app_ui.h" | 
| 6 | 6 | 
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" | 
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" | 
| 9 #include "base/task.h" | 9 #include "base/task.h" | 
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" | 
| (...skipping 26 matching lines...) Expand all  Loading... | 
| 37 // update them when icons are downloaded. It observes TAB_CLOSING notification | 37 // update them when icons are downloaded. It observes TAB_CLOSING notification | 
| 38 // and cancels all the work when the underlying tab is closing. | 38 // and cancels all the work when the underlying tab is closing. | 
| 39 class UpdateShortcutWorker : public NotificationObserver { | 39 class UpdateShortcutWorker : public NotificationObserver { | 
| 40  public: | 40  public: | 
| 41   explicit UpdateShortcutWorker(TabContentsWrapper* tab_contents); | 41   explicit UpdateShortcutWorker(TabContentsWrapper* tab_contents); | 
| 42 | 42 | 
| 43   void Run(); | 43   void Run(); | 
| 44 | 44 | 
| 45  private: | 45  private: | 
| 46   // Overridden from NotificationObserver: | 46   // Overridden from NotificationObserver: | 
| 47   virtual void Observe(NotificationType type, | 47   virtual void Observe(int type, | 
| 48                        const NotificationSource& source, | 48                        const NotificationSource& source, | 
| 49                        const NotificationDetails& details); | 49                        const NotificationDetails& details); | 
| 50 | 50 | 
| 51   // Downloads icon via TabContents. | 51   // Downloads icon via TabContents. | 
| 52   void DownloadIcon(); | 52   void DownloadIcon(); | 
| 53 | 53 | 
| 54   // Callback when icon downloaded. | 54   // Callback when icon downloaded. | 
| 55   void OnIconDownloaded(int download_id, bool errored, const SkBitmap& image); | 55   void OnIconDownloaded(int download_id, bool errored, const SkBitmap& image); | 
| 56 | 56 | 
| 57   // Checks if shortcuts exists on desktop, start menu and quick launch. | 57   // Checks if shortcuts exists on desktop, start menu and quick launch. | 
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 92 }; | 92 }; | 
| 93 | 93 | 
| 94 UpdateShortcutWorker::UpdateShortcutWorker(TabContentsWrapper* tab_contents) | 94 UpdateShortcutWorker::UpdateShortcutWorker(TabContentsWrapper* tab_contents) | 
| 95     : tab_contents_(tab_contents), | 95     : tab_contents_(tab_contents), | 
| 96       profile_path_(tab_contents->profile()->GetPath()) { | 96       profile_path_(tab_contents->profile()->GetPath()) { | 
| 97   web_app::GetShortcutInfoForTab(tab_contents_, &shortcut_info_); | 97   web_app::GetShortcutInfoForTab(tab_contents_, &shortcut_info_); | 
| 98   web_app::GetIconsInfo(tab_contents_->extension_tab_helper()->web_app_info(), | 98   web_app::GetIconsInfo(tab_contents_->extension_tab_helper()->web_app_info(), | 
| 99                         &unprocessed_icons_); | 99                         &unprocessed_icons_); | 
| 100   file_name_ = web_app::internals::GetSanitizedFileName(shortcut_info_.title); | 100   file_name_ = web_app::internals::GetSanitizedFileName(shortcut_info_.title); | 
| 101 | 101 | 
| 102   registrar_.Add(this, NotificationType::TAB_CLOSING, | 102   registrar_.Add(this, content::NOTIFICATION_TAB_CLOSING, | 
| 103                  Source<NavigationController>(&tab_contents_->controller())); | 103                  Source<NavigationController>(&tab_contents_->controller())); | 
| 104 } | 104 } | 
| 105 | 105 | 
| 106 void UpdateShortcutWorker::Run() { | 106 void UpdateShortcutWorker::Run() { | 
| 107   // Starting by downloading app icon. | 107   // Starting by downloading app icon. | 
| 108   DownloadIcon(); | 108   DownloadIcon(); | 
| 109 } | 109 } | 
| 110 | 110 | 
| 111 void UpdateShortcutWorker::Observe(NotificationType type, | 111 void UpdateShortcutWorker::Observe(int type, | 
| 112                                    const NotificationSource& source, | 112                                    const NotificationSource& source, | 
| 113                                    const NotificationDetails& details) { | 113                                    const NotificationDetails& details) { | 
| 114   if (type == NotificationType::TAB_CLOSING && | 114   if (type == content::NOTIFICATION_TAB_CLOSING && | 
| 115       Source<NavigationController>(source).ptr() == | 115       Source<NavigationController>(source).ptr() == | 
| 116         &tab_contents_->controller()) { | 116         &tab_contents_->controller()) { | 
| 117     // Underlying tab is closing. | 117     // Underlying tab is closing. | 
| 118     tab_contents_ = NULL; | 118     tab_contents_ = NULL; | 
| 119   } | 119   } | 
| 120 } | 120 } | 
| 121 | 121 | 
| 122 void UpdateShortcutWorker::DownloadIcon() { | 122 void UpdateShortcutWorker::DownloadIcon() { | 
| 123   // FetchIcon must run on UI thread because it relies on TabContents | 123   // FetchIcon must run on UI thread because it relies on TabContents | 
| 124   // to download the icon. | 124   // to download the icon. | 
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 311 | 311 | 
| 312 void UpdateShortcutForTabContents(TabContentsWrapper* tab_contents) { | 312 void UpdateShortcutForTabContents(TabContentsWrapper* tab_contents) { | 
| 313 #if defined(OS_WIN) | 313 #if defined(OS_WIN) | 
| 314   // UpdateShortcutWorker will delete itself when it's done. | 314   // UpdateShortcutWorker will delete itself when it's done. | 
| 315   UpdateShortcutWorker* worker = new UpdateShortcutWorker(tab_contents); | 315   UpdateShortcutWorker* worker = new UpdateShortcutWorker(tab_contents); | 
| 316   worker->Run(); | 316   worker->Run(); | 
| 317 #endif  // defined(OS_WIN) | 317 #endif  // defined(OS_WIN) | 
| 318 } | 318 } | 
| 319 | 319 | 
| 320 }  // namespace web_app | 320 }  // namespace web_app | 
| OLD | NEW | 
|---|