| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ptr_util.h" |
| 15 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 17 #include "chrome/browser/extensions/crx_installer.h" | 18 #include "chrome/browser/extensions/crx_installer.h" |
| 18 #include "chrome/browser/extensions/install_tracker.h" | 19 #include "chrome/browser/extensions/install_tracker.h" |
| 19 #include "chrome/browser/image_decoder.h" | 20 #include "chrome/browser/image_decoder.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 21 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 22 #include "extensions/browser/extension_system.h" | 23 #include "extensions/browser/extension_system.h" |
| 23 #include "extensions/common/constants.h" | 24 #include "extensions/common/constants.h" |
| 24 #include "net/base/load_flags.h" | 25 #include "net/base/load_flags.h" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 web_app_.app_url = drive_app_info_.create_url; | 147 web_app_.app_url = drive_app_info_.create_url; |
| 147 | 148 |
| 148 std::set<int> pending_sizes; | 149 std::set<int> pending_sizes; |
| 149 for (size_t i = 0; i < drive_app_info_.app_icons.size(); ++i) { | 150 for (size_t i = 0; i < drive_app_info_.app_icons.size(); ++i) { |
| 150 const int icon_size = drive_app_info_.app_icons[i].first; | 151 const int icon_size = drive_app_info_.app_icons[i].first; |
| 151 if (pending_sizes.find(icon_size) != pending_sizes.end()) | 152 if (pending_sizes.find(icon_size) != pending_sizes.end()) |
| 152 continue; | 153 continue; |
| 153 | 154 |
| 154 pending_sizes.insert(icon_size); | 155 pending_sizes.insert(icon_size); |
| 155 const GURL& icon_url = drive_app_info_.app_icons[i].second; | 156 const GURL& icon_url = drive_app_info_.app_icons[i].second; |
| 156 IconFetcher* fetcher = new IconFetcher(this, icon_url, icon_size); | 157 fetchers_.push_back( |
| 157 fetchers_.push_back(fetcher); // Pass ownership to |fetchers|. | 158 base::MakeUnique<IconFetcher>(this, icon_url, icon_size)); |
| 158 fetcher->Start(); | 159 fetchers_.back()->Start(); |
| 159 } | 160 } |
| 160 | 161 |
| 161 if (fetchers_.empty()) | 162 if (fetchers_.empty()) |
| 162 StartInstall(); | 163 StartInstall(); |
| 163 } | 164 } |
| 164 | 165 |
| 165 bool DriveAppConverter::IsStarted() const { | 166 bool DriveAppConverter::IsStarted() const { |
| 166 return !fetchers_.empty() || crx_installer_.get(); | 167 return !fetchers_.empty() || crx_installer_.get(); |
| 167 } | 168 } |
| 168 | 169 |
| 169 bool DriveAppConverter::IsInstalling(const std::string& app_id) const { | 170 bool DriveAppConverter::IsInstalling(const std::string& app_id) const { |
| 170 return crx_installer_.get() && crx_installer_->extension() && | 171 return crx_installer_.get() && crx_installer_->extension() && |
| 171 crx_installer_->extension()->id() == app_id; | 172 crx_installer_->extension()->id() == app_id; |
| 172 } | 173 } |
| 173 | 174 |
| 174 void DriveAppConverter::OnIconFetchComplete(const IconFetcher* fetcher) { | 175 void DriveAppConverter::OnIconFetchComplete(const IconFetcher* fetcher) { |
| 175 const SkBitmap& icon = fetcher->icon(); | 176 const SkBitmap& icon = fetcher->icon(); |
| 176 if (!icon.empty() && icon.width() != 0) { | 177 if (!icon.empty() && icon.width() != 0) { |
| 177 WebApplicationInfo::IconInfo icon_info; | 178 WebApplicationInfo::IconInfo icon_info; |
| 178 icon_info.url = fetcher->icon_url(); | 179 icon_info.url = fetcher->icon_url(); |
| 179 icon_info.data = icon; | 180 icon_info.data = icon; |
| 180 icon_info.width = icon.width(); | 181 icon_info.width = icon.width(); |
| 181 icon_info.height = icon.height(); | 182 icon_info.height = icon.height(); |
| 182 web_app_.icons.push_back(icon_info); | 183 web_app_.icons.push_back(icon_info); |
| 183 } | 184 } |
| 184 | 185 |
| 185 fetchers_.erase(std::find(fetchers_.begin(), fetchers_.end(), fetcher)); | 186 fetchers_.erase( |
| 187 std::find_if(fetchers_.begin(), fetchers_.end(), |
| 188 [fetcher](const std::unique_ptr<IconFetcher>& item) { |
| 189 return item.get() == fetcher; |
| 190 })); |
| 186 | 191 |
| 187 if (fetchers_.empty()) | 192 if (fetchers_.empty()) |
| 188 StartInstall(); | 193 StartInstall(); |
| 189 } | 194 } |
| 190 | 195 |
| 191 void DriveAppConverter::StartInstall() { | 196 void DriveAppConverter::StartInstall() { |
| 192 DCHECK(!crx_installer_.get()); | 197 DCHECK(!crx_installer_.get()); |
| 193 crx_installer_ = extensions::CrxInstaller::CreateSilent( | 198 crx_installer_ = extensions::CrxInstaller::CreateSilent( |
| 194 extensions::ExtensionSystem::Get(profile_)->extension_service()); | 199 extensions::ExtensionSystem::Get(profile_)->extension_service()); |
| 195 // The converted url app should not be syncable. Drive apps go with the user's | 200 // The converted url app should not be syncable. Drive apps go with the user's |
| (...skipping 21 matching lines...) Expand all Loading... |
| 217 return; | 222 return; |
| 218 } | 223 } |
| 219 | 224 |
| 220 extension_ = crx_installer_->extension(); | 225 extension_ = crx_installer_->extension(); |
| 221 is_new_install_ = success && !crx_installer_->current_version().IsValid(); | 226 is_new_install_ = success && !crx_installer_->current_version().IsValid(); |
| 222 PostInstallCleanUp(); | 227 PostInstallCleanUp(); |
| 223 | 228 |
| 224 base::ResetAndReturn(&finished_callback_).Run(this, success); | 229 base::ResetAndReturn(&finished_callback_).Run(this, success); |
| 225 // |finished_callback_| could delete this. | 230 // |finished_callback_| could delete this. |
| 226 } | 231 } |
| OLD | NEW |