| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/apps/drive/drive_app_converter.h" | 5 #include "chrome/browser/apps/drive/drive_app_converter.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 IconFetcher* fetcher = new IconFetcher(this, icon_url, icon_size); | 143 IconFetcher* fetcher = new IconFetcher(this, icon_url, icon_size); |
| 144 fetchers_.push_back(fetcher); // Pass ownership to |fetchers|. | 144 fetchers_.push_back(fetcher); // Pass ownership to |fetchers|. |
| 145 fetcher->Start(); | 145 fetcher->Start(); |
| 146 } | 146 } |
| 147 | 147 |
| 148 if (fetchers_.empty()) | 148 if (fetchers_.empty()) |
| 149 StartInstall(); | 149 StartInstall(); |
| 150 } | 150 } |
| 151 | 151 |
| 152 bool DriveAppConverter::IsStarted() const { | 152 bool DriveAppConverter::IsStarted() const { |
| 153 return !fetchers_.empty() || crx_installer_; | 153 return !fetchers_.empty() || crx_installer_.get(); |
| 154 } | 154 } |
| 155 | 155 |
| 156 bool DriveAppConverter::IsInstalling(const std::string& app_id) const { | 156 bool DriveAppConverter::IsInstalling(const std::string& app_id) const { |
| 157 return crx_installer_ && crx_installer_->extension() && | 157 return crx_installer_.get() && crx_installer_->extension() && |
| 158 crx_installer_->extension()->id() == app_id; | 158 crx_installer_->extension()->id() == app_id; |
| 159 } | 159 } |
| 160 | 160 |
| 161 void DriveAppConverter::OnIconFetchComplete(const IconFetcher* fetcher) { | 161 void DriveAppConverter::OnIconFetchComplete(const IconFetcher* fetcher) { |
| 162 const SkBitmap& icon = fetcher->icon(); | 162 const SkBitmap& icon = fetcher->icon(); |
| 163 if (!icon.empty() && icon.width() != 0) { | 163 if (!icon.empty() && icon.width() != 0) { |
| 164 WebApplicationInfo::IconInfo icon_info; | 164 WebApplicationInfo::IconInfo icon_info; |
| 165 icon_info.url = fetcher->icon_url(); | 165 icon_info.url = fetcher->icon_url(); |
| 166 icon_info.data = icon; | 166 icon_info.data = icon; |
| 167 icon_info.width = icon.width(); | 167 icon_info.width = icon.width(); |
| 168 icon_info.height = icon.height(); | 168 icon_info.height = icon.height(); |
| 169 web_app_.icons.push_back(icon_info); | 169 web_app_.icons.push_back(icon_info); |
| 170 } | 170 } |
| 171 | 171 |
| 172 fetchers_.erase(std::find(fetchers_.begin(), fetchers_.end(), fetcher)); | 172 fetchers_.erase(std::find(fetchers_.begin(), fetchers_.end(), fetcher)); |
| 173 | 173 |
| 174 if (fetchers_.empty()) | 174 if (fetchers_.empty()) |
| 175 StartInstall(); | 175 StartInstall(); |
| 176 } | 176 } |
| 177 | 177 |
| 178 void DriveAppConverter::StartInstall() { | 178 void DriveAppConverter::StartInstall() { |
| 179 DCHECK(!crx_installer_); | 179 DCHECK(!crx_installer_.get()); |
| 180 crx_installer_ = extensions::CrxInstaller::CreateSilent( | 180 crx_installer_ = extensions::CrxInstaller::CreateSilent( |
| 181 extensions::ExtensionSystem::Get(profile_)->extension_service()); | 181 extensions::ExtensionSystem::Get(profile_)->extension_service()); |
| 182 // The converted url app should not be syncable. Drive apps go with the user's | 182 // The converted url app should not be syncable. Drive apps go with the user's |
| 183 // account and url apps will be created when needed. Syncing those apps could | 183 // account and url apps will be created when needed. Syncing those apps could |
| 184 // hit an edge case where the synced url apps become orphans when the user has | 184 // hit an edge case where the synced url apps become orphans when the user has |
| 185 // corresponding chrome apps. | 185 // corresponding chrome apps. |
| 186 crx_installer_->set_do_not_sync(true); | 186 crx_installer_->set_do_not_sync(true); |
| 187 | 187 |
| 188 extensions::InstallTracker::Get(profile_)->AddObserver(this); | 188 extensions::InstallTracker::Get(profile_)->AddObserver(this); |
| 189 crx_installer_->InstallWebApp(web_app_); | 189 crx_installer_->InstallWebApp(web_app_); |
| 190 } | 190 } |
| 191 | 191 |
| 192 void DriveAppConverter::PostInstallCleanUp() { | 192 void DriveAppConverter::PostInstallCleanUp() { |
| 193 if (!crx_installer_) | 193 if (!crx_installer_.get()) |
| 194 return; | 194 return; |
| 195 | 195 |
| 196 extensions::InstallTracker::Get(profile_)->RemoveObserver(this); | 196 extensions::InstallTracker::Get(profile_)->RemoveObserver(this); |
| 197 crx_installer_ = NULL; | 197 crx_installer_ = NULL; |
| 198 } | 198 } |
| 199 | 199 |
| 200 void DriveAppConverter::OnFinishCrxInstall(const std::string& extension_id, | 200 void DriveAppConverter::OnFinishCrxInstall(const std::string& extension_id, |
| 201 bool success) { | 201 bool success) { |
| 202 if (!crx_installer_->extension() || | 202 if (!crx_installer_->extension() || |
| 203 crx_installer_->extension()->id() != extension_id) { | 203 crx_installer_->extension()->id() != extension_id) { |
| 204 return; | 204 return; |
| 205 } | 205 } |
| 206 | 206 |
| 207 extension_ = crx_installer_->extension(); | 207 extension_ = crx_installer_->extension(); |
| 208 is_new_install_ = success && crx_installer_->current_version().empty(); | 208 is_new_install_ = success && crx_installer_->current_version().empty(); |
| 209 PostInstallCleanUp(); | 209 PostInstallCleanUp(); |
| 210 | 210 |
| 211 finished_callback_.Run(this, success); | 211 finished_callback_.Run(this, success); |
| 212 // |finished_callback_| could delete this. | 212 // |finished_callback_| could delete this. |
| 213 } | 213 } |
| OLD | NEW |