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/ui/app_list/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 97 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 DCHECK(!IsStarted()); |
| 119 |
118 if (app_info_.app_name.empty() || | 120 if (app_info_.app_name.empty() || |
119 !app_info_.create_url.is_valid()) { | 121 !app_info_.create_url.is_valid()) { |
120 finished_callback_.Run(this, false); | 122 finished_callback_.Run(this, false); |
121 return; | 123 return; |
122 } | 124 } |
123 | 125 |
124 web_app_.title = base::UTF8ToUTF16(app_info_.app_name); | 126 web_app_.title = base::UTF8ToUTF16(app_info_.app_name); |
125 web_app_.app_url = app_info_.create_url; | 127 web_app_.app_url = app_info_.create_url; |
126 | 128 |
127 const std::set<int> allowed_sizes(extension_misc::kExtensionIconSizes, | 129 const std::set<int> allowed_sizes(extension_misc::kExtensionIconSizes, |
(...skipping 11 matching lines...) Expand all Loading... |
139 const GURL& icon_url = app_info_.app_icons[i].second; | 141 const GURL& icon_url = app_info_.app_icons[i].second; |
140 IconFetcher* fetcher = new IconFetcher(this, icon_url, icon_size); | 142 IconFetcher* fetcher = new IconFetcher(this, icon_url, icon_size); |
141 fetchers_.push_back(fetcher); // Pass ownership to |fetchers|. | 143 fetchers_.push_back(fetcher); // Pass ownership to |fetchers|. |
142 fetcher->Start(); | 144 fetcher->Start(); |
143 } | 145 } |
144 | 146 |
145 if (fetchers_.empty()) | 147 if (fetchers_.empty()) |
146 StartInstall(); | 148 StartInstall(); |
147 } | 149 } |
148 | 150 |
| 151 bool DriveAppConverter::IsStarted() const { |
| 152 return !fetchers_.empty() || crx_installer_; |
| 153 } |
| 154 |
149 void DriveAppConverter::OnIconFetchComplete(const IconFetcher* fetcher) { | 155 void DriveAppConverter::OnIconFetchComplete(const IconFetcher* fetcher) { |
150 const SkBitmap& icon = fetcher->icon(); | 156 const SkBitmap& icon = fetcher->icon(); |
151 if (!icon.empty() && icon.width() != 0) { | 157 if (!icon.empty() && icon.width() != 0) { |
152 WebApplicationInfo::IconInfo icon_info; | 158 WebApplicationInfo::IconInfo icon_info; |
153 icon_info.url = fetcher->icon_url(); | 159 icon_info.url = fetcher->icon_url(); |
154 icon_info.data = icon; | 160 icon_info.data = icon; |
155 icon_info.width = icon.width(); | 161 icon_info.width = icon.width(); |
156 icon_info.height = icon.height(); | 162 icon_info.height = icon.height(); |
157 web_app_.icons.push_back(icon_info); | 163 web_app_.icons.push_back(icon_info); |
158 } | 164 } |
159 | 165 |
160 fetchers_.erase(std::find(fetchers_.begin(), fetchers_.end(), fetcher)); | 166 fetchers_.erase(std::find(fetchers_.begin(), fetchers_.end(), fetcher)); |
161 | 167 |
162 if (fetchers_.empty()) | 168 if (fetchers_.empty()) |
163 StartInstall(); | 169 StartInstall(); |
164 } | 170 } |
165 | 171 |
166 void DriveAppConverter::StartInstall() { | 172 void DriveAppConverter::StartInstall() { |
167 DCHECK(!crx_installer_); | 173 DCHECK(!crx_installer_); |
168 crx_installer_ = extensions::CrxInstaller::CreateSilent( | 174 crx_installer_ = extensions::CrxInstaller::CreateSilent( |
169 extensions::ExtensionSystem::Get(profile_)->extension_service()); | 175 extensions::ExtensionSystem::Get(profile_)->extension_service()); |
| 176 |
| 177 // Sets WAS_INSTALLED_BY_DEFAULT to make the converted url app not syncable. |
| 178 // Drive apps goes with the user's account and url apps will be created when |
| 179 // needed. Syncing those apps could hit an edge case where the synced url |
| 180 // apps become orphans when the user has corresponding chrome apps. |
| 181 crx_installer_->set_creation_flags( |
| 182 extensions::Extension::FROM_BOOKMARK | |
| 183 extensions::Extension::WAS_INSTALLED_BY_DEFAULT); |
| 184 |
170 extensions::InstallTracker::Get(profile_)->AddObserver(this); | 185 extensions::InstallTracker::Get(profile_)->AddObserver(this); |
171 crx_installer_->InstallWebApp(web_app_); | 186 crx_installer_->InstallWebApp(web_app_); |
172 } | 187 } |
173 | 188 |
174 void DriveAppConverter::PostInstallCleanUp() { | 189 void DriveAppConverter::PostInstallCleanUp() { |
175 if (!crx_installer_) | 190 if (!crx_installer_) |
176 return; | 191 return; |
177 | 192 |
178 extensions::InstallTracker::Get(profile_)->RemoveObserver(this); | 193 extensions::InstallTracker::Get(profile_)->RemoveObserver(this); |
179 crx_installer_ = NULL; | 194 crx_installer_ = NULL; |
180 } | 195 } |
181 | 196 |
182 void DriveAppConverter::OnFinishCrxInstall(const std::string& extension_id, | 197 void DriveAppConverter::OnFinishCrxInstall(const std::string& extension_id, |
183 bool success) { | 198 bool success) { |
184 if (!crx_installer_->extension() || | 199 if (!crx_installer_->extension() || |
185 crx_installer_->extension()->id() != extension_id) { | 200 crx_installer_->extension()->id() != extension_id) { |
186 return; | 201 return; |
187 } | 202 } |
188 | 203 |
189 app_ = crx_installer_->extension(); | 204 app_ = crx_installer_->extension(); |
| 205 PostInstallCleanUp(); |
| 206 |
190 finished_callback_.Run(this, success); | 207 finished_callback_.Run(this, success); |
191 | 208 // |finished_callback_| could delete this. |
192 PostInstallCleanUp(); | |
193 } | 209 } |
OLD | NEW |