Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1672)

Side by Side Diff: chrome/browser/apps/drive/drive_app_provider.cc

Issue 1130903006: cros: Fix DriveAppProvider racing during initialization. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 24 matching lines...) Expand all
35 35
36 } // namespace 36 } // namespace
37 37
38 DriveAppProvider::DriveAppProvider( 38 DriveAppProvider::DriveAppProvider(
39 Profile* profile, 39 Profile* profile,
40 DriveAppUninstallSyncService* uninstall_sync_service) 40 DriveAppUninstallSyncService* uninstall_sync_service)
41 : profile_(profile), 41 : profile_(profile),
42 uninstall_sync_service_(uninstall_sync_service), 42 uninstall_sync_service_(uninstall_sync_service),
43 service_bridge_(DriveServiceBridge::Create(profile).Pass()), 43 service_bridge_(DriveServiceBridge::Create(profile).Pass()),
44 mapping_(new DriveAppMapping(profile->GetPrefs())), 44 mapping_(new DriveAppMapping(profile->GetPrefs())),
45 drive_app_registry_updated_(false),
45 weak_ptr_factory_(this) { 46 weak_ptr_factory_(this) {
46 service_bridge_->GetAppRegistry()->AddObserver(this); 47 service_bridge_->GetAppRegistry()->AddObserver(this);
47 ExtensionRegistry::Get(profile_)->AddObserver(this); 48 ExtensionRegistry::Get(profile_)->AddObserver(this);
48 } 49 }
49 50
50 DriveAppProvider::~DriveAppProvider() { 51 DriveAppProvider::~DriveAppProvider() {
51 ExtensionRegistry::Get(profile_)->RemoveObserver(this); 52 ExtensionRegistry::Get(profile_)->RemoveObserver(this);
52 service_bridge_->GetAppRegistry()->RemoveObserver(this); 53 service_bridge_->GetAppRegistry()->RemoveObserver(this);
53 } 54 }
54 55
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 230
230 extensions::ExtensionSystem::Get(profile_) 231 extensions::ExtensionSystem::Get(profile_)
231 ->extension_service() 232 ->extension_service()
232 ->UninstallExtension(chrome_app_id, 233 ->UninstallExtension(chrome_app_id,
233 extensions::UNINSTALL_REASON_SYNC, 234 extensions::UNINSTALL_REASON_SYNC,
234 base::Bind(&base::DoNothing), 235 base::Bind(&base::DoNothing),
235 NULL); 236 NULL);
236 } 237 }
237 238
238 void DriveAppProvider::UpdateDriveApps() { 239 void DriveAppProvider::UpdateDriveApps() {
240 if (!drive_app_registry_updated_)
241 return;
242
239 service_bridge_->GetAppRegistry()->GetAppList(&drive_apps_); 243 service_bridge_->GetAppRegistry()->GetAppList(&drive_apps_);
240 244
241 IdSet current_ids; 245 IdSet current_ids;
242 for (size_t i = 0; i < drive_apps_.size(); ++i) { 246 for (size_t i = 0; i < drive_apps_.size(); ++i) {
243 const std::string& drive_app_id = drive_apps_[i].app_id; 247 const std::string& drive_app_id = drive_apps_[i].app_id;
244 if (!mapping_->IsUninstalledDriveApp(drive_app_id) && 248 if (!mapping_->IsUninstalledDriveApp(drive_app_id) &&
245 drive_apps_[i].create_url.is_valid()) { 249 drive_apps_[i].create_url.is_valid()) {
246 current_ids.insert(drive_app_id); 250 current_ids.insert(drive_app_id);
247 } 251 }
248 } 252 }
(...skipping 10 matching lines...) Expand all
259 for (size_t i = 0; i < drive_apps_.size(); ++i) { 263 for (size_t i = 0; i < drive_apps_.size(); ++i) {
260 if (!mapping_->IsUninstalledDriveApp(drive_apps_[i].app_id) && 264 if (!mapping_->IsUninstalledDriveApp(drive_apps_[i].app_id) &&
261 drive_apps_[i].create_url.is_valid()) { 265 drive_apps_[i].create_url.is_valid()) {
262 AddOrUpdateDriveApp(drive_apps_[i]); 266 AddOrUpdateDriveApp(drive_apps_[i]);
263 } 267 }
264 } 268 }
265 SchedulePendingConverters(); 269 SchedulePendingConverters();
266 } 270 }
267 271
268 void DriveAppProvider::OnDriveAppRegistryUpdated() { 272 void DriveAppProvider::OnDriveAppRegistryUpdated() {
273 drive_app_registry_updated_ = true;
269 UpdateDriveApps(); 274 UpdateDriveApps();
270 } 275 }
271 276
272 void DriveAppProvider::OnExtensionInstalled( 277 void DriveAppProvider::OnExtensionInstalled(
273 content::BrowserContext* browser_context, 278 content::BrowserContext* browser_context,
274 const Extension* extension, 279 const Extension* extension,
275 bool is_update) { 280 bool is_update) {
276 // Bail if the |extension| is installed from a converter. The post install 281 // Bail if the |extension| is installed from a converter. The post install
277 // processing will be handled in OnLocalAppConverted. 282 // processing will be handled in OnLocalAppConverted.
278 if (!pending_converters_.empty() && 283 if (!pending_converters_.empty() &&
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 service_bridge_->GetAppRegistry()->UninstallApp( 326 service_bridge_->GetAppRegistry()->UninstallApp(
322 drive_app_id, base::Bind(&IgnoreUninstallResult)); 327 drive_app_id, base::Bind(&IgnoreUninstallResult));
323 } else { 328 } else {
324 mapping_->AddUninstalledDriveApp(drive_app_id); 329 mapping_->AddUninstalledDriveApp(drive_app_id);
325 uninstall_sync_service_->TrackUninstalledDriveApp(drive_app_id); 330 uninstall_sync_service_->TrackUninstalledDriveApp(drive_app_id);
326 } 331 }
327 332
328 return; 333 return;
329 } 334 }
330 } 335 }
OLDNEW
« no previous file with comments | « chrome/browser/apps/drive/drive_app_provider.h ('k') | chrome/browser/apps/drive/drive_app_provider_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698