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" |
| 11 #include "base/location.h" |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
12 #include "base/message_loop/message_loop.h" | 13 #include "base/single_thread_task_runner.h" |
13 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 15 #include "base/thread_task_runner_handle.h" |
14 #include "chrome/browser/apps/drive/drive_app_converter.h" | 16 #include "chrome/browser/apps/drive/drive_app_converter.h" |
15 #include "chrome/browser/apps/drive/drive_app_mapping.h" | 17 #include "chrome/browser/apps/drive/drive_app_mapping.h" |
16 #include "chrome/browser/apps/drive/drive_app_uninstall_sync_service.h" | 18 #include "chrome/browser/apps/drive/drive_app_uninstall_sync_service.h" |
17 #include "chrome/browser/apps/drive/drive_service_bridge.h" | 19 #include "chrome/browser/apps/drive/drive_service_bridge.h" |
18 #include "chrome/browser/drive/drive_app_registry.h" | 20 #include "chrome/browser/drive/drive_app_registry.h" |
19 #include "chrome/browser/extensions/extension_service.h" | 21 #include "chrome/browser/extensions/extension_service.h" |
20 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 23 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
22 #include "extensions/browser/extension_registry.h" | 24 #include "extensions/browser/extension_registry.h" |
23 #include "extensions/browser/extension_registry_factory.h" | 25 #include "extensions/browser/extension_registry_factory.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 service_bridge_->GetAppRegistry()->AddObserver(this); | 69 service_bridge_->GetAppRegistry()->AddObserver(this); |
68 } | 70 } |
69 | 71 |
70 void DriveAppProvider::AddUninstalledDriveAppFromSync( | 72 void DriveAppProvider::AddUninstalledDriveAppFromSync( |
71 const std::string& drive_app_id) { | 73 const std::string& drive_app_id) { |
72 mapping_->AddUninstalledDriveApp(drive_app_id); | 74 mapping_->AddUninstalledDriveApp(drive_app_id); |
73 | 75 |
74 // Decouple the operation because this function could be called during | 76 // Decouple the operation because this function could be called during |
75 // sync processing and UpdateDriveApps could trigger another sync change. | 77 // sync processing and UpdateDriveApps could trigger another sync change. |
76 // See http://crbug.com/429205 | 78 // See http://crbug.com/429205 |
77 base::MessageLoop::current()->PostTask( | 79 base::ThreadTaskRunnerHandle::Get()->PostTask( |
78 FROM_HERE, | 80 FROM_HERE, base::Bind(&DriveAppProvider::UpdateDriveApps, |
79 base::Bind(&DriveAppProvider::UpdateDriveApps, | 81 weak_ptr_factory_.GetWeakPtr())); |
80 weak_ptr_factory_.GetWeakPtr())); | |
81 } | 82 } |
82 | 83 |
83 void DriveAppProvider::RemoveUninstalledDriveAppFromSync( | 84 void DriveAppProvider::RemoveUninstalledDriveAppFromSync( |
84 const std::string& drive_app_id) { | 85 const std::string& drive_app_id) { |
85 mapping_->RemoveUninstalledDriveApp(drive_app_id); | 86 mapping_->RemoveUninstalledDriveApp(drive_app_id); |
86 | 87 |
87 // Decouple the operation because this function could be called during | 88 // Decouple the operation because this function could be called during |
88 // sync processing and UpdateDriveApps could trigger another sync change. | 89 // sync processing and UpdateDriveApps could trigger another sync change. |
89 // See http://crbug.com/429205 | 90 // See http://crbug.com/429205 |
90 base::MessageLoop::current()->PostTask( | 91 base::ThreadTaskRunnerHandle::Get()->PostTask( |
91 FROM_HERE, | 92 FROM_HERE, base::Bind(&DriveAppProvider::UpdateDriveApps, |
92 base::Bind(&DriveAppProvider::UpdateDriveApps, | 93 weak_ptr_factory_.GetWeakPtr())); |
93 weak_ptr_factory_.GetWeakPtr())); | |
94 } | 94 } |
95 | 95 |
96 void DriveAppProvider::UpdateMappingAndExtensionSystem( | 96 void DriveAppProvider::UpdateMappingAndExtensionSystem( |
97 const std::string& drive_app_id, | 97 const std::string& drive_app_id, |
98 const Extension* new_app, | 98 const Extension* new_app, |
99 bool is_new_app_generated) { | 99 bool is_new_app_generated) { |
100 const std::string& new_chrome_app_id = new_app->id(); | 100 const std::string& new_chrome_app_id = new_app->id(); |
101 | 101 |
102 const std::string existing_chrome_app_id = | 102 const std::string existing_chrome_app_id = |
103 mapping_->GetChromeApp(drive_app_id); | 103 mapping_->GetChromeApp(drive_app_id); |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 mapping_->IsChromeAppGenerated(extension->id())) { | 292 mapping_->IsChromeAppGenerated(extension->id())) { |
293 mapping_->Add(drive_app_id, extension->id(), false); | 293 mapping_->Add(drive_app_id, extension->id(), false); |
294 return; | 294 return; |
295 } | 295 } |
296 | 296 |
297 for (size_t i = 0; i < drive_apps_.size(); ++i) { | 297 for (size_t i = 0; i < drive_apps_.size(); ++i) { |
298 if (drive_apps_[i].product_id == extension->id()) { | 298 if (drive_apps_[i].product_id == extension->id()) { |
299 // Defer the processing because it touches the extensions system and | 299 // Defer the processing because it touches the extensions system and |
300 // it is better to let the current task finish to avoid unexpected | 300 // it is better to let the current task finish to avoid unexpected |
301 // incomplete status. | 301 // incomplete status. |
302 base::MessageLoop::current()->PostTask( | 302 base::ThreadTaskRunnerHandle::Get()->PostTask( |
303 FROM_HERE, | 303 FROM_HERE, |
304 base::Bind(&DriveAppProvider::ProcessDeferredOnExtensionInstalled, | 304 base::Bind(&DriveAppProvider::ProcessDeferredOnExtensionInstalled, |
305 weak_ptr_factory_.GetWeakPtr(), | 305 weak_ptr_factory_.GetWeakPtr(), drive_apps_[i].app_id, |
306 drive_apps_[i].app_id, | |
307 extension->id())); | 306 extension->id())); |
308 return; | 307 return; |
309 } | 308 } |
310 } | 309 } |
311 } | 310 } |
312 | 311 |
313 void DriveAppProvider::OnExtensionUninstalled( | 312 void DriveAppProvider::OnExtensionUninstalled( |
314 content::BrowserContext* browser_context, | 313 content::BrowserContext* browser_context, |
315 const Extension* extension, | 314 const Extension* extension, |
316 extensions::UninstallReason reason) { | 315 extensions::UninstallReason reason) { |
317 std::string drive_app_id = mapping_->GetDriveApp(extension->id()); | 316 std::string drive_app_id = mapping_->GetDriveApp(extension->id()); |
318 if (drive_app_id.empty()) | 317 if (drive_app_id.empty()) |
319 return; | 318 return; |
320 | 319 |
321 for (size_t i = 0; i < drive_apps_.size(); ++i) { | 320 for (size_t i = 0; i < drive_apps_.size(); ++i) { |
322 if (drive_apps_[i].app_id != drive_app_id) | 321 if (drive_apps_[i].app_id != drive_app_id) |
323 continue; | 322 continue; |
324 | 323 |
325 if (drive_apps_[i].is_removable) { | 324 if (drive_apps_[i].is_removable) { |
326 service_bridge_->GetAppRegistry()->UninstallApp( | 325 service_bridge_->GetAppRegistry()->UninstallApp( |
327 drive_app_id, base::Bind(&IgnoreUninstallResult)); | 326 drive_app_id, base::Bind(&IgnoreUninstallResult)); |
328 } else { | 327 } else { |
329 mapping_->AddUninstalledDriveApp(drive_app_id); | 328 mapping_->AddUninstalledDriveApp(drive_app_id); |
330 uninstall_sync_service_->TrackUninstalledDriveApp(drive_app_id); | 329 uninstall_sync_service_->TrackUninstalledDriveApp(drive_app_id); |
331 } | 330 } |
332 | 331 |
333 return; | 332 return; |
334 } | 333 } |
335 } | 334 } |
OLD | NEW |