| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/extensions/platform_app_launcher.h" | 5 #include "chrome/browser/extensions/platform_app_launcher.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 return; | 155 return; |
| 156 } | 156 } |
| 157 | 157 |
| 158 // Access needs to be granted to the file for the process associated with | 158 // Access needs to be granted to the file for the process associated with |
| 159 // the extension. To do this the ExtensionHost is needed. This might not be | 159 // the extension. To do this the ExtensionHost is needed. This might not be |
| 160 // available, or it might be in the process of being unloaded, in which case | 160 // available, or it might be in the process of being unloaded, in which case |
| 161 // the lazy background task queue is used to load the extension and then | 161 // the lazy background task queue is used to load the extension and then |
| 162 // call back to us. | 162 // call back to us. |
| 163 extensions::LazyBackgroundTaskQueue* queue = | 163 extensions::LazyBackgroundTaskQueue* queue = |
| 164 ExtensionSystem::Get(profile_)->lazy_background_task_queue(); | 164 ExtensionSystem::Get(profile_)->lazy_background_task_queue(); |
| 165 if (queue->ShouldEnqueueTask(profile_, extension_)) { | 165 queue->AddPendingTask(profile_, extension_->id(), base::Bind( |
| 166 queue->AddPendingTask(profile_, extension_->id(), base::Bind( | 166 &PlatformAppCommandLineLauncher::GrantAccessToFileAndLaunch, |
| 167 &PlatformAppCommandLineLauncher::GrantAccessToFileAndLaunch, | 167 this, file_path, mime_type)); |
| 168 this, file_path, mime_type)); | |
| 169 return; | |
| 170 } | |
| 171 | |
| 172 ExtensionProcessManager* process_manager = | |
| 173 ExtensionSystem::Get(profile_)->process_manager(); | |
| 174 ExtensionHost* host = | |
| 175 process_manager->GetBackgroundHostForExtension(extension_->id()); | |
| 176 DCHECK(host); | |
| 177 GrantAccessToFileAndLaunch(file_path, mime_type, host); | |
| 178 } | 168 } |
| 179 | 169 |
| 180 void GrantAccessToFileAndLaunch(const FilePath& file_path, | 170 void GrantAccessToFileAndLaunch(const FilePath& file_path, |
| 181 const std::string& mime_type, | 171 const std::string& mime_type, |
| 182 ExtensionHost* host) { | 172 ExtensionHost* host) { |
| 183 // If there was an error loading the app page, |host| will be NULL. | 173 // If there was an error loading the app page, |host| will be NULL. |
| 184 if (!host) { | 174 if (!host) { |
| 185 LOG(ERROR) << "Could not load app page for " << extension_->id(); | 175 LOG(ERROR) << "Could not load app page for " << extension_->id(); |
| 186 return; | 176 return; |
| 187 } | 177 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 void Launch() { | 233 void Launch() { |
| 244 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 234 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 245 | 235 |
| 246 // Access needs to be granted to the file for the process associated with | 236 // Access needs to be granted to the file for the process associated with |
| 247 // the extension. To do this the ExtensionHost is needed. This might not be | 237 // the extension. To do this the ExtensionHost is needed. This might not be |
| 248 // available, or it might be in the process of being unloaded, in which case | 238 // available, or it might be in the process of being unloaded, in which case |
| 249 // the lazy background task queue is used to load the extension and then | 239 // the lazy background task queue is used to load the extension and then |
| 250 // call back to us. | 240 // call back to us. |
| 251 extensions::LazyBackgroundTaskQueue* queue = | 241 extensions::LazyBackgroundTaskQueue* queue = |
| 252 ExtensionSystem::Get(profile_)->lazy_background_task_queue(); | 242 ExtensionSystem::Get(profile_)->lazy_background_task_queue(); |
| 253 if (queue->ShouldEnqueueTask(profile_, extension_)) { | 243 queue->AddPendingTask(profile_, extension_->id(), base::Bind( |
| 254 queue->AddPendingTask(profile_, extension_->id(), base::Bind( | 244 &PlatformAppBlobIntentLauncher::GrantAccessToFileAndLaunch, |
| 255 &PlatformAppBlobIntentLauncher::GrantAccessToFileAndLaunch, | 245 this)); |
| 256 this)); | |
| 257 return; | |
| 258 } | |
| 259 | |
| 260 ExtensionProcessManager* process_manager = | |
| 261 ExtensionSystem::Get(profile_)->process_manager(); | |
| 262 ExtensionHost* host = | |
| 263 process_manager->GetBackgroundHostForExtension(extension_->id()); | |
| 264 DCHECK(host); | |
| 265 GrantAccessToFileAndLaunch(host); | |
| 266 } | 246 } |
| 267 | 247 |
| 268 private: | 248 private: |
| 269 friend class base::RefCountedThreadSafe<PlatformAppBlobIntentLauncher>; | 249 friend class base::RefCountedThreadSafe<PlatformAppBlobIntentLauncher>; |
| 270 | 250 |
| 271 virtual ~PlatformAppBlobIntentLauncher() {} | 251 virtual ~PlatformAppBlobIntentLauncher() {} |
| 272 | 252 |
| 273 void GrantAccessToFileAndLaunch(ExtensionHost* host) { | 253 void GrantAccessToFileAndLaunch(ExtensionHost* host) { |
| 274 // If there was an error loading the app page, |host| will be NULL. | 254 // If there was an error loading the app page, |host| will be NULL. |
| 275 if (!host) { | 255 if (!host) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 new PlatformAppBlobIntentLauncher(profile, extension, web_intent_data); | 308 new PlatformAppBlobIntentLauncher(profile, extension, web_intent_data); |
| 329 launcher->Launch(); | 309 launcher->Launch(); |
| 330 return; | 310 return; |
| 331 } | 311 } |
| 332 | 312 |
| 333 extensions::AppEventRouter::DispatchOnLaunchedEventWithWebIntent( | 313 extensions::AppEventRouter::DispatchOnLaunchedEventWithWebIntent( |
| 334 profile, extension, web_intent_data); | 314 profile, extension, web_intent_data); |
| 335 } | 315 } |
| 336 | 316 |
| 337 } // namespace extensions | 317 } // namespace extensions |
| OLD | NEW |