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_provider.h" | 5 #include "chrome/browser/apps/drive/drive_app_provider.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 return; | 74 return; |
75 | 75 |
76 const bool is_existing_app_generated = | 76 const bool is_existing_app_generated = |
77 mapping_->IsChromeAppGenerated(existing_chrome_app_id); | 77 mapping_->IsChromeAppGenerated(existing_chrome_app_id); |
78 mapping_->Add(drive_app_id, new_chrome_app_id, is_new_app_generated); | 78 mapping_->Add(drive_app_id, new_chrome_app_id, is_new_app_generated); |
79 | 79 |
80 const Extension* existing_app = | 80 const Extension* existing_app = |
81 ExtensionRegistry::Get(profile_)->GetExtensionById( | 81 ExtensionRegistry::Get(profile_)->GetExtensionById( |
82 existing_chrome_app_id, ExtensionRegistry::EVERYTHING); | 82 existing_chrome_app_id, ExtensionRegistry::EVERYTHING); |
83 if (existing_app && is_existing_app_generated) { | 83 if (existing_app && is_existing_app_generated) { |
| 84 // If the new app was installed by the custodian, also use custodian |
| 85 // privileges for removing the old one. |
| 86 extensions::UninstallReason reason = |
| 87 new_app->was_installed_by_custodian() ? |
| 88 extensions::UNINSTALL_REASON_SYNC_BY_CUSTODIAN : |
| 89 extensions::UNINSTALL_REASON_SYNC; |
| 90 |
84 extensions::ExtensionSystem::Get(profile_) | 91 extensions::ExtensionSystem::Get(profile_) |
85 ->extension_service() | 92 ->extension_service() |
86 ->UninstallExtension( | 93 ->UninstallExtension(existing_chrome_app_id, reason, NULL); |
87 existing_chrome_app_id, extensions::UNINSTALL_REASON_SYNC, NULL); | |
88 } | 94 } |
89 } | 95 } |
90 | 96 |
91 void DriveAppProvider::ProcessDeferredOnExtensionInstalled( | 97 void DriveAppProvider::ProcessDeferredOnExtensionInstalled( |
92 const std::string drive_app_id, | 98 const std::string drive_app_id, |
93 const std::string chrome_app_id) { | 99 const std::string chrome_app_id) { |
94 const Extension* app = ExtensionRegistry::Get(profile_)->GetExtensionById( | 100 const Extension* app = ExtensionRegistry::Get(profile_)->GetExtensionById( |
95 chrome_app_id, ExtensionRegistry::EVERYTHING); | 101 chrome_app_id, ExtensionRegistry::EVERYTHING); |
96 if (!app) | 102 if (!app) |
97 return; | 103 return; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 | 190 |
185 if (chrome_app_id.empty() || !is_generated) | 191 if (chrome_app_id.empty() || !is_generated) |
186 return; | 192 return; |
187 | 193 |
188 const Extension* existing_app = | 194 const Extension* existing_app = |
189 ExtensionRegistry::Get(profile_) | 195 ExtensionRegistry::Get(profile_) |
190 ->GetExtensionById(chrome_app_id, ExtensionRegistry::EVERYTHING); | 196 ->GetExtensionById(chrome_app_id, ExtensionRegistry::EVERYTHING); |
191 if (!existing_app) | 197 if (!existing_app) |
192 return; | 198 return; |
193 | 199 |
| 200 extensions::UninstallReason reason = |
| 201 existing_app->was_installed_by_custodian() ? |
| 202 extensions::UNINSTALL_REASON_SYNC_BY_CUSTODIAN : |
| 203 extensions::UNINSTALL_REASON_SYNC; |
194 extensions::ExtensionSystem::Get(profile_) | 204 extensions::ExtensionSystem::Get(profile_) |
195 ->extension_service() | 205 ->extension_service() |
196 ->UninstallExtension( | 206 ->UninstallExtension(chrome_app_id, reason, NULL); |
197 chrome_app_id, extensions::UNINSTALL_REASON_SYNC, NULL); | |
198 } | 207 } |
199 | 208 |
200 void DriveAppProvider::OnDriveAppRegistryUpdated() { | 209 void DriveAppProvider::OnDriveAppRegistryUpdated() { |
201 service_bridge_->GetAppRegistry()->GetAppList(&drive_apps_); | 210 service_bridge_->GetAppRegistry()->GetAppList(&drive_apps_); |
202 | 211 |
203 IdSet current_ids; | 212 IdSet current_ids; |
204 for (size_t i = 0; i < drive_apps_.size(); ++i) | 213 for (size_t i = 0; i < drive_apps_.size(); ++i) |
205 current_ids.insert(drive_apps_[i].app_id); | 214 current_ids.insert(drive_apps_[i].app_id); |
206 | 215 |
207 const IdSet existing_ids = mapping_->GetDriveAppIds(); | 216 const IdSet existing_ids = mapping_->GetDriveAppIds(); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 content::BrowserContext* browser_context, | 268 content::BrowserContext* browser_context, |
260 const Extension* extension, | 269 const Extension* extension, |
261 extensions::UninstallReason reason) { | 270 extensions::UninstallReason reason) { |
262 std::string drive_app_id = mapping_->GetDriveApp(extension->id()); | 271 std::string drive_app_id = mapping_->GetDriveApp(extension->id()); |
263 if (drive_app_id.empty()) | 272 if (drive_app_id.empty()) |
264 return; | 273 return; |
265 | 274 |
266 service_bridge_->GetAppRegistry()->UninstallApp( | 275 service_bridge_->GetAppRegistry()->UninstallApp( |
267 drive_app_id, base::Bind(&IgnoreUninstallResult)); | 276 drive_app_id, base::Bind(&IgnoreUninstallResult)); |
268 } | 277 } |
OLD | NEW |