Chromium Code Reviews| 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/ui/app_list/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" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "chrome/browser/extensions/crx_installer.h" | 13 #include "chrome/browser/extensions/crx_installer.h" |
| 14 #include "chrome/browser/extensions/install_tracker.h" | 14 #include "chrome/browser/extensions/install_tracker.h" |
| 15 #include "chrome/browser/image_decoder.h" | 15 #include "chrome/browser/image_decoder.h" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 app_(NULL), | 108 app_(NULL), |
| 109 finished_callback_(finished_callback) { | 109 finished_callback_(finished_callback) { |
| 110 DCHECK(profile_); | 110 DCHECK(profile_); |
| 111 } | 111 } |
| 112 | 112 |
| 113 DriveAppConverter::~DriveAppConverter() { | 113 DriveAppConverter::~DriveAppConverter() { |
| 114 PostInstallCleanUp(); | 114 PostInstallCleanUp(); |
| 115 } | 115 } |
| 116 | 116 |
| 117 void DriveAppConverter::Start() { | 117 void DriveAppConverter::Start() { |
| 118 if (app_info_.app_name.empty() || | 118 DCHECK(!IsStarted()); |
| 119 !app_info_.create_url.is_valid()) { | 119 |
| 120 if (app_info_.app_name.empty() || !app_info_.create_url.is_valid()) { | |
| 120 finished_callback_.Run(this, false); | 121 finished_callback_.Run(this, false); |
| 121 return; | 122 return; |
| 122 } | 123 } |
| 123 | 124 |
| 124 web_app_.title = base::UTF8ToUTF16(app_info_.app_name); | 125 web_app_.title = base::UTF8ToUTF16(app_info_.app_name); |
| 125 web_app_.app_url = app_info_.create_url; | 126 web_app_.app_url = app_info_.create_url; |
| 126 | 127 |
| 127 const std::set<int> allowed_sizes(extension_misc::kExtensionIconSizes, | 128 const std::set<int> allowed_sizes(extension_misc::kExtensionIconSizes, |
| 128 extension_misc::kExtensionIconSizes + | 129 extension_misc::kExtensionIconSizes + |
| 129 extension_misc::kNumExtensionIconSizes); | 130 extension_misc::kNumExtensionIconSizes); |
| 130 std::set<int> pending_sizes; | 131 std::set<int> pending_sizes; |
| 131 for (size_t i = 0; i < app_info_.app_icons.size(); ++i) { | 132 for (size_t i = 0; i < app_info_.app_icons.size(); ++i) { |
| 132 const int icon_size = app_info_.app_icons[i].first; | 133 const int icon_size = app_info_.app_icons[i].first; |
| 133 if (allowed_sizes.find(icon_size) == allowed_sizes.end() || | 134 if (allowed_sizes.find(icon_size) == allowed_sizes.end() || |
| 134 pending_sizes.find(icon_size) != pending_sizes.end()) { | 135 pending_sizes.find(icon_size) != pending_sizes.end()) { |
| 135 continue; | 136 continue; |
| 136 } | 137 } |
| 137 | 138 |
| 138 pending_sizes.insert(icon_size); | 139 pending_sizes.insert(icon_size); |
| 139 const GURL& icon_url = app_info_.app_icons[i].second; | 140 const GURL& icon_url = app_info_.app_icons[i].second; |
| 140 IconFetcher* fetcher = new IconFetcher(this, icon_url, icon_size); | 141 IconFetcher* fetcher = new IconFetcher(this, icon_url, icon_size); |
| 141 fetchers_.push_back(fetcher); // Pass ownership to |fetchers|. | 142 fetchers_.push_back(fetcher); // Pass ownership to |fetchers|. |
| 142 fetcher->Start(); | 143 fetcher->Start(); |
| 143 } | 144 } |
| 144 | 145 |
| 145 if (fetchers_.empty()) | 146 if (fetchers_.empty()) |
| 146 StartInstall(); | 147 StartInstall(); |
| 147 } | 148 } |
| 148 | 149 |
| 150 bool DriveAppConverter::IsStarted() const { | |
| 151 return !fetchers_.empty() || crx_installer_; | |
| 152 } | |
| 153 | |
| 149 void DriveAppConverter::OnIconFetchComplete(const IconFetcher* fetcher) { | 154 void DriveAppConverter::OnIconFetchComplete(const IconFetcher* fetcher) { |
| 150 const SkBitmap& icon = fetcher->icon(); | 155 const SkBitmap& icon = fetcher->icon(); |
| 151 if (!icon.empty() && icon.width() != 0) { | 156 if (!icon.empty() && icon.width() != 0) { |
| 152 WebApplicationInfo::IconInfo icon_info; | 157 WebApplicationInfo::IconInfo icon_info; |
| 153 icon_info.url = fetcher->icon_url(); | 158 icon_info.url = fetcher->icon_url(); |
| 154 icon_info.data = icon; | 159 icon_info.data = icon; |
| 155 icon_info.width = icon.width(); | 160 icon_info.width = icon.width(); |
| 156 icon_info.height = icon.height(); | 161 icon_info.height = icon.height(); |
| 157 web_app_.icons.push_back(icon_info); | 162 web_app_.icons.push_back(icon_info); |
| 158 } | 163 } |
| 159 | 164 |
| 160 fetchers_.erase(std::find(fetchers_.begin(), fetchers_.end(), fetcher)); | 165 fetchers_.erase(std::find(fetchers_.begin(), fetchers_.end(), fetcher)); |
| 161 | 166 |
| 162 if (fetchers_.empty()) | 167 if (fetchers_.empty()) |
| 163 StartInstall(); | 168 StartInstall(); |
| 164 } | 169 } |
| 165 | 170 |
| 166 void DriveAppConverter::StartInstall() { | 171 void DriveAppConverter::StartInstall() { |
| 167 DCHECK(!crx_installer_); | 172 DCHECK(!crx_installer_); |
| 168 crx_installer_ = extensions::CrxInstaller::CreateSilent( | 173 crx_installer_ = extensions::CrxInstaller::CreateSilent( |
| 169 extensions::ExtensionSystem::Get(profile_)->extension_service()); | 174 extensions::ExtensionSystem::Get(profile_)->extension_service()); |
| 175 | |
| 176 // Sets WAS_INSTALLED_BY_DEFAULT to make the converted url app not syncable. | |
| 177 // Drive apps go with the user's account and url apps will be created when | |
| 178 // needed. Syncing those apps could hit an edge case where the synced url | |
| 179 // apps become orphans when the user has corresponding chrome apps. | |
| 180 crx_installer_->set_creation_flags( | |
| 181 extensions::Extension::FROM_BOOKMARK | | |
| 182 extensions::Extension::WAS_INSTALLED_BY_DEFAULT); | |
|
stevenjb
2014/06/05 20:15:16
WAS_INSTALLED_BY_DEFAULT might trigger other behav
xiyuan
2014/06/05 20:36:14
The converted app is sort of a default (in a sense
Yoyo Zhou
2014/06/05 20:45:33
This isn't really what we mean by default apps; th
not at google - send to devlin
2014/06/05 20:47:47
I agree with Steven, even if this works at the mom
xiyuan
2014/06/05 21:17:06
Okay.
- Add a ExtensionPrefs backed boolean prope
Yoyo Zhou
2014/06/05 21:18:20
Minor detail: you can check this in IsSyncable ins
| |
| 183 | |
| 170 extensions::InstallTracker::Get(profile_)->AddObserver(this); | 184 extensions::InstallTracker::Get(profile_)->AddObserver(this); |
| 171 crx_installer_->InstallWebApp(web_app_); | 185 crx_installer_->InstallWebApp(web_app_); |
| 172 } | 186 } |
| 173 | 187 |
| 174 void DriveAppConverter::PostInstallCleanUp() { | 188 void DriveAppConverter::PostInstallCleanUp() { |
| 175 if (!crx_installer_) | 189 if (!crx_installer_) |
| 176 return; | 190 return; |
| 177 | 191 |
| 178 extensions::InstallTracker::Get(profile_)->RemoveObserver(this); | 192 extensions::InstallTracker::Get(profile_)->RemoveObserver(this); |
| 179 crx_installer_ = NULL; | 193 crx_installer_ = NULL; |
| 180 } | 194 } |
| 181 | 195 |
| 182 void DriveAppConverter::OnFinishCrxInstall(const std::string& extension_id, | 196 void DriveAppConverter::OnFinishCrxInstall(const std::string& extension_id, |
| 183 bool success) { | 197 bool success) { |
| 184 if (!crx_installer_->extension() || | 198 if (!crx_installer_->extension() || |
| 185 crx_installer_->extension()->id() != extension_id) { | 199 crx_installer_->extension()->id() != extension_id) { |
| 186 return; | 200 return; |
| 187 } | 201 } |
| 188 | 202 |
| 189 app_ = crx_installer_->extension(); | 203 app_ = crx_installer_->extension(); |
| 204 PostInstallCleanUp(); | |
| 205 | |
| 190 finished_callback_.Run(this, success); | 206 finished_callback_.Run(this, success); |
| 191 | 207 // |finished_callback_| could delete this. |
| 192 PostInstallCleanUp(); | |
| 193 } | 208 } |
| OLD | NEW |