| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/installable/installable_manager.h" | 5 #include "chrome/browser/installable/installable_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "chrome/browser/manifest/manifest_icon_downloader.h" | 9 #include "chrome/browser/manifest/manifest_icon_downloader.h" |
| 10 #include "chrome/browser/manifest/manifest_icon_selector.h" | 10 #include "chrome/browser/manifest/manifest_icon_selector.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 } | 48 } |
| 49 | 49 |
| 50 return false; | 50 return false; |
| 51 } | 51 } |
| 52 | 52 |
| 53 } // namespace | 53 } // namespace |
| 54 | 54 |
| 55 DEFINE_WEB_CONTENTS_USER_DATA_KEY(InstallableManager); | 55 DEFINE_WEB_CONTENTS_USER_DATA_KEY(InstallableManager); |
| 56 | 56 |
| 57 struct InstallableManager::ManifestProperty { | 57 struct InstallableManager::ManifestProperty { |
| 58 InstallableErrorCode error = NO_ERROR_DETECTED; | 58 InstallableStatusCode error = NO_ERROR_DETECTED; |
| 59 GURL url; | 59 GURL url; |
| 60 content::Manifest manifest; | 60 content::Manifest manifest; |
| 61 bool fetched = false; | 61 bool fetched = false; |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 struct InstallableManager::InstallableProperty { | 64 struct InstallableManager::InstallableProperty { |
| 65 InstallableErrorCode error = NO_ERROR_DETECTED; | 65 InstallableStatusCode error = NO_ERROR_DETECTED; |
| 66 bool installable = false; | 66 bool installable = false; |
| 67 bool fetched = false; | 67 bool fetched = false; |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 struct InstallableManager::IconProperty { | 70 struct InstallableManager::IconProperty { |
| 71 IconProperty() : | 71 IconProperty() : |
| 72 error(NO_ERROR_DETECTED), url(), icon(), fetched(false) { } | 72 error(NO_ERROR_DETECTED), url(), icon(), fetched(false) { } |
| 73 IconProperty(IconProperty&& other) = default; | 73 IconProperty(IconProperty&& other) = default; |
| 74 IconProperty& operator=(IconProperty&& other) = default; | 74 IconProperty& operator=(IconProperty&& other) = default; |
| 75 | 75 |
| 76 InstallableErrorCode error = NO_ERROR_DETECTED; | 76 InstallableStatusCode error = NO_ERROR_DETECTED; |
| 77 GURL url; | 77 GURL url; |
| 78 std::unique_ptr<SkBitmap> icon; | 78 std::unique_ptr<SkBitmap> icon; |
| 79 bool fetched; | 79 bool fetched; |
| 80 | 80 |
| 81 private: | 81 private: |
| 82 // This class contains a std::unique_ptr and therefore must be move-only. | 82 // This class contains a std::unique_ptr and therefore must be move-only. |
| 83 DISALLOW_COPY_AND_ASSIGN(IconProperty); | 83 DISALLOW_COPY_AND_ASSIGN(IconProperty); |
| 84 }; | 84 }; |
| 85 | 85 |
| 86 | 86 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 150 |
| 151 void InstallableManager::SetIconFetched(const InstallableParams& params) { | 151 void InstallableManager::SetIconFetched(const InstallableParams& params) { |
| 152 GetIcon(params).fetched = true; | 152 GetIcon(params).fetched = true; |
| 153 } | 153 } |
| 154 | 154 |
| 155 InstallableManager::IconProperty& InstallableManager::GetIcon( | 155 InstallableManager::IconProperty& InstallableManager::GetIcon( |
| 156 const InstallableParams& params) { | 156 const InstallableParams& params) { |
| 157 return icons_[{params.ideal_icon_size_in_dp, params.minimum_icon_size_in_dp}]; | 157 return icons_[{params.ideal_icon_size_in_dp, params.minimum_icon_size_in_dp}]; |
| 158 } | 158 } |
| 159 | 159 |
| 160 InstallableErrorCode InstallableManager::GetErrorCode( | 160 InstallableStatusCode InstallableManager::GetErrorCode( |
| 161 const InstallableParams& params) { | 161 const InstallableParams& params) { |
| 162 if (manifest_->error != NO_ERROR_DETECTED) | 162 if (manifest_->error != NO_ERROR_DETECTED) |
| 163 return manifest_->error; | 163 return manifest_->error; |
| 164 | 164 |
| 165 if (params.check_installable && installable_->error != NO_ERROR_DETECTED) | 165 if (params.check_installable && installable_->error != NO_ERROR_DETECTED) |
| 166 return installable_->error; | 166 return installable_->error; |
| 167 | 167 |
| 168 if (params.fetch_valid_icon) { | 168 if (params.fetch_valid_icon) { |
| 169 IconProperty& icon = GetIcon(params); | 169 IconProperty& icon = GetIcon(params); |
| 170 if (icon.error != NO_ERROR_DETECTED) | 170 if (icon.error != NO_ERROR_DETECTED) |
| 171 return icon.error; | 171 return icon.error; |
| 172 } | 172 } |
| 173 | 173 |
| 174 return NO_ERROR_DETECTED; | 174 return NO_ERROR_DETECTED; |
| 175 } | 175 } |
| 176 | 176 |
| 177 InstallableErrorCode InstallableManager::manifest_error() const { | 177 InstallableStatusCode InstallableManager::manifest_error() const { |
| 178 return manifest_->error; | 178 return manifest_->error; |
| 179 } | 179 } |
| 180 | 180 |
| 181 InstallableErrorCode InstallableManager::installable_error() const { | 181 InstallableStatusCode InstallableManager::installable_error() const { |
| 182 return installable_->error; | 182 return installable_->error; |
| 183 } | 183 } |
| 184 | 184 |
| 185 void InstallableManager::set_installable_error( | 185 void InstallableManager::set_installable_error( |
| 186 InstallableErrorCode error_code) { | 186 InstallableStatusCode error_code) { |
| 187 installable_->error = error_code; | 187 installable_->error = error_code; |
| 188 } | 188 } |
| 189 | 189 |
| 190 InstallableErrorCode InstallableManager::icon_error( | 190 InstallableStatusCode InstallableManager::icon_error( |
| 191 const InstallableManager::IconParams& icon_params) { | 191 const InstallableManager::IconParams& icon_params) { |
| 192 return icons_[icon_params].error; | 192 return icons_[icon_params].error; |
| 193 } | 193 } |
| 194 | 194 |
| 195 GURL& InstallableManager::icon_url( | 195 GURL& InstallableManager::icon_url( |
| 196 const InstallableManager::IconParams& icon_params) { | 196 const InstallableManager::IconParams& icon_params) { |
| 197 return icons_[icon_params].url; | 197 return icons_[icon_params].url; |
| 198 } | 198 } |
| 199 | 199 |
| 200 const SkBitmap* InstallableManager::icon( | 200 const SkBitmap* InstallableManager::icon( |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 if (tasks_.empty()) { | 244 if (tasks_.empty()) { |
| 245 is_active_ = false; | 245 is_active_ = false; |
| 246 return; | 246 return; |
| 247 } | 247 } |
| 248 | 248 |
| 249 DCHECK(is_active_); | 249 DCHECK(is_active_); |
| 250 WorkOnTask(); | 250 WorkOnTask(); |
| 251 } | 251 } |
| 252 | 252 |
| 253 void InstallableManager::RunCallback(const Task& task, | 253 void InstallableManager::RunCallback(const Task& task, |
| 254 InstallableErrorCode code) { | 254 InstallableStatusCode code) { |
| 255 const InstallableParams& params = task.first; | 255 const InstallableParams& params = task.first; |
| 256 IconProperty& icon = GetIcon(params); | 256 IconProperty& icon = GetIcon(params); |
| 257 InstallableData data = { | 257 InstallableData data = { |
| 258 code, | 258 code, |
| 259 manifest_url(), | 259 manifest_url(), |
| 260 manifest(), | 260 manifest(), |
| 261 params.fetch_valid_icon ? icon.url : GURL::EmptyGURL(), | 261 params.fetch_valid_icon ? icon.url : GURL::EmptyGURL(), |
| 262 params.fetch_valid_icon ? icon.icon.get() : nullptr, | 262 params.fetch_valid_icon ? icon.icon.get() : nullptr, |
| 263 params.check_installable ? is_installable() : false}; | 263 params.check_installable ? is_installable() : false}; |
| 264 | 264 |
| 265 task.second.Run(data); | 265 task.second.Run(data); |
| 266 } | 266 } |
| 267 | 267 |
| 268 void InstallableManager::WorkOnTask() { | 268 void InstallableManager::WorkOnTask() { |
| 269 DCHECK(!tasks_.empty()); | 269 DCHECK(!tasks_.empty()); |
| 270 const Task& task = tasks_[0]; | 270 const Task& task = tasks_[0]; |
| 271 const InstallableParams& params = task.first; | 271 const InstallableParams& params = task.first; |
| 272 | 272 |
| 273 InstallableErrorCode code = GetErrorCode(params); | 273 InstallableStatusCode code = GetErrorCode(params); |
| 274 if (code != NO_ERROR_DETECTED || IsComplete(params)) { | 274 if (code != NO_ERROR_DETECTED || IsComplete(params)) { |
| 275 RunCallback(task, code); | 275 RunCallback(task, code); |
| 276 tasks_.erase(tasks_.begin()); | 276 tasks_.erase(tasks_.begin()); |
| 277 StartNextTask(); | 277 StartNextTask(); |
| 278 return; | 278 return; |
| 279 } | 279 } |
| 280 | 280 |
| 281 if (!manifest_->fetched) | 281 if (!manifest_->fetched) |
| 282 FetchManifest(); | 282 FetchManifest(); |
| 283 else if (params.check_installable && !installable_->fetched) | 283 else if (params.check_installable && !installable_->fetched) |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 } | 435 } |
| 436 | 436 |
| 437 bool InstallableManager::is_installable() const { | 437 bool InstallableManager::is_installable() const { |
| 438 return installable_->installable; | 438 return installable_->installable; |
| 439 } | 439 } |
| 440 | 440 |
| 441 // static | 441 // static |
| 442 int InstallableManager::GetMinimumIconSizeInPx() { | 442 int InstallableManager::GetMinimumIconSizeInPx() { |
| 443 return kIconMinimumSizeInPx; | 443 return kIconMinimumSizeInPx; |
| 444 } | 444 } |
| OLD | NEW |